bpo-36710: Remove PyImport_Cleanup() function (GH-14221)
authorVictor Stinner <vstinner@redhat.com>
Wed, 19 Jun 2019 08:36:10 +0000 (10:36 +0200)
committerGitHub <noreply@github.com>
Wed, 19 Jun 2019 08:36:10 +0000 (10:36 +0200)
* 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.".

Doc/c-api/import.rst
Doc/whatsnew/3.9.rst
Include/import.h
Include/internal/pycore_import.h
Python/import.c
Python/pylifecycle.c

index 86cc4031610b7dbfb39951a1bf245879e1ee827a..3bc50609714a5bfb3c32924529fc628ea06a0951 100644 (file)
@@ -223,21 +223,6 @@ Importing Modules
    Return a new reference to the finder object.
 
 
-.. c:function:: void _PyImport_Init()
-
-   Initialize the import mechanism.  For internal use only.
-
-
-.. c:function:: void PyImport_Cleanup()
-
-   Empty the module table.  For internal use only.
-
-
-.. c:function:: void _PyImport_Fini()
-
-   Finalize the import mechanism.  For internal use only.
-
-
 .. c:function:: int PyImport_ImportFrozenModuleObject(PyObject *name)
 
    Load a frozen module named *name*.  Return ``1`` for success, ``0`` if the
index 446c8b9719e0fabb45e4f3284230086a8d3c835a..24fbe1870c87e22fece1be3e82ad20f91063997a 100644 (file)
@@ -122,6 +122,9 @@ Deprecated
 Removed
 =======
 
+* The C function ``PyImport_Cleanup()`` has been removed. It was documented as:
+  "Empty the module table.  For internal use only."
+
 * ``_dummy_thread`` and ``dummy_threading`` modules have been removed. These
   modules were deprecated since Python 3.7 which requires threading support.
   (Contributed by Victor Stinner in :issue:`37312`.)
index c50767d904de1b89161e7929574aede48d1529cd..735533ee7a79ac17655148a2b441f73376fbfaaa 100644 (file)
@@ -72,7 +72,6 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevelObject(
 PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path);
 PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);
 PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);
-PyAPI_FUNC(void) PyImport_Cleanup(void);
 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
 PyAPI_FUNC(int) PyImport_ImportFrozenModuleObject(
     PyObject *name
index bbcd170ab1358d5d86c2d5229ce06017ce7dc1fc..5d3203e5b97fdf1e5967ffdcf7202d620b177277 100644 (file)
@@ -11,6 +11,7 @@ PyAPI_FUNC(PyObject *) _PyImport_FindBuiltin(
     );
 
 extern void _PyImport_ReInitLock(void);
+extern void _PyImport_Cleanup(PyThreadState *tstate);
 
 #ifdef __cplusplus
 }
index 5606d3bea456998025d23f46154df540176c8741..dc0d5b8b901ca028a04833a01ca25c1f6755b203 100644 (file)
@@ -413,9 +413,8 @@ static const char * const sys_files[] = {
 /* Un-initialize things, as good as we can */
 
 void
-PyImport_Cleanup(void)
+_PyImport_Cleanup(PyThreadState *tstate)
 {
-    PyThreadState *tstate = _PyThreadState_GET();
     PyInterpreterState *interp = tstate->interp;
     PyObject *modules = interp->modules;
     if (modules == NULL) {
index 4a97295102f793452ac91013c7a51a20d2004229..c0b34507899f939dc06705ff0419195c29add9d7 100644 (file)
@@ -1225,7 +1225,7 @@ Py_FinalizeEx(void)
     _PySys_ClearAuditHooks();
 
     /* Destroy all modules */
-    PyImport_Cleanup();
+    _PyImport_Cleanup(tstate);
 
     /* Print debug stats if any */
     _PyEval_Fini();
@@ -1589,7 +1589,7 @@ Py_EndInterpreter(PyThreadState *tstate)
     if (tstate != interp->tstate_head || tstate->next != NULL)
         Py_FatalError("Py_EndInterpreter: not the last thread");
 
-    PyImport_Cleanup();
+    _PyImport_Cleanup(tstate);
     PyInterpreterState_Clear(interp);
     PyThreadState_Swap(NULL);
     PyInterpreterState_Delete(interp);