]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Remove private _PyImport C API functions (#106383)
authorVictor Stinner <vstinner@python.org>
Mon, 3 Jul 2023 23:02:07 +0000 (01:02 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Jul 2023 23:02:07 +0000 (23:02 +0000)
* Remove private _PyImport C API functions: move them to the internal
  C API (pycore_import.h).
* No longer export most of these private functions.
* _testcapi avoids private _PyImport_GetModuleAttrString().

Include/cpython/import.h
Include/internal/pycore_import.h
Modules/_elementtree.c
Modules/_sqlite/connection.c
Modules/_sqlite/module.c
Modules/_testcapimodule.c
Modules/cjkcodecs/cjkcodecs.h
Modules/pyexpat.c

index 2bca4ade4c4f2cf76fd859c8db282a20a469958e..cdfdd15bfa48d22ac844868919ae8a8b445b679d 100644 (file)
@@ -4,23 +4,6 @@
 
 PyMODINIT_FUNC PyInit__imp(void);
 
-PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *);
-
-PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
-PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
-PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
-
-PyAPI_FUNC(void) _PyImport_AcquireLock(PyInterpreterState *interp);
-PyAPI_FUNC(int) _PyImport_ReleaseLock(PyInterpreterState *interp);
-
-PyAPI_FUNC(int) _PyImport_FixupBuiltin(
-    PyObject *mod,
-    const char *name,            /* UTF-8 encoded string */
-    PyObject *modules
-    );
-PyAPI_FUNC(int) _PyImport_FixupExtensionObject(PyObject*, PyObject *,
-                                               PyObject *, PyObject *);
-
 struct _inittab {
     const char *name;           /* ASCII encoded string */
     PyObject* (*initfunc)(void);
@@ -41,6 +24,3 @@ struct _frozen {
    collection of frozen modules: */
 
 PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules;
-
-PyAPI_DATA(PyObject *) _PyImport_GetModuleAttr(PyObject *, PyObject *);
-PyAPI_DATA(PyObject *) _PyImport_GetModuleAttrString(const char *, const char *);
index ee93f7d99d91554146e4bae479782df6170b5803..457a654aff46448934d3faa4720da821a3a6935f 100644 (file)
@@ -7,6 +7,26 @@ extern "C" {
 
 #include "pycore_time.h"          // _PyTime_t
 
+extern int _PyImport_IsInitialized(PyInterpreterState *);
+
+PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
+PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
+PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
+
+extern void _PyImport_AcquireLock(PyInterpreterState *interp);
+extern int _PyImport_ReleaseLock(PyInterpreterState *interp);
+
+extern int _PyImport_FixupBuiltin(
+    PyObject *mod,
+    const char *name,            /* UTF-8 encoded string */
+    PyObject *modules
+    );
+extern int _PyImport_FixupExtensionObject(PyObject*, PyObject *,
+                                          PyObject *, PyObject *);
+
+PyAPI_DATA(PyObject *) _PyImport_GetModuleAttr(PyObject *, PyObject *);
+PyAPI_DATA(PyObject *) _PyImport_GetModuleAttrString(const char *, const char *);
+
 
 struct _import_runtime_state {
     /* The builtin modules (defined in config.c). */
index 48280690a707a42d67700c3260022d9fbe611f5a..3e742e067e7db1d054eb627cac825d7682006076 100644 (file)
  *--------------------------------------------------------------------
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
+#include "pycore_import.h"        // _PyImport_GetModuleAttrString()
 #include "structmember.h"         // PyMemberDef
 #include "expat.h"
 #include "pyexpat.h"
index 967ba2812080e5645ec60c9400c51b53eba701b8..d71cef14779e5109df1460f352b8e3f0ab163181 100644 (file)
@@ -33,6 +33,7 @@
 #include "blob.h"
 #include "prepare_protocol.h"
 #include "util.h"
+#include "pycore_import.h"        // _PyImport_GetModuleAttrString()
 #include "pycore_weakref.h"       // _PyWeakref_IS_DEAD()
 
 #include <stdbool.h>
index ea4d8c58b7ee0ebf7ec4c691d6bfeeffe6bde147..368e581b4f3355bd4469625a0cb3fa4634408f8a 100644 (file)
  * 3. This notice may not be removed or altered from any source distribution.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "connection.h"
 #include "statement.h"
 #include "cursor.h"
@@ -29,6 +33,8 @@
 #include "row.h"
 #include "blob.h"
 
+#include "pycore_import.h"        // _PyImport_GetModuleAttrString()
+
 #if SQLITE_VERSION_NUMBER < 3015002
 #error "SQLite 3.15.2 or higher required"
 #endif
index ce1131743eb2a4b3a66b9887f1cffbe552d870af..d1044b5445202dbdb38579ab7d4a2e42a37bcc77 100644 (file)
@@ -1267,9 +1267,15 @@ test_pep3118_obsolete_write_locks(PyObject* self, PyObject *Py_UNUSED(ignored))
     if (ret != -1 || match == 0)
         goto error;
 
+    PyObject *mod_io = PyImport_ImportModule("_io");
+    if (mod_io == NULL) {
+        return NULL;
+    }
+
     /* bytesiobuf_getbuffer() */
-    PyTypeObject *type = (PyTypeObject *)_PyImport_GetModuleAttrString(
-            "_io", "_BytesIOBuffer");
+    PyTypeObject *type = (PyTypeObject *)PyObject_GetAttrString(
+            mod_io, "_BytesIOBuffer");
+    Py_DECREF(mod_io);
     if (type == NULL) {
         return NULL;
     }
index 97290aac3ba4390d9e1af8ae57b0280397f9e60e..ee588785e7403f44e8075d620f8aec373c77dccd 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "Python.h"
 #include "multibytecodec.h"
+#include "pycore_import.h"        // _PyImport_GetModuleAttrString()
 
 
 /* a unicode "undefined" code point */
index e3333fff00b2b2fea51def2a938a3fa2d29f85f1..28915359fb49e291af1e0810e68823b0a02484ec 100644 (file)
@@ -1,4 +1,9 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
+#include "pycore_import.h"        // _PyImport_SetModule()
 #include <ctype.h>
 
 #include "structmember.h"         // PyMemberDef