8000 Add _PyImport_CheckSubinterpIncompatibleExtensionAllowed(). · python/cpython@ed505a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed505a6

Browse files
Add _PyImport_CheckSubinterpIncompatibleExtensionAllowed().
1 parent 49b4895 commit ed505a6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Include/internal/pycore_import.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ PyAPI_DATA(const struct _frozen *) _PyImport_FrozenStdlib;
5252
PyAPI_DATA(const struct _frozen *) _PyImport_FrozenTest;
5353
extern const struct _module_alias * _PyImport_FrozenAliases;
5454

55+
PyAPI_FUNC(int) _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
56+
const char *name);
57+
5558
#ifdef __cplusplus
5659
}
5760
#endif

Python/import.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,21 @@ exec_builtin_or_dynamic(PyObject *mod) {
23952395
return PyModule_ExecDef(mod, def);
23962396
}
23972397

2398+
int
2399+
_PyImport_CheckSubinterpIncompatibleExtensionAllowed(const char *name)
2400+
{
2401+
PyInterpreterState *interp = _PyInterpreterState_Get();
2402+
if (_PyInterpreterState_HasFeature(
2403+
interp, Py_RTFLAGS_MULTI_INTERP_EXTENSIONS)) {
2404+
assert(!_Py_IsMainInterpreter(interp));
2405+
PyErr_Format(PyExc_ImportError,
2406+
"module %s does not support loading in subinterpreters",
2407+
name);
2408+
return -1;
2409+
}
2410+
return 0;
2411+
}
2412+
23982413
#ifdef HAVE_DYNAMIC_LOADING
23992414

24002415
/*[clinic input]

0 commit comments

Comments
 (0)
0