On Thu, Jan 14 2021, Tim Peters wrote: > I'm not clear on exactly what it is you're after, but CPython faces > the same question all the time: _given_ a pointer to an object, is > there, or is there not, a GC header prepended? That's answered by > this C API function: > > """ > int PyObject_IS_GC(PyObject *obj) > > Returns non-zero if the object implements the garbage collector > protocol, otherwise returns 0. > > The object cannot be tracked by the garbage collector if this function > returns 0. > """ > > FYI, the implementation usually resolves it by looking at whether > obj's type object has the Py_TPFLAGS_HAVE_GC flag set.
Right, but that only works if you have the PyObject address. If you all got is a pointer returned by PyObject_Malloc(), you don't know if the PyObject is at this pointer address, or after the PyGC_HEAD header that is prepended. :( -- Julien Danjou /* Free Software hacker https://julien.danjou.info */ _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/Z6GJUNKOFE2IN6EKQKDBBMX4SUZ36ITU/ Code of Conduct: http://python.org/psf/codeofconduct/