Author llllllllll
Recipients llllllllll
Date 2019-06-13.21:31:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560461494.72.0.39613394712.issue37270@roundup.psfhosted.org>
In-reply-to
Content
When using PyType_FromSpec, the memory for PyType_Spec.name, Py_tp_methods, and Py_tp_members needs to somehow outlive the resulting type. This makes it hard to use this interface to generate types without just leaking the memory for these arrays, which is bad if you are programatically creating short-lived types.

I posted about this on capi-sig, and the response seemed to be that it would be to replace the things that currently hold pointers into the array with copies of the data.

Remove internal usages of PyMethodDef and PyGetSetDef.

For PyMethodDef, change PyCFunctionObject to replace the PyMethodDef* member
with a PyCFunctionBase member. The PyCFunctionBase is a new struct to hold the
managed values of a PyMethodDef. This type is shared between PyCFunction and the
various callable descriptor objects. A PyCFunctionBase is like a PyMethodDef but
replaces the char* members with PyObject* members.

For PyGetSetDef, inline the members on the resulting PyGetSetDescrObject,
replacing all char* members with PyObject* members. The memory for the closure
is *not* managed, adding support for that would likely require an API change and
can be done in a future change.

For the tp_name field, instead of setting it directly to the value of
PyType_Spec.name, set it to the result of PyUnicode_AsUTF8(ht_name), where
ht_name is the PyUnicode object created from the original spec name. This is the
same trick used to properly manage this pointer for heap types when the __name__
is reassigned.
History
Date User Action Args
2019-06-13 21:31:34llllllllllsetrecipients: + llllllllll
2019-06-13 21:31:34llllllllllsetmessageid: <1560461494.72.0.39613394712.issue37270@roundup.psfhosted.org>
2019-06-13 21:31:34lllllllllllinkissue37270 messages
2019-06-13 21:31:34llllllllllcreate