Getting a locked buffer from objects (PEP 3118)

K

KKH

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
 
S

Stefan Behnel

KKH said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top