You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python3.7 crash in PyCFunction_New due to broken _PyObject_GC_TRACK #79589
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2018-12-04.14:29:58.186>created_at=<Date2018-12-04.12:35:18.331>labels= ['interpreter-core', '3.7', 'invalid', 'type-crash']
title='Python3.7 crash in PyCFunction_New due to broken _PyObject_GC_TRACK'updated_at=<Date2018-12-05.14:07:25.296>user='https://bugs.python.org/etejedor'
Attached is a reproducer that calls PyCFunction_New. The reproducer runs normally with Python 3.6.5, but it crashes with Python 3.7.1. The reason seems to be that the _PyObject_GC_TRACK macro ends up being called and it is broken in Python3.7.
A fix for that macro seems to have been committed to master:
"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.
Activity
etejedor commentedon Dec 4, 2018
Attached is a reproducer that calls PyCFunction_New. The reproducer runs normally with Python 3.6.5, but it crashes with Python 3.7.1. The reason seems to be that the _PyObject_GC_TRACK macro ends up being called and it is broken in Python3.7.
A fix for that macro seems to have been committed to master:
#10507
vstinner commentedon Dec 4, 2018
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:
PyMethodDef methoddef_ = {
const_cast< char* >( "myfun" ),
(PyCFunction) myfun,
METH_O,
NULL
};
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.
vstinner commentedon Dec 4, 2018
I close the issue as "not a bug".
Even if the code "worked" in Python 3.6, it worked because of a mistake :-)
etejedor commentedon Dec 5, 2018
Hi Victor,
Thank you for clarifying.
If the call to PyCFunction_New is done from a C extension module, is it also necessary to call Py_Initialize()?
vstinner commentedon Dec 5, 2018
Py_Initialize() must always be called first.