This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sbt
Recipients amaury.forgeotdarc, jcea, pitrou, sbt, skrah
Date 2012-09-18.18:19:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1347992383.6.0.445489615232.issue15903@psf.upfronthosting.co.za>
In-reply-to
Content
I am rather confused about the ownership semantics when one uses PyMemoryView_FromBuffer().

It looks as though PyMemoryView_FromBuffer() "steals" ownership of the buffer since, when the associated _PyManagedBufferObject is garbage collected, PyBuffer_Release() is called on its copy of the buffer info.  However, the _PyManagedBufferObject does not own a reference of the base object, so one still needs to decref the base object (at some time when it is safe to do so).

So am I right in thinking that

  PyObject_GetBuffer(obj, &buf, ...);
  view = PyMemoryView_FromBuffer(&buf);     // view->master owns the buffer, but view->master->obj == NULL
  ...
  Py_DECREF(view);                          // releases buffer (assuming no other exports)
  Py_XDECREF(buf.obj);

has balanced refcounting and is more or less equivalent to

  view = PyMemoryView_FromObject(obj);
  ...
  Py_DECREF(view);

The documentation is not very helpful.  It just says that calls to PyObject_GetBuffer() must be matched with calls to PyBuffer_Release().
History
Date User Action Args
2012-09-18 18:19:43sbtsetrecipients: + sbt, jcea, amaury.forgeotdarc, pitrou, skrah
2012-09-18 18:19:43sbtsetmessageid: <1347992383.6.0.445489615232.issue15903@psf.upfronthosting.co.za>
2012-09-18 18:19:43sbtlinkissue15903 messages
2012-09-18 18:19:42sbtcreate