On 29/08/2012 22:28, Alexander Belopolsky wrote:
I am trying to reconcile this section in 3.3 documentation:

"""
void *obj

A new reference to the exporting object. The reference is owned by the
consumer and automatically decremented and set to NULL by
PyBuffer_Release().

with the following comment in the code (Objects/memoryobject.c:762):

     /* info->obj is either NULL or a borrowed reference. This
reference
        should not be decremented in PyBuffer_Release(). */
I've studied this code in the interests of reproducing something similar for Jython.

The comment is in the context of PyMemoryView_FromBuffer(Py_buffer *info), at a point where the whole info struct is being copied to mbuf->master, then the code sets mbuf->master.obj = NULL. I think the comment means that the caller, which is in the role of consumer to the original exporter, owns the info struct and therefore the reference info.obj. That caller will eventually call PyBuffer_Release(info), which will result in a DECREF(obj) matching the INCREF(obj) that happened during bf_getbuffer(info). In this sense obj is a borrowed reference as far as the memoryview is concerned. mbuf->master must not also keep a reference, or it risks making a second call to DECREF(obj).

Jeff Allen
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to