A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20150510/a28e70dd/attachment.html below:

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">


  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <br>
    In Python's argument parsing code (convertsimple in
    Python/getargs.c), a couple of format units* accept "read-only
    bytes-like objects", aka read-only buffer objects.  They call a
    helper function called convertbuffer() which uses the buffer
    protocol to extract a pointer to the memory.<br>
    <br>
    Here's the relevant bit of code:<br>
    <blockquote><tt>static Py_ssize_t<br>
        convertbuffer(PyObject *arg, void **p, char **errmsg)<br>
        {<br>
        Py_buffer view;<br>
        ...<br>
        <br>
        if (getbuffer(arg, &view, errmsg) < 0)<br>
        Â Â Â  return -1;<br>
        count = view.len;<br>
        *p = view.buf;<br>
        PyBuffer_Release(&view);<br>
        return count;<br>
        }</tt><br>
    </blockquote>
    <br>
    getbuffer() uses the buffer protocol to fill in the "view" buffer. 
    If it's successful, "view" is a valid buffer.  We store the pointer
    to the buffer's memory in output parameter p.<br>
    <br>
    THEN WE RELEASE THE BUFFER.<br>
    <br>
    THEN WE RETURN TO THE CALLER.<br>
    <br>
    In case you missed the big helpful capital letters, we are returning
    a pointer given to us by PyObject_GetBuffer(), which we have already
    released by calling PyBuffer_Release().  The buffer protocol
    documentation for
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    bf_releasebuffer makes it sound like this pointer could easily be
    invalid after the release call finishes.<br>
    <br>
    Am I missing something, or is this code relying on an implementation
    detail it shouldn't--namely that you can continue using a pointer to
    some (most? all?) buffer memory even after releasing it?<br>
    <br>
    <br>
    <i>/arry</i><br>
    <br>
    * Specifically: s# y y# z#<br>
  </body>
</html>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4