-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
The new_interpreter()
function incorrectly returns _PyStatus_OK()
on some error code paths
#112729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The proposed changes SGTM |
Py_NewInterpreter() returns NULL if PyInterpreterState_New() or _PyThreadState_New() returns NULL. Sadly, this behavior is not documented: https://docs.python.org/dev/c-api/init.html#c.Py_NewInterpreter It's possible to recover from Py_NewInterpreter() returning NULL, whereas calling Py_ExitStatusException() kills the process: it's not possible to recover from such error.
Are you sure about that? |
@vstinner, please take a look at the current implementations. You can also test it yourself by injecting a
Lines 756 to 769 in 2d9d3a9
You can read through the called
|
I looked at the code and it looks dangerous to change _PyInterpreterState_New() and PyInterpreterState_New() to return NULL on memory allocation error, simply because it wasn't possible before. Memory allocation failure is unlikely and so I'm ok with using _PyStatus_NO_MEMORY() in this case. |
Bug report
The following code paths should probably returns some sort of exception status (possibly
_PyStatus_NO_MEMORY()
).cpython/Python/pylifecycle.c
Lines 2084 to 2088 in a1551b4
cpython/Python/pylifecycle.c
Lines 2090 to 2096 in a1551b4
Note that
PyInterpreterState_New()
currently never returns NULL -- it callsPy_FatalError()
instead -- but we should probably still handle that case as well._PyThreadState_New
can return NULL when out of memory.cc @ericsnowcurrently
The text was updated successfully, but these errors were encountered: