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

Replace buffer()-->memoryview() in Lib/ctypes/test/ #51952

Closed
florentx mannequin opened this issue Jan 14, 2010 · 13 comments
Closed

Replace buffer()-->memoryview() in Lib/ctypes/test/ #51952

florentx mannequin opened this issue Jan 14, 2010 · 13 comments
Assignees
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@florentx
Copy link
Mannequin

florentx mannequin commented Jan 14, 2010

BPO 7703
Nosy @theller, @pitrou, @florentx
Files
  • issue7703_ctypes_memoryview.diff: Patch, apply to trunk
  • issue7703_test_ctypes.diff: Patch, apply to trunk
  • 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/theller'
    closed_at = <Date 2010-03-22.16:09:41.610>
    created_at = <Date 2010-01-14.14:17:09.816>
    labels = ['ctypes', 'type-bug']
    title = 'Replace buffer()-->memoryview() in Lib/ctypes/test/'
    updated_at = <Date 2010-03-22.16:09:41.580>
    user = 'https://github.com/florentx'

    bugs.python.org fields:

    activity = <Date 2010-03-22.16:09:41.580>
    actor = 'flox'
    assignee = 'theller'
    closed = True
    closed_date = <Date 2010-03-22.16:09:41.610>
    closer = 'flox'
    components = ['ctypes']
    creation = <Date 2010-01-14.14:17:09.816>
    creator = 'flox'
    dependencies = []
    files = ['15875', '15876']
    hgrepos = []
    issue_num = 7703
    keywords = ['patch']
    message_count = 13.0
    messages = ['97765', '97766', '97768', '97769', '97772', '97773', '97867', '97868', '97872', '97877', '97885', '97886', '101518']
    nosy_count = 3.0
    nosy_names = ['theller', 'pitrou', 'flox']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue7703'
    versions = ['Python 2.7']

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jan 14, 2010

    In order to upgrate the tests for ctypes, following changes are required:

    • binascii.hexlify should accept memoryview() objects
    • the ctypes character buffer should accept assignment of memoryview() objects using their "raw" property

    Then we can backport the Py3 ctypes tests to Py2.

    @florentx florentx mannequin added the type-bug An unexpected behavior, bug, or error label Jan 14, 2010
    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jan 14, 2010

    Patches attached:

    @florentx florentx mannequin added the topic-ctypes label Jan 14, 2010
    @florentx florentx mannequin assigned theller Jan 14, 2010
    @pitrou
    Copy link
    Member

    pitrou commented Jan 14, 2010

    Does binascii still work with array.array objects? Also, there should be additional tests for compatibility of binascii with memoryview objects.

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jan 14, 2010

    Additional tests for binascii.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 14, 2010

    Please be careful with the coding style. Stuff like:

    + if (_PyString_Resize(&rv, 2*out_len) < 0) \
    + { Py_DECREF(rv); PyBuffer_Release(&pin); return NULL; } \

    should be spread out on several lines.
    Otherwise, the binascii patch looks good.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 14, 2010

    I've now committed the binascii patch + tests to trunk, and merged the tests into py3k.

    Note: binascii_a2b_hqx() still uses the "t#" argument specifier in py3k as well as in trunk, this would deserve a separate patch.

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jan 16, 2010

    Patch for the last "t#" format string in binascii module.
    And provide additional tests.

    PS: I removed this comment. IMHO, it is a wrong assertion:
    "# The hqx test is in test_binhex.py"

    @pitrou
    Copy link
    Member

    pitrou commented Jan 16, 2010

    I don't think the bytes -> bytearray changes are useful, e.g.:

    •    fillers = ""
      

    + fillers = bytearray()

    As for:

    + try:
    + f(empty)
    + except SystemError, err:
    + self.fail("{}({!r}) raises SystemError: {}".format(func, empty, err))
    + except Exception, err:
    + self.fail("{}({!r}) raises {!r}".format(func, empty, err))

    The "except SystemError" is pointless, since "except Exception" will catch SystemError anyway.

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jan 16, 2010

    Changed.

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jan 16, 2010

    Removed no-op str("...") conversions.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 16, 2010

    When the following snippet is taken:

    	if (_PyString_Resize(&rv,
    			   (bin_data -
    			    (unsigned char *)PyString_AS_STRING(rv))) < 0) {
    		PyBuffer_Release(&pascii);
    		Py_DECREF(rv);
    		rv = NULL;
    	}

    pascii will get released a second time at the end of function. The rest is fine, I'm gonna fix it myself.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 16, 2010

    The a2b_hqx() patch was committed in r77528 (trunk) and r77529 (py3k). Thanks again!

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Mar 22, 2010

    Fixed with r79288 and r79295.

    @florentx florentx mannequin closed this as completed Mar 22, 2010
    @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