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.

classification
Title: ~Py_buffer.obj field is undocumented, though not hidden
Type: Stage: needs patch
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Problems with Py_buffer management in memoryobject.c (and elsewhere?)
View: 10181
Assigned To: docs@python Nosy List: docs@python, kermode, mark.dickinson, ncoghlan, pitrou
Priority: normal Keywords:

Created on 2010-09-30 17:46 by kermode, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bufobj.c.gz kermode, 2010-09-30 17:46 Embedded Python C program; crashes with Python 3.2a2
Messages (4)
msg117754 - (view) Author: Lenard Lindstrom (kermode) Date: 2010-09-30 17:46
Python 3.2a2+ (py3k:85072M, Sep 29 2010, 12:11:17) (from SVN)
[GCC 4.4.5 20100728 (prerelease)] on linux2 (Debian squeeze)

The ~Py_buffer.obj field is undocumented. Yet memoryview, that acts as a wrapper, includes the field in gc traversal. Also, if the field is not initialized by bf_getbuffer its value can be indeterminate. For memoryview the gc can crash (see attached C demo program).
msg117770 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-10-01 01:10
The recommended way is to use PyBuffer_FillInfo() (and then fill in any additional data if necessary), which will set the pointer and incref it itself.

I agree all this is a bit poorly documented.
msg117780 - (view) Author: Lenard Lindstrom (kermode) Date: 2010-10-01 07:26
This will work for bf_getbuffer, though having PyObject_GetBuffer set 
the obj field before passing it to the callback might be safer. Also, 
this does not address the case with wrapper types like memoryview. What 
happens if ~Py_buffer.obj is not visited in tp_traverse? Should this be 
documented?
msg125330 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-01-04 14:56
Closing as a dupe of 10181, but transferring Lenard's comments over there.
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54210
2011-01-04 14:56:10ncoghlansetstatus: open -> closed
superseder: Problems with Py_buffer management in memoryobject.c (and elsewhere?)
messages: + msg125330

nosy: mark.dickinson, ncoghlan, kermode, pitrou, docs@python
resolution: duplicate
2011-01-04 01:03:42pitrousetnosy: + mark.dickinson, ncoghlan
2010-10-01 07:26:12kermodesetmessages: + msg117780
2010-10-01 01:10:22pitrousetassignee: docs@python
components: + Documentation, - Interpreter Core
versions: + Python 3.1, Python 2.7
nosy: + docs@python, pitrou

messages: + msg117770
stage: needs patch
2010-09-30 17:46:45kermodecreate