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

struct.unpack doens't support buffer protocol objects #44012

Closed
moese mannequin opened this issue Sep 22, 2006 · 8 comments
Closed

struct.unpack doens't support buffer protocol objects #44012

moese mannequin opened this issue Sep 22, 2006 · 8 comments
Labels
stdlib Python modules in the Lib dir

Comments

@moese
Copy link
Mannequin

moese mannequin commented Sep 22, 2006

BPO 1563759
Nosy @loewis, @rhettinger
Files
  • test_struct.py: Append to end of test_struct.py
  • test_struct_run.py: Runnable test version for both Python 2.4 and 2.5
  • 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 2007-04-04.20:32:41.000>
    created_at = <Date 2006-09-22.22:17:45.000>
    labels = ['library']
    title = "struct.unpack doens't support buffer protocol objects"
    updated_at = <Date 2007-04-04.20:32:41.000>
    user = 'https://bugs.python.org/moese'

    bugs.python.org fields:

    activity = <Date 2007-04-04.20:32:41.000>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2006-09-22.22:17:45.000>
    creator = 'moese'
    dependencies = []
    files = ['2149', '2150']
    hgrepos = []
    issue_num = 1563759
    keywords = []
    message_count = 8.0
    messages = ['29930', '29931', '29932', '29933', '29934', '29935', '29936', '29937']
    nosy_count = 3.0
    nosy_names = ['loewis', 'rhettinger', 'moese']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1563759'
    versions = ['Python 2.5']

    @moese
    Copy link
    Mannequin Author

    moese mannequin commented Sep 22, 2006

    If you pass an object which supports the buffer
    protocol to struct.unpack it will fail because it
    specifically checks for a string.

    You should use PyObject_AsReadBuffer instead.

    If this code is performance critical, you could add an
    unpack_buffer method or something like that.

    @moese moese mannequin closed this as completed Sep 22, 2006
    @moese moese mannequin added the stdlib Python modules in the Lib dir label Sep 22, 2006
    @moese moese mannequin closed this as completed Sep 22, 2006
    @moese moese mannequin added the stdlib Python modules in the Lib dir label Sep 22, 2006
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 23, 2006

    Logged In: YES
    user_id=21627

    Why is this a bug?

    @moese
    Copy link
    Mannequin Author

    moese mannequin commented Sep 23, 2006

    Logged In: YES
    user_id=1067739

    Well, because it broke previously working code and there is
    no warning in the documentation about that.

    In the mean-time, I've found out about pack_into and
    unpack_from which accept buffer like objects. Note that they
    are not documented in the struct module section, only
    mentioned in the "What's new" chapter.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 23, 2006

    Logged In: YES
    user_id=21627

    Ah, so you say that was working previously? It's a bug,
    then. Can you provide a test case?

    @moese
    Copy link
    Mannequin Author

    moese mannequin commented Sep 23, 2006

    Logged In: YES
    user_id=1067739

    The actual code which broke used a Pointer extension class
    implemented in C++.

    I reproduced the problem using array.array. Using array in
    this way (without calling tostring) looks a bit weird.

    @moese
    Copy link
    Mannequin Author

    moese mannequin commented Sep 23, 2006

    Logged In: YES
    user_id=1067739

    test_struct_run.py works in 2.4, throws exception in 2.5

    @rhettinger
    Copy link
    Contributor

    This was due to Bob Ippolito's commit in revision 46184.

    @rhettinger
    Copy link
    Contributor

    Fixed. See revision 54690.

    @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
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant