[Python-Dev] pre-PEP: The Safe Buffer Interface
Thomas Heller
thomas.heller@ion-tof.com
Tue, 30 Jul 2002 18:09:40 +0200
[Scott]
> > A single lock interface can be implemented over an object without any
> > locking. Have the lockable object return simple "fixed buffer objects"
> > with a limited lifespan.
>
[Neil]
> This returns to the possibility of indeterminate lifespan as mentioned
> earlier in the thread.
>
Can't you do something like this (maybe this is what Scott has in mind):
static void _unlock(void *ptr, MyObject *self)
{
/* do whatever needed to unlock the object */
self->locked--;
Py_DECREF(self);
}
static PyObject*
MyObject_GetBuffer(MyObject *self)
{
/* Do whatever needed to lock the object */
self->lock++;
Py_INCREF(self);
return PyCObject_FromVoidPtrAndDesc(self->ptr,
self,
_unlock)
}
In plain text:
Provide a method which returns a 'view' into your object's
buffer after locking the object. The view holds a reference
to object, the objects is unlocked and decref'd when the
view is destroyed.
In practice something better than a PyCObject will be used,
and this one can even implement the 'fixed buffer' interface.
Thomas