[issue35408] Python3.7 crash in PyCFunction_New due to broken _PyObject_GC_TRACK

STINNER Victor report at bugs.python.org
Tue Dec 4 09:24:56 EST 2018


STINNER Victor <vstinner at redhat.com> added the comment:

> Python3.7 crash in PyCFunction_New due to broken _PyObject_GC_TRACK

It's unrelated. Your must not use the Python API before Python is initialized. If you modify your code like that, it works as expected:

int main()
{
Py_Initialize();

  PyMethodDef methoddef_ = {
    const_cast< char* >( "myfun" ),
    (PyCFunction) myfun,
    METH_O,
    NULL
  };

  PyObject* myFunPtr = PyCFunction_New( &methoddef_, NULL );

Py_Finalize();
  return 0;
}

I don't think that it's a regression.

Python initialization is now well documented:
https://docs.python.org/dev/c-api/init.html

The documentation starts with:

"In an application embedding Python, the Py_Initialize() function must be called before using any other Python/C API functions; with the exception of a few functions and the global configuration variables."

PyCFunction_New() is an example of function of the Python C API.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35408>
_______________________________________


More information about the Python-bugs-list mailing list