This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Steve.Thompson
Recipients Steve.Thompson, amaury.forgeotdarc, santoso.wijaya
Date 2011-04-25.21:21:56
SpamBayes Score 1.6442849e-08
Marked as misclassified No
Message-id <BANLkTinn4zhSsHEFd0bitLhPNOUSEhWxyw@mail.gmail.com>
In-reply-to <1303760974.06.0.721393925879.issue11920@psf.upfronthosting.co.za>
Content
So, knowing there's a potential cross platform inconsistency here, is there
a proposed way to deal with this that doesn't involve modifying the real c
code I'm interfacing with?  That's not always an option.

On Mon, Apr 25, 2011 at 2:49 PM, Santoso Wijaya <report@bugs.python.org>wrote:

>
> Santoso Wijaya <santoso.wijaya@gmail.com> added the comment:
>
> What compilers were used to build your Python distro and the native
> structure?
>
> I found out in _ctypes/cfield.c (lns. 76-95):
>
>    if (bitsize /* this is a bitfield request */
>        && *pfield_size /* we have a bitfield open */
> #ifdef MS_WIN32
>        /* MSVC, GCC with -mms-bitfields */
>        && dict->size * 8 == *pfield_size
> #else
>        /* GCC */
>        && dict->size * 8 <= *pfield_size
> #endif
>        && (*pbitofs + bitsize) <= *pfield_size) {
>        /* continue bit field */
>        fieldtype = CONT_BITFIELD;
> #ifndef MS_WIN32
>    } else if (bitsize /* this is a bitfield request */
>        && *pfield_size /* we have a bitfield open */
>        && dict->size * 8 >= *pfield_size
>        && (*pbitofs + bitsize) <= dict->size * 8) {
>        /* expand bit field */
>        fieldtype = EXPAND_BITFIELD;
> #endif
>
> So the allocation of the extra byte for the structure seems to depend on
> Python's compiler. To make sure, I compiled a native structure using MSVC:
>
> #pragma pack(1)
> typedef struct _struct1
> {
>    UINT8 first   : 1;
>    UINT8 second  : 1;
>    UINT8 third   : 1;
>    UINT8 fourth  : 1;
>    UINT8 fifth   : 1;
>    UINT16 pad    : 11;
> } struct1;
>
> And I got the same value (sizeof == 3).
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue11920>
> _______________________________________
>
Files
File name Uploaded
unnamed Steve.Thompson, 2011-04-25.21:21:56
History
Date User Action Args
2011-04-25 21:21:58Steve.Thompsonsetrecipients: + Steve.Thompson, amaury.forgeotdarc, santoso.wijaya
2011-04-25 21:21:56Steve.Thompsonlinkissue11920 messages
2011-04-25 21:21:56Steve.Thompsoncreate