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

Skip to content

Commit eb7d1ce

Browse files
Add _PyImport_CheckSubinterpIncompatibleExtensionAllowed().
1 parent e30053b commit eb7d1ce

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
@@ -20,6 +20,9 @@ PyAPI_DATA(const struct _frozen *) _PyImport_FrozenStdlib;
2020
PyAPI_DATA(const struct _frozen *) _PyImport_FrozenTest;
2121
extern const struct _module_alias * _PyImport_FrozenAliases;
2222

23+
PyAPI_FUNC(int) _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
24+
const char *name);
25+
2326
#ifdef __cplusplus
2427
}
2528
#endif

Python/import.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,21 @@ exec_builtin_or_dynamic(PyObject *mod) {
23302330
return PyModule_ExecDef(mod, def);
23312331
}
23322332

2333+
int
2334+
_PyImport_CheckSubinterpIncompatibleExtensionAllowed(const char *name)
2335+
{
2336+
PyInterpreterState *interp = _PyInterpreterState_Get();
2337+
if (_PyInterpreterState_HasFeature(
2338+
interp, Py_RTFLAGS_MULTI_INTERP_EXTENSIONS)) {
2339+
assert(!_Py_IsMainInterpreter(interp));
2340+
PyErr_Format(PyExc_ImportError,
2341+
"module %s does not support loading in subinterpreters",
2342+
name);
2343+
return -1;
2344+
}
2345+
return 0;
2346+
}
2347+
23332348
#ifdef HAVE_DYNAMIC_LOADING
23342349

23352350
/*[clinic input]

0 commit comments

Comments
 (0)
0