Re: Problem with alignment under Linux [SEC=UNCLASSIFIED]
"Andrew MacIntyre" <[email protected]> Fri, 10 Feb 2012 08:28:26 +0000
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <A1E4E9D08D14924498E135FB4441EE8D18FEBC47@act01exmbx01vp.internal.govt> |
Axel, According to http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html, "aligned" is the attribute to look for. There is another possibility that occurs to me: the use of the gcc option "-malign-double" forcing doubles to be 8 byte aligned when building the library. I haven't found anything to suggest that a union will automatically force 8 byte alignment, but such might arise from one of the union's fields - as I noted earlier, on linux i386 long long is the only type likely to cause this without explicit action being taken. When you originally investigated the problem, did you write C test code to fully evaluate the behaviour using sizeof, offsetof and __alignof__ (see http://gcc.gnu.org/onlinedocs/gcc/Alignment.html)? Writing C test cases is the last resort way of finding some of this info out, because sometimes the info is obscured (eg in gcc's configuration, or pragmas in ancestor headers). While I think the behaviour of the ctypes pack option on other than Windows is unfortunate (given the fact that MS do packing related things differently to gcc), it should be feasible to pad the structures to match the requirements - once you know exactly what the requirements are. BTW, I'm not an expert in this but I've had cause to write test cases when dealing with similar issues. Andrew. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre Operations Branch tel: +61 2 6219 5356 Communications Infrastructure Division fax: +61 2 6253 3277 Australian Communications & Media Authority email: [email protected] http://www.acma.gov.au/ > -----Original Message----- > From: Axel Seibert [mailto:[email protected]] > Sent: Thursday, 9 February 2012 10:45 PM > To: [email protected] > Subject: Re: [ctypes-users] Problem with alignment under Linux > [SEC=UNCLASSIFIED] > > Hi, Andrew! > > Thanx for the quick answer. > > > In the 32bit linux environment, which I would have expected to > > include a 32bit binary on a 64bit kernel, > > yes, we are talking about 32bit binaries. > > > So there has to be something in the C headers you're working from > > that triggers 8 byte packing. I went back through the old thread, > > but didn't see any reference to any actual structure/union > > declarations as they appear in the C headers, so it would be useful > > to know how this is being triggered. > > I was under the impression that it might have to do with the inclusion of the > union, which brings the trouble. > > Can you give me a hint what to search for in the header files? I've been > looking for pragma, pack, alignment, 32 and 64, so far with no success. I > could also include the header files in my email, but I guess, you don't want > to go through more than 340 KBs of header files... > > > BTW, it seems to me that there's a bug in the fill_union() function > > as I think the union as shown should be 8 bytes rather than the 16 > > bytes reported - I think the calculation of the delta should be > > something like > > > > delta = size % 8 > > if delta: > > delta = 8 - delta > > > > OK, I will fix this in the program. > > What else can I do to support? > > Thanx, > Axel > > > ------------------------------------------------------------------------------ > Virtualization & Cloud Management Using Capacity Planning > Cloud computing makes use of virtualization - but cloud computing > also focuses on allowing computing to be delivered as a service. > http://www.accelacomm.com/jaw/sfnl/114/51521223/ > _______________________________________________ > ctypes-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/ctypes-users NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/