[Python-Dev] PEP 298
Martin v. Löwis
Martin v. Löwis
Sat, 14 Dec 2002 12:43:49 +0100
> It's not a flaw, and that's an odd criticism. There aren't many
functions
> in the Python API that are documented in terms of what happens when
you
> misuse them.
There sure are. Looking at the sys module:
- exit: Most systems require it to be in the range 0-127, and produce
undefined results otherwise.
- _getframe: If that is deeper than the call stack, ValueError is
raised.
- setdefaultencoding: If name does not match any available encoding,
LookupError is raised.
and so on.
> Think of it as more like knowing when you have to call Py_INCREF and
> Py_DECREF. If you want to keep a pointer to an object, you call
Py_INCREF.
Precisely, and this is my complaint. It ought to be like incref/decref,
but isn't. If I do incref without decref, I know what happens: the
object stays alive. If I do acquire without release, I would *expect*
that the the buffer stays acquired, but this is not necessarily the
case.
> If you think it's an issue, the act of locking the buffer could
increase
> the refcount too...
I know something is flawed. Whether this is fixed by changing the spec,
or by changing the implementation, I don't know.
If the spec means "the pointer is not valid if the reference count of
the underlying object goes to zero", it should say so. If the spec means
"if the reference count goes to zero while the object is locked, Python
aborts", it should say so. If the spec means "the buffer will not be
released while it is acquired", it should say so. From reading the spec,
I cannot tell which one it is. From reading the implementation, I can
tell "it depends on the type". I thought that "depends on the type" is
what this API was meant to eliminate.
> How would you use this at the Python level? I don't see how it is
useful
> outside of a C extension.
I want to pass buffers to fcntl, and want fcntl to change the buffer
in-place. Currently, fcntl will need to keep the interpreter lock for
that.
For that to work, I need to create a locked buffer, and I need to find
out its address. I can create a buffer using the buffer builtin, but it
won't be a locked one, and I need to find out its address, but I can't.
Regards,
Martin