Skip to content

Commit 9ce4b6a

Browse files
vstinnerDinoV
authored andcommitted
bpo-36710: Remove PyImport_Cleanup() function (pythonGH-14221)
* Rename PyImport_Cleanup() to _PyImport_Cleanup() and move it to the internal C API. Add 'tstate' parameters. * Remove documentation of _PyImport_Init(), PyImport_Cleanup(), _PyImport_Fini(). All three were documented as "For internal use only.".
1 parent 2a2e19c commit 9ce4b6a

File tree

6 files changed

+7
-20
lines changed

6 files changed

+7
-20
lines changed

Doc/c-api/import.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,6 @@ Importing Modules
223223
Return a new reference to the finder object.
224224
225225
226-
.. c:function:: void _PyImport_Init()
227-
228-
Initialize the import mechanism. For internal use only.
229-
230-
231-
.. c:function:: void PyImport_Cleanup()
232-
233-
Empty the module table. For internal use only.
234-
235-
236-
.. c:function:: void _PyImport_Fini()
237-
238-
Finalize the import mechanism. For internal use only.
239-
240-
241226
.. c:function:: int PyImport_ImportFrozenModuleObject(PyObject *name)
242227
243228
Load a frozen module named *name*. Return ``1`` for success, ``0`` if the

Doc/whatsnew/3.9.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ Deprecated
122122
Removed
123123
=======
124124

125+
* The C function ``PyImport_Cleanup()`` has been removed. It was documented as:
126+
"Empty the module table. For internal use only."
127+
125128
* ``_dummy_thread`` and ``dummy_threading`` modules have been removed. These
126129
modules were deprecated since Python 3.7 which requires threading support.
127130
(Contributed by Victor Stinner in :issue:`37312`.)

Include/import.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevelObject(
7272
PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path);
7373
PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);
7474
PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);
75-
PyAPI_FUNC(void) PyImport_Cleanup(void);
7675
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
7776
PyAPI_FUNC(int) PyImport_ImportFrozenModuleObject(
7877
PyObject *name

Include/internal/pycore_import.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PyAPI_FUNC(PyObject *) _PyImport_FindBuiltin(
1111
);
1212

1313
extern void _PyImport_ReInitLock(void);
14+
extern void _PyImport_Cleanup(PyThreadState *tstate);
1415

1516
#ifdef __cplusplus
1617
}

Python/import.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,8 @@ static const char * const sys_files[] = {
413413
/* Un-initialize things, as good as we can */
414414

415415
void
416-
PyImport_Cleanup(void)
416+
_PyImport_Cleanup(PyThreadState *tstate)
417417
{
418-
PyThreadState *tstate = _PyThreadState_GET();
419418
PyInterpreterState *interp = tstate->interp;
420419
PyObject *modules = interp->modules;
421420
if (modules == NULL) {

Python/pylifecycle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ Py_FinalizeEx(void)
12251225
_PySys_ClearAuditHooks();
12261226

12271227
/* Destroy all modules */
1228-
PyImport_Cleanup();
1228+
_PyImport_Cleanup(tstate);
12291229

12301230
/* Print debug stats if any */
12311231
_PyEval_Fini();
@@ -1589,7 +1589,7 @@ Py_EndInterpreter(PyThreadState *tstate)
15891589
if (tstate != interp->tstate_head || tstate->next != NULL)
15901590
Py_FatalError("Py_EndInterpreter: not the last thread");
15911591

1592-
PyImport_Cleanup();
1592+
_PyImport_Cleanup(tstate);
15931593
PyInterpreterState_Clear(interp);
15941594
PyThreadState_Swap(NULL);
15951595
PyInterpreterState_Delete(interp);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy