Richard Oudkerk added the comment:

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().

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15903>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to