Author vstinner
Recipients BTaskaya, WildCard65, ZackerySpytz, corona10, erlendaasland, hroncok, kj, nascheme, pablogsal, ronaldoussoren, serhiy.storchaka, shihai1991, steve.dower, vstinner
Date 2021-09-08.16:14:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1631117641.32.0.478239809727.issue39573@roundup.psfhosted.org>
In-reply-to
Content
Oh and obviously, it's not possible possible to define structures which *include* PyObject or PyVarObject if PyObject and PyVarObject become opaque. Example:

typedef struct {
    PyObject ob_base;
    Py_ssize_t ob_size; /* Number of items in variable part */
} PyVarObject;

This C code requires the PyObject structure to be fully defined (not being opaque).

A new C API and ABI where structures *don't* include PyObject or PyVarObject should be designed to allocate their members "before" the PyObject* pointer value. Something like the current PyGC_Head structure which is excluded from PyObject and stored *before* the "PyObject*" pointer.

Simplified code which allocates memory for an object implementin the GC protocol:

static PyObject *
_PyObject_GC_Malloc(size_t basicsize)
{
    ...
    size_t size = sizeof(PyGC_Head) + basicsize;
    ...
    PyGC_Head *g = (PyGC_Head *)PyObject_Malloc(size);
    ...
    PyObject *op = (PyObject *)(g + 1);
    return op;
}
History
Date User Action Args
2021-09-08 16:14:01vstinnersetrecipients: + vstinner, nascheme, ronaldoussoren, serhiy.storchaka, steve.dower, hroncok, corona10, ZackerySpytz, pablogsal, WildCard65, BTaskaya, shihai1991, erlendaasland, kj
2021-09-08 16:14:01vstinnersetmessageid: <1631117641.32.0.478239809727.issue39573@roundup.psfhosted.org>
2021-09-08 16:14:01vstinnerlinkissue39573 messages
2021-09-08 16:14:01vstinnercreate