-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-28411: Remove "modules" field from Py_InterpreterState. #1638
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
Changes from 26 commits
70f6e19
10f7443
5ea0e3b
29780ec
e6de215
29f6b7c
b77d73f
8275633
7c62114
428d223
833b00b
e0e51d2
88aadeb
79320bd
6a0215c
dabd187
58d9be7
e3b0f0c
d9c6b79
e3565f9
9946341
08e556e
f043e47
b2edd25
0eced28
a85a11f
9ba4c43
f837a61
101aa31
8f8a7a2
3a56648
619b0a0
57eeb5b
6544fa2
8e86c53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,11 +38,26 @@ PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleObject( | |
| ); | ||
| #endif | ||
| PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void); | ||
| #ifndef Py_LIMITED_API | ||
| PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *); | ||
| #endif | ||
| PyAPI_FUNC(PyObject *) PyImport_GetModule(PyObject *name); | ||
| #ifndef Py_LIMITED_API | ||
| PyAPI_FUNC(PyObject *) _PyImport_GetModule(PyObject *name); | ||
| PyAPI_FUNC(PyObject *) _PyImport_GetModuleWithError(PyObject *name); | ||
| PyAPI_FUNC(PyObject *) _PyImport_GetModuleString(const char *name); | ||
|
||
| PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(struct _Py_Identifier *name); | ||
| PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module); | ||
| PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module); | ||
| #endif | ||
| #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 | ||
| PyAPI_FUNC(PyObject *) PyImport_AddModuleObject( | ||
| PyObject *name | ||
| ); | ||
| #endif | ||
| #ifndef Py_LIMITED_API | ||
| PyAPI_FUNC(PyObject *) _PyImport_AddModuleObject(PyObject *, PyObject *); | ||
| #endif | ||
| PyAPI_FUNC(PyObject *) PyImport_AddModule( | ||
| const char *name /* UTF-8 encoded string */ | ||
| ); | ||
|
|
@@ -97,14 +112,20 @@ PyAPI_FUNC(int) _PyImport_ReleaseLock(void); | |
| PyAPI_FUNC(void) _PyImport_ReInitLock(void); | ||
|
|
||
| PyAPI_FUNC(PyObject *) _PyImport_FindBuiltin( | ||
| const char *name /* UTF-8 encoded string */ | ||
| const char *name, /* UTF-8 encoded string */ | ||
| PyObject *modules | ||
| ); | ||
| PyAPI_FUNC(PyObject *) _PyImport_FindExtensionObject(PyObject *, PyObject *); | ||
| PyAPI_FUNC(PyObject *) _PyImport_FindExtensionObjectEx(PyObject *, PyObject *, | ||
| PyObject *); | ||
| PyAPI_FUNC(int) _PyImport_FixupBuiltin( | ||
| PyObject *mod, | ||
| const char *name /* UTF-8 encoded string */ | ||
| const char *name, /* UTF-8 encoded string */ | ||
| PyObject *modules | ||
| ); | ||
| PyAPI_FUNC(int) _PyImport_FixupExtensionObject(PyObject*, PyObject *, PyObject *); | ||
| PyAPI_FUNC(int) _PyImport_FixupExtensionObjectEx(PyObject*, PyObject *, | ||
| PyObject *, PyObject *); | ||
|
|
||
| struct _inittab { | ||
| const char *name; /* ASCII encoded string */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,6 @@ typedef struct _is { | |
|
|
||
| int64_t id; | ||
|
|
||
| PyObject *modules; | ||
|
||
| PyObject *modules_by_index; | ||
| PyObject *sysdict; | ||
| PyObject *builtins; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ``PyInterpreterState`` has a "modules" field that is copied into | ||
| ``sys.modules`` during interpreter startup. This causes problems if a | ||
| program replaces ``sys.modules`` with something else. To solve this we | ||
| eliminate ``PyInterpreterState.modules``. |
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.
What happens if the module is not found?
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.
Seems this function returns a borrowed reference. This should be specially emphasized.
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.
It shouldn't be returning a borrowed reference.
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.
The only code that uses it (
_pickle_Unpickler_find_class_impl) is written asPyImport_GetModulereturning a borrowed reference.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.
That was an omission on my part. I should have moved the Py_DECREF(module) line down.
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 should document that the function returns NULL if the module is not already imported, but raise an exception and return NULL on exception. I don't think that it's obvious from the current doc.