Skip to content

Commit a4c7ca3

Browse files
committed
restore stable ABI symbols
1 parent 8b7a020 commit a4c7ca3

File tree

6 files changed

+54
-0
lines changed

6 files changed

+54
-0
lines changed

Lib/test/test_capi/test_import.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def test_importmodule(self):
133133
self.assertRaises(UnicodeDecodeError, importmodule, b'\xff')
134134
# CRASHES importmodule(NULL)
135135

136+
def test_importmodulenoblock(self):
137+
# Test deprecated (stable ABI only) PyImport_ImportModuleNoBlock()
138+
importmodulenoblock = _testlimitedcapi.PyImport_ImportModuleNoBlock
139+
with check_warnings(('', DeprecationWarning)):
140+
self.check_import_func(importmodulenoblock)
141+
self.assertRaises(UnicodeDecodeError, importmodulenoblock, b'\xff')
142+
143+
# CRASHES importmodulenoblock(NULL)
144+
136145
def check_frozen_import(self, import_frozen_module):
137146
# Importing a frozen module executes its code, so start by unloading
138147
# the module to execute the code in a new (temporary) module.

Lib/test/test_stable_abi_ctypes.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Misc/stable_abi.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@
886886
added = '3.2'
887887
[function.PyImport_ImportModuleLevel]
888888
added = '3.2'
889+
[function.PyImport_ImportModuleNoBlock]
890+
added = '3.2'
891+
abi_only = true
889892
[function.PyImport_ReloadModule]
890893
added = '3.2'
891894
[function.PyInterpreterState_Clear]

Modules/_testlimitedcapi/import.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ pyimport_importmodule(PyObject *Py_UNUSED(module), PyObject *args)
108108
}
109109

110110

111+
/* Test PyImport_ImportModuleNoBlock() */
112+
static PyObject *
113+
pyimport_importmodulenoblock(PyObject *Py_UNUSED(module), PyObject *args)
114+
{
115+
extern PyObject *PyImport_ImportModuleNoBlock(const char *name);
116+
117+
const char *name;
118+
Py_ssize_t size;
119+
if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
120+
return NULL;
121+
}
122+
return PyImport_ImportModuleNoBlock(name);
123+
}
124+
125+
111126
/* Test PyImport_ImportModuleEx() */
112127
static PyObject *
113128
pyimport_importmoduleex(PyObject *Py_UNUSED(module), PyObject *args)
@@ -268,6 +283,7 @@ static PyMethodDef test_methods[] = {
268283
{"PyImport_AddModuleRef", pyimport_addmoduleref, METH_VARARGS},
269284
{"PyImport_Import", pyimport_import, METH_O},
270285
{"PyImport_ImportModule", pyimport_importmodule, METH_VARARGS},
286+
{"PyImport_ImportModuleNoBlock", pyimport_importmodulenoblock, METH_VARARGS},
271287
{"PyImport_ImportModuleEx", pyimport_importmoduleex, METH_VARARGS},
272288
{"PyImport_ImportModuleLevel", pyimport_importmodulelevel, METH_VARARGS},
273289
{"PyImport_ImportModuleLevelObject", pyimport_importmodulelevelobject, METH_VARARGS},

PC/python3dll.c

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/import.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,6 +3426,30 @@ PyImport_ImportModule(const char *name)
34263426
}
34273427

34283428

3429+
/* Import a module without blocking
3430+
*
3431+
* At first it tries to fetch the module from sys.modules. If the module was
3432+
* never loaded before it loads it with PyImport_ImportModule() unless another
3433+
* thread holds the import lock. In the latter case the function raises an
3434+
* ImportError instead of blocking.
3435+
*
3436+
* Returns the module object with incremented ref count.
3437+
*
3438+
* Removed in 3.15, but kept for stable ABI compatibility.
3439+
*/
3440+
PyAPI_FUNC(PyObject *)
3441+
PyImport_ImportModuleNoBlock(const char *name)
3442+
{
3443+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3444+
"PyImport_ImportModuleNoBlock() is deprecated and scheduled for "
3445+
"removal in Python 3.15. Use PyImport_ImportModule() instead.", 1))
3446+
{
3447+
return NULL;
3448+
}
3449+
return PyImport_ImportModule(name);
3450+
}
3451+
3452+
34293453
/* Remove importlib frames from the traceback,
34303454
* except in Verbose mode. */
34313455
static void

0 commit comments

Comments
 (0)