Message170658
| 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:43 | sbt | set | recipients:
+ sbt, jcea, amaury.forgeotdarc, pitrou, skrah |
| 2012年09月18日 18:19:43 | sbt | set | messageid: <1347992383.6.0.445489615232.issue15903@psf.upfronthosting.co.za> |
| 2012年09月18日 18:19:43 | sbt | link | issue15903 messages |
| 2012年09月18日 18:19:42 | sbt | create |
|