Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-28411: Isolate PyInterpreterState.modules #3575

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add _PyImport_EnsureInitialized().
  • Loading branch information
ericsnowcurrently committed Sep 14, 2017
commit 12f55d30be0a66760cb0806e06093e08f43c60da
1 change: 1 addition & 0 deletions Include/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleObject(
PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void);
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyImport_GetModuleDict(PyThreadState *tstate);
PyAPI_FUNC(void) _PyImport_EnsureInitialized(PyInterpreterState *interp);
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(PyObject *) PyImport_AddModuleObject(
Expand Down
15 changes: 15 additions & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ PyImport_GetModuleDict(void)
return _PyImport_GetModuleDict(PyThreadState_GET());
}

/* In some corner cases it is important to be sure that the import
machinery has been initialized (or not cleaned up yet). For
example, see issue #4236 and PyModule_Create2(). */

void
_PyImport_EnsureInitialized(PyInterpreterState *interp)
{
if (interp->modules == NULL)
goto notinitialized;
return;

notinitialized:
Py_FatalError("Python import machinery not initialized");
}


/* List of names to clear in sys */
static const char * const sys_deletes[] = {
Expand Down