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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4