Re: feature request for setting _pack_ to a higher value

Mads Kiilerich <[email protected]>
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Axel Seibert wrote, On 03/21/2010 09:56 PM:
> Dear list!
>
> My quest continues... During this weekend, I learned a lot about C 
> data structures, more than I ever wanted to. After all, that's why I'm 
> using Python.

Yeah. ctypes can't hide the details and the simplistic complexity of C 
and the CPU, so ctypes is not a magic silver bullet.

If you couldn't do it in C then you probably can't do it in ctypes. The 
advantage of ctypes is that you don't have to actually do it in C and 
you can avoid a lot of trivial and error-prone C code ;-) And if you can 
do it with ctypes then you probably could have done it in other ways as 
well - but ctypes is often more convenient.

> It's surprising to learn that the alignment under Linux (32bit) is 
> different from Windows (32bit) and Solaris (32bit).
>
> Basically, now I have a feature request: The library I'm wrapping is 
> available under different plattforms (Windows, Linux, Solaris, AIX and 
> HP/UX). As this library contains the code to talk to a server across 
> the network, it probably tries to keep alignment across all plattforms 
> the same. At least, under Linux, I had to change the alignment of many 
> structs.

AFAIK C structs are - for this and other reasons - very seldom 
transferred directly over the network. This library might however do it 
anyway.

> When I tried to do this with the class variable _pack_, I could not 
> get the desired result; up to a value of 4 I saw a difference, but not 
> beyond. Then I found the following statement from Thomas:
>
> > To force an alignment that is larger than the native alignment, you
> > must use padding.
>
> But that's not really an option. The supporting header files define 
> 293 struct's; in 44 cases, I had to change the alignment from 4 to 8 
> -- but ctypes does not allow for this.
>

Can you give an (or several) exact example of a problematic C 
declaration and what you would have hoped worked with ctypes and how you 
have to workaround?

A reference to the Thomas quote might help the discussion too.

/Mads

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.