-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-43551: fix PyImport_Import use static silly_list, under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi sub interpreters cause crash. #24929
bpo-43551: fix PyImport_Import use static silly_list, under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi sub interpreters cause crash. #24929
Conversation
Hello, this change seems might not need to update news. |
Python/import.c
Outdated
@@ -1745,7 +1745,7 @@ PyObject * | |||
PyImport_Import(PyObject *module_name) | |||
{ | |||
PyThreadState *tstate = _PyThreadState_GET(); | |||
static PyObject *silly_list = NULL; | |||
PyObject *silly_list = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"silly list" is not a great name, I propose to rename it to "from_list".
Also you must put a DECREF somewhere, otherwise the code will leak.
@@ -0,0 +1 @@ | |||
fix PyImport_Import use static silly_list, under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi sub interpreters cause crash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--with-experimental-isolated-subinterpreters option is supposed to remain secret!
Either remove your NEWS entry, or just say "subinterpreters". For example, "Fix the import function for subinterpreters." I'm not sure that it's worth it to document every single subinterpreter fix.
Python/import.c
Outdated
static PyObject *builtins_str = NULL; | ||
static PyObject *import_str = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static variables are bad, they don't work in subinterpreters. You can use the _Py_IDENTIFIER() API with _PyUnicode_FromId() (return a borrowed reference), it is compatible with subinterpreters.
@vstinner thanks for your review. I have fix these problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it's way better, thanks! I have remarks on the coding style.
Python/import.c
Outdated
if (silly_list == NULL) | ||
return NULL; | ||
} | ||
import_str = _PyUnicode_FromId(&PyId___import__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can define the variable here (same for the 2 other variables) and add a comment to mention that it's a borrowed ref
import_str = _PyUnicode_FromId(&PyId___import__); | |
PyObject *import_str = _PyUnicode_FromId(&PyId___import__); // borrowed ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a refleak (unrelated to your PR) at:
/* No globals -- use standard builtins, and fake globals */
builtins = PyImport_ImportModuleLevel("builtins",
NULL, NULL, NULL, 0);
if (builtins == NULL)
return NULL; // <=== HERE
Please replace return NULL
with goto err
and add braces (PEP 7).
You may also replace return NULL
with goto err
at:
PyObject *from_list = PyList_New(0);
if (from_list == NULL) {
return NULL;
}
You might also remove trailing spaces at line 1761 :-D (my text editor highlights them ;-))
under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi subinterpreters cause crash.
|
https://bugs.python.org/issue43551
fix PyImport_Import use static silly_list under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi subinterpreters cause crash.
Under the sub interpreters parallel, PyObject_CallFunction clean stack,
Py_DECREF(stack[i]), Py_DECREF silly_list is not thread safe. cause crash
https://bugs.python.org/issue43551