Alexander Belopolsky <alexander.belopol...@gmail.com> wrote: > /* info->obj is either NULL or a borrowed reference. This > reference should not be decremented in PyBuffer_Release(). */
The semantics of PyMemoryView_FromBuffer() are problematic. This function is the odd one in memoryobject.c since it's the only function that breaks the link in consumer -> exporter chains. This has several consequences: 1) One can't rely on the fact that 'info' has PyBUF_FULL information. This is a major inconvenience and the reason for *a lot* of code in memoryobject.c that reconstructs PyBUF_FULL information. 2) One has to make a decision whether PyMemoryView_FromBuffer() steals the reference to view.obj or treats it as a borrowed reference. My view on this is that it's safer to treat it as a borrowed reference. Additionally, I can't see a scenario where PyMemoryView_FromBuffer(info) could be used for creating a non-temporary memoryview with automatic decref of info.obj: If 'info' is allocated on the stack, then the memoryview shouldn't be returned from a function. If 'info' is allocated on the heap, then who frees 'info' when the memoryview is deallocated? Permanent memoryviews can now be safely created with PyMemoryView_FromMemory(). PyMemoryView_FromBuffer() isn't really that useful any more. It's hard to document all this in a few lines. Perhaps you can open an issue for this? Stefan Krah _______________________________________________ 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