Problem with unions and bitfields
"Chris Higgs" <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Ctypes behaves unexpectedly when attempting to access an anonymous union
containing bitfields.
I'm using hdr2py to convert a structure into a python module, the
generated python module looks ok, but in python 2.5.2 and 2.6.2 writing
the bitfields in the union splat other parts of the structure.
Header file:
/*
* WARNING: Autogenerated file, do not modify!
*/
#ifndef ___AUTO_STATS_MATRIX_RFILE_H
#define ___AUTO_STATS_MATRIX_RFILE_H
#include <stdint.h>
struct matrix_status_w0_t {
uint32_t width : 8;
uint32_t depth : 8;
uint32_t reserved_future_1 : 16;
};
struct matrix_status_t {
uint32_t rdata;
uint32_t raddr;
union {
uint32_t w0;
matrix_status_w0_t w0b;
uint32_t reserved_future_1 : 16;
uint32_t depth : 8;
uint32_t width : 8;
};
};
#endif
Example:
>>> import ctypes_testcase
>>> import ctypes
>>> u = ctypes_testcase.matrix_status_t()
>>> ctypes.sizeof(u)
12
>>> u.depth
0L
>>> u.raddr
0L
>>> u.depth = 4
>>> u.depth
4L
>>> u.raddr
1024L
>>> u.raddr = 0
>>> u.raddr
0L
>>> u.depth
0L
Am I doing something wrong of is this a bug in ctypes?
Thanks,
Chris
This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies.
Detica Limited is registered in England under No: 1337451.
Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.
------------------------------------------------------------------------------