Skip to content
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

Missing SWAP_INT in I_set_sw #67508

Closed
mgautierfr mannequin opened this issue Jan 25, 2015 · 9 comments
Closed

Missing SWAP_INT in I_set_sw #67508

mgautierfr mannequin opened this issue Jan 25, 2015 · 9 comments
Assignees
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@mgautierfr
Copy link
Mannequin

mgautierfr mannequin commented Jan 25, 2015

BPO 23319
Nosy @amauryfa, @abalkin, @vstinner, @meadori
Files
  • ctypes_swap_uint.patch: Fix the bug. Add the missing SWAP_INT.
  • ctypes_swap_uint_unittest.patch: Add missing SWAP_INT + unit_test
  • 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 = 'https://github.com/meadori'
    closed_at = <Date 2015-07-29.12:38:49.556>
    created_at = <Date 2015-01-25.18:53:37.217>
    labels = ['ctypes', 'type-bug']
    title = 'Missing SWAP_INT\xc2\xa0in I_set_sw'
    updated_at = <Date 2015-07-29.13:20:12.349>
    user = 'https://bugs.python.org/mgautierfr'

    bugs.python.org fields:

    activity = <Date 2015-07-29.13:20:12.349>
    actor = 'meador.inge'
    assignee = 'meador.inge'
    closed = True
    closed_date = <Date 2015-07-29.12:38:49.556>
    closer = 'vstinner'
    components = ['ctypes']
    creation = <Date 2015-01-25.18:53:37.217>
    creator = 'mgautierfr'
    dependencies = []
    files = ['37856', '39800']
    hgrepos = []
    issue_num = 23319
    keywords = ['patch']
    message_count = 9.0
    messages = ['234682', '245758', '246509', '246797', '247567', '247568', '247569', '247570', '247572']
    nosy_count = 6.0
    nosy_names = ['amaury.forgeotdarc', 'belopolsky', 'vstinner', 'meador.inge', 'python-dev', 'mgautierfr']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23319'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @mgautierfr
    Copy link
    Mannequin Author

    mgautierfr mannequin commented Jan 25, 2015

    I_set_sw function is missing a SWAP_INT.

    This leads to wrong set of bitfield value.

    Here is a script to reproduce:

    ----------

    from ctypes import *
    
    class HEADER(BigEndianStructure):
       _fields_ = ( ('pad', c_uint32, 16),
                    ('v1', c_uint32, 4),
                    ('v2', c_uint32, 12)
                  )
    
    b = bytearray(4)
    header = HEADER.from_buffer(b)
    
    header.type = 1
    assert b == b'\x00\x00\x10\x00'
    
    header.mode = 0x234
    assert b == b'\x00\x00\x12\x34'

    @mgautierfr mgautierfr mannequin added topic-ctypes type-bug An unexpected behavior, bug, or error labels Jan 25, 2015
    @mgautierfr
    Copy link
    Mannequin Author

    mgautierfr mannequin commented Jun 24, 2015

    A little ping.

    With a new patch integrating the unit test.

    @meadori
    Copy link
    Member

    meadori commented Jul 9, 2015

    I will review this today.

    @meadori meadori self-assigned this Jul 9, 2015
    @mgautierfr
    Copy link
    Mannequin Author

    mgautierfr mannequin commented Jul 16, 2015

    The bug is also present in Python 2.7.

    Is it possible to backport this fix ?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 29, 2015

    New changeset 935ae7f001e3 by Victor Stinner in branch '3.4':
    Issue bpo-23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch
    https://hg.python.org/cpython/rev/935ae7f001e3

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 29, 2015

    New changeset 88f2c4f12b56 by Victor Stinner in branch '2.7':
    Issue bpo-23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch
    https://hg.python.org/cpython/rev/88f2c4f12b56

    @vstinner
    Copy link
    Member

    Thanks for your report, patch and unit test Matthieu. I rewrote the unit test because your layout was too complex for my little brain :-) I also write a unit test for little endian. I applied your fix to Python 2.7, 3.4, 3.5 and 3.6.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 29, 2015

    New changeset 12b353f76447 by Victor Stinner in branch '2.7':
    Issue bpo-23319: Add Matthieu Gautier to Misc/ACKS
    https://hg.python.org/cpython/rev/12b353f76447

    New changeset 3caa68f55e3e by Victor Stinner in branch '3.4':
    Issue bpo-23319: Add Matthieu Gautier to Misc/ACKS
    https://hg.python.org/cpython/rev/3caa68f55e3e

    @meadori
    Copy link
    Member

    meadori commented Jul 29, 2015

    Thanks for committing this Victor. The patch looked good to me too. Sorry for not getting around to update the tracker.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-ctypes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants