Skip to content

ctype with packed bitfields does not match native compiler #59658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MikeCastle mannequin opened this issue Jul 26, 2012 · 5 comments
Closed

ctype with packed bitfields does not match native compiler #59658

MikeCastle mannequin opened this issue Jul 26, 2012 · 5 comments

Comments

@MikeCastle
Copy link
Mannequin

MikeCastle mannequin commented Jul 26, 2012

BPO 15453
Nosy @terryjreedy, @mdickinson, @meadori
Superseder
  • bpo-29753: [Linux] ctypes packs bitfields Incorrectly
  • Files
  • t.py
  • t.c
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-03-12.21:11:59.988>
    created_at = <Date 2012-07-26.07:24:57.167>
    labels = ['ctypes']
    title = 'ctype with packed bitfields does not match native compiler'
    updated_at = <Date 2021-03-12.21:11:59.987>
    user = 'https://bugs.python.org/MikeCastle'

    bugs.python.org fields:

    activity = <Date 2021-03-12.21:11:59.987>
    actor = 'eryksun'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-12.21:11:59.988>
    closer = 'eryksun'
    components = ['ctypes']
    creation = <Date 2012-07-26.07:24:57.167>
    creator = 'Mike.Castle'
    dependencies = []
    files = ['26521', '26522']
    hgrepos = []
    issue_num = 15453
    keywords = []
    message_count = 4.0
    messages = ['166462', '166463', '166621', '167078']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'mark.dickinson', 'meador.inge', 'Mike.Castle']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '29753'
    type = None
    url = 'https://bugs.python.org/issue15453'
    versions = ['Python 2.7']

    @MikeCastle
    Copy link
    Mannequin Author

    MikeCastle mannequin commented Jul 26, 2012

    On debian/testing with python 2.7.3rc2 and gcc 4.7.1.

    I was trying to use ctypeslib to wrap libdvdnav and running into some issues porting my test C code to Python, eventually tracking it down to this difference between how ctypes and gcc handles bitfields in packed structs (i.e., affects real world problems).

    Basically, by default, gcc treats 8, 16 and 32 bit types in bit fields as 1 byte when using __attribute__ ((packed)) , while ctypes treats them each as 1, 2 and 4 bytes even when using _pack_ = 1. (and libdvdnav using packed a lot)

    Output from the attached programs:

    $ ./a.out
    1
    1
    1
    $ ./t.py
    1
    2
    4

    Removing the packed attribute or building with gcc -mms-bitfields both match the ctypes expectations (though -mms-bitfields is probably rarely used in Linux).

    @MikeCastle MikeCastle mannequin added the topic-ctypes label Jul 26, 2012
    @MikeCastle
    Copy link
    Mannequin Author

    MikeCastle mannequin commented Jul 26, 2012

    And the C version....

    @terryjreedy
    Copy link
    Member

    If you have not, please check other ctypes bitfields issues, especially bpo-15119 "ctypes mixed-types bitfield layout nonsensical; doesn't match compiler." to see if this is the same problem.

    @MikeCastle
    Copy link
    Mannequin Author

    MikeCastle mannequin commented Aug 1, 2012

    I did read through all of those before posting this one.

    As far as I can remember, none of those addressed the use of pack, which is the sole problem I'm facing here.

    Now maybe when all is said and done and all of these bitfield bugs are worked out, this one and that one will both be fixed. But I wasn't sure if this example would clarify or cloud those issues.

    @eryksun eryksun closed this as completed Mar 12, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @certik
    Copy link

    certik commented Jan 18, 2023

    This issue is now being tracked at #73939.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants