classification
Title: Redundant doc field in TypeSpec
Type: Stage:
Components: Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: Egon.Smiwa, georg.brandl, loewis
Priority: release blocker Keywords: patch

Created on 2011-02-06 20:02 by loewis, last changed 2011-02-16 21:05 by loewis. This issue is now closed.

Files
File name Uploaded Description Edit
tp_doc.diff loewis, 2011-02-06 20:02
Messages (7)
msg128077 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-06 20:02
There are currently two ways to specify a type doc string in PyType_FromSpec; either through the doc field (which is not actually processed), or through Py_tp_doc (which works correctly).

The original concern for adding doc into the TypeSpec was that the slots may only refer to function pointers; as it turns out, putting character pointers in there works fine as well, so I recommend to drop the doc field in TypeSlot.

The patch also fixes some labelling in the xxlimited module.
msg128114 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-02-07 13:00
Looks good.
msg128427 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-11 20:48
Thansk for the review. Committed as r88400.
msg128665 - (view) Author: Egon Smiwa (Egon.Smiwa) Date: 2011-02-16 12:12
You bring the tp_doc parameter pointer 
into the ownership of the new typeobject?
and tp_doc is assumed to be created by pyObject_malloc?
IMO, if CPython wants to be the owner of the string parameter,
then it should make a copy of that parameter (tp_doc) 
and become owner of that copy.
msg128691 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-16 19:57
It's the same as the current tp_doc parameter for static type objects, and essentially like any other doc string in the C API. It's owned by the extension module, which must make sure it lives at least as long as the type object.
msg128696 - (view) Author: Egon Smiwa (Egon.Smiwa) Date: 2011-02-16 20:58
Hello, I'm just a app developer which is embedding the python32.dll
and I assumed (and wished) python would simply copy my allocated parameter-string into the type object (( spec->name) is copied too). I looked in the source and see this ownership confirmed:

static void 
type_dealloc(PyTypeObject *type)
.... PyObject_Free((char *)type->tp_doc);

The typeobject owns tp_doc and even requires a special allocation (pyobject_malloc), which is no problem if the type creates its own copy; the hosting app is not connected.
msg128697 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-16 21:05
I see. This is an issue independent of the issue discussed here, though, please open a new issue for that. I agree that either tp_dealloc should not release the string, or should make a copy that it can release.
History
Date User Action Args
2011-02-16 21:05:52loewissetnosy: loewis, georg.brandl, Egon.Smiwa
messages: + msg128697
2011-02-16 20:58:07Egon.Smiwasetnosy: loewis, georg.brandl, Egon.Smiwa
messages: + msg128696
2011-02-16 19:57:09loewissetnosy: loewis, georg.brandl, Egon.Smiwa
messages: + msg128691
2011-02-16 12:12:14Egon.Smiwasetnosy: + Egon.Smiwa
messages: + msg128665
2011-02-11 20:48:09loewissetstatus: open -> closed

messages: + msg128427
resolution: accepted
2011-02-07 13:00:08georg.brandlsetmessages: + msg128114
2011-02-06 20:02:06loewiscreate