Getting a locked buffer from objects (PEP 3118)

Discussion in 'Python' started by KKH, Dec 25, 2008.

  1. KKH

    KKH Guest

    Hi,

    it seems the whole locking-theme has gone from PEP 3118 (PyBUF_LOCK is gone). Yet the string and byte objects seem to provide locked buffers through PyArg_Parse arguments s*, y* and z* (documentation says so).

    Could someone please clarify the situation for me: Is it save to release the GIL after getting a reference to a buffer-object by the arguments above and only talking to this buffer while the GIL is gone?

    And while we are at it :) Is "PyArg_Parse('[syz]*'..." the only way to get a locked buffer-view from string/byte objects?

    Regards
    ebfe
     
    KKH, Dec 25, 2008
    #1
    1. Advertising

  2. KKH wrote:
    > it seems the whole locking-theme has gone from PEP 3118 (PyBUF_LOCK is
    > gone). Yet the string and byte objects seem to provide locked buffers
    > through PyArg_Parse arguments s*, y* and z* (documentation says so).


    Might be a left-over. All locking the buffer interface itself provides is
    the guarantee that the buffer will not move between getting and releasing a
    buffer. Everything else must be handled at the application level.


    > Could someone please clarify the situation for me: Is it save to release
    > the GIL after getting a reference to a buffer-object by the arguments
    > above and only talking to this buffer while the GIL is gone?


    The buffer interface is a pure C level interface. All you get is a pointer
    to a memory buffer plus some meta data. No Python references are involved
    from that point on. So it only depends on your own code if it's safe to
    free the GIL or not.


    > And while we are at it :) Is "PyArg_Parse('[syz]*'..." the only way to
    > get a locked buffer-view from string/byte objects?


    What kind of locking do you need?

    Stefan
     
    Stefan Behnel, Dec 27, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TS
    Replies:
    4
    Views:
    849
    Steven Cheng[MSFT]
    Feb 1, 2006
  2. Raja
    Replies:
    12
    Views:
    24,646
    John Harrison
    Jun 21, 2004
  3. Christoph Becker-Freyseng

    PEP for new modules (I read PEP 2)

    Christoph Becker-Freyseng, Jan 15, 2004, in forum: Python
    Replies:
    3
    Views:
    390
    Gerrit Holl
    Jan 16, 2004
  4. Replies:
    2
    Views:
    623
    sergejusz
    Mar 26, 2007
  5. Lie
    Replies:
    25
    Views:
    772
    Dafydd Hughes
    Dec 18, 2007
Loading...

Share This Page