]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-101524: Only Use Public C-API in the _xxsubinterpreters Module (gh-105258...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 27 Jul 2023 19:15:47 +0000 (12:15 -0700)
committerGitHub <noreply@github.com>
Thu, 27 Jul 2023 19:15:47 +0000 (13:15 -0600)
The _xxsubinterpreters module was meant to only use public API.  Some internal C-API usage snuck in over the last few years (e.g. gh-28969).  This fixes that.
(cherry picked from commit e6373c0d8b59512aa7f0dea7f3fb162b6ed10fa4)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
12 files changed:
Include/cpython/interpreteridobject.h [moved from Include/internal/pycore_interpreteridobject.h with 51% similarity]
Include/internal/pycore_pymem.h
Include/interpreteridobject.h [new file with mode: 0644]
Makefile.pre.in
Modules/_testinternalcapi.c
Modules/_xxinterpchannelsmodule.c
Modules/_xxsubinterpretersmodule.c
Objects/interpreteridobject.c
Objects/object.c
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters
Tools/c-analyzer/cpython/_parser.py

similarity index 51%
rename from Include/internal/pycore_interpreteridobject.h
rename to Include/cpython/interpreteridobject.h
index 804831e76deaeac213e122f6373bc1812d5af8ff..5076584209b90b4f8309913b9ade0fd121f8d526 100644 (file)
@@ -1,22 +1,11 @@
-/* Interpreter ID Object */
-
-#ifndef Py_INTERNAL_INTERPRETERIDOBJECT_H
-#define Py_INTERNAL_INTERPRETERIDOBJECT_H
-#ifdef __cplusplus
-extern "C" {
+#ifndef Py_CPYTHON_INTERPRETERIDOBJECT_H
+#  error "this header file must not be included directly"
 #endif
 
-#ifndef Py_BUILD_CORE
-#  error "this header requires Py_BUILD_CORE define"
-#endif
+/* Interpreter ID Object */
 
 PyAPI_DATA(PyTypeObject) _PyInterpreterID_Type;
 
 PyAPI_FUNC(PyObject *) _PyInterpreterID_New(int64_t);
 PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
 PyAPI_FUNC(PyInterpreterState *) _PyInterpreterID_LookUp(PyObject *);
-
-#ifdef __cplusplus
-}
-#endif
-#endif  // !Py_INTERNAL_INTERPRETERIDOBJECT_H
index c2f03254bb87609ba2617094c6f023079794bf4d..81a707a0a5ddf3e92c27e37c84860ae48a7beacf 100644 (file)
@@ -95,4 +95,4 @@ PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator);
 #ifdef __cplusplus
 }
 #endif
-#endif  // !Py_INTERNAL_PYMEM_H
+#endif /* !Py_INTERNAL_PYMEM_H */
diff --git a/Include/interpreteridobject.h b/Include/interpreteridobject.h
new file mode 100644 (file)
index 0000000..8432632
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef Py_INTERPRETERIDOBJECT_H
+#define Py_INTERPRETERIDOBJECT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_LIMITED_API
+#  define Py_CPYTHON_INTERPRETERIDOBJECT_H
+#  include "cpython/interpreteridobject.h"
+#  undef Py_CPYTHON_INTERPRETERIDOBJECT_H
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERPRETERIDOBJECT_H */
index 393eec7b8d324c52e956ec7ad7247d99fe243416..a74f4fd66d323516c5fa85527de1819d5ad0e7b2 100644 (file)
@@ -1616,6 +1616,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/floatobject.h \
                $(srcdir)/Include/frameobject.h \
                $(srcdir)/Include/import.h \
+               $(srcdir)/Include/interpreteridobject.h \
                $(srcdir)/Include/intrcheck.h \
                $(srcdir)/Include/iterobject.h \
                $(srcdir)/Include/listobject.h \
@@ -1686,6 +1687,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/cpython/genobject.h \
                $(srcdir)/Include/cpython/import.h \
                $(srcdir)/Include/cpython/initconfig.h \
+               $(srcdir)/Include/cpython/interpreteridobject.h \
                $(srcdir)/Include/cpython/listobject.h \
                $(srcdir)/Include/cpython/longintrepr.h \
                $(srcdir)/Include/cpython/longobject.h \
@@ -1754,7 +1756,6 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/internal/pycore_import.h \
                $(srcdir)/Include/internal/pycore_initconfig.h \
                $(srcdir)/Include/internal/pycore_interp.h \
-               $(srcdir)/Include/internal/pycore_interpreteridobject.h \
                $(srcdir)/Include/internal/pycore_intrinsics.h \
                $(srcdir)/Include/internal/pycore_list.h \
                $(srcdir)/Include/internal/pycore_long.h \
index 6fc31f61c144d8ff533170d1fd1e8b31cb8dc1d8..4e063a8615293136770fdb35f562fb0cbba8e09a 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "Python.h"
 #include "frameobject.h"
+#include "interpreteridobject.h" // _PyInterpreterID_LookUp()
 #include "pycore_atomic_funcs.h" // _Py_atomic_int_get()
 #include "pycore_bitutils.h"     // _Py_bswap32()
 #include "pycore_bytesobject.h"  // _PyBytes_Find()
@@ -24,7 +25,6 @@
 #include "pycore_hashtable.h"    // _Py_hashtable_new()
 #include "pycore_initconfig.h"   // _Py_GetConfigsAsDict()
 #include "pycore_interp.h"       // _PyInterpreterState_GetConfigCopy()
-#include "pycore_interpreteridobject.h"  // _PyInterpreterID_LookUp()
 #include "pycore_pathconfig.h"   // _PyPathConfig_ClearGlobal()
 #include "pycore_pyerrors.h"     // _Py_UTF8_Edit_Cost()
 #include "pycore_pystate.h"      // _PyThreadState_GET()
index 616dd57768811631055934c8993f529d50b9916c..1d7e7f1d71af3eda55736655da3267b3e9207553 100644 (file)
@@ -1,13 +1,9 @@
 
 /* interpreters module */
 /* low-level access to interpreter primitives */
-#ifndef Py_BUILD_CORE_BUILTIN
-#  define Py_BUILD_CORE_MODULE 1
-#endif
 
 #include "Python.h"
-#include "pycore_pystate.h"       // _PyThreadState_GET()
-#include "pycore_interpreteridobject.h"
+#include "interpreteridobject.h"
 
 
 /*
index d7daae254638ecd958143fe1a9985564371dc407..4801f37d6f6c5fa6ffa8327fca61c84dd3000701 100644 (file)
@@ -1,15 +1,9 @@
 
 /* interpreters module */
 /* low-level access to interpreter primitives */
-#ifndef Py_BUILD_CORE_BUILTIN
-#  define Py_BUILD_CORE_MODULE 1
-#endif
 
 #include "Python.h"
-// XXX This module should not rely on internal API.
-#include "pycore_frame.h"
-#include "pycore_pystate.h"       // _PyThreadState_GET()
-#include "pycore_interpreteridobject.h"
+#include "interpreteridobject.h"
 
 
 #define MODULE_NAME "_xxsubinterpreters"
@@ -376,7 +370,7 @@ _is_running(PyInterpreterState *interp)
     }
 
     assert(!PyErr_Occurred());
-    _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+    struct _PyInterpreterFrame *frame = tstate->cframe->current_frame;
     if (frame == NULL) {
         return 0;
     }
@@ -512,7 +506,7 @@ interp_create(PyObject *self, PyObject *args, PyObject *kwds)
     }
 
     // Create and initialize the new interpreter.
-    PyThreadState *save_tstate = _PyThreadState_GET();
+    PyThreadState *save_tstate = PyThreadState_Get();
     assert(save_tstate != NULL);
     const PyInterpreterConfig config = isolated
         ? (PyInterpreterConfig)_PyInterpreterConfig_INIT
index 7b3e31beded5947701c1f6e040d5a3a1eddc9329..46239100dcb7b77415ad4bcecd66c42729d5b4b4 100644 (file)
@@ -3,7 +3,7 @@
 #include "Python.h"
 #include "pycore_abstract.h"   // _PyIndex_Check()
 #include "pycore_interp.h"     // _PyInterpreterState_LookUpID()
-#include "pycore_interpreteridobject.h"
+#include "interpreteridobject.h"
 
 
 typedef struct interpid {
index 6a73c3588da798256cb5e77a64dca62e09e4a38b..bd0fa40bd2a8511c11b4fcc69f3c061d96476061 100644 (file)
@@ -17,7 +17,7 @@
 #include "pycore_typevarobject.h" // _PyTypeAlias_Type, _Py_initialize_generic
 #include "pycore_typeobject.h"    // _PyBufferWrapper_Type
 #include "pycore_unionobject.h"   // _PyUnion_Type
-#include "pycore_interpreteridobject.h"  // _PyInterpreterID_Type
+#include "interpreteridobject.h"  // _PyInterpreterID_Type
 
 #ifdef Py_LIMITED_API
    // Prevent recursive call _Py_IncRef() <=> Py_INCREF()
index 43716487f91bd5085cf6b888aff2ec30f5781c22..b265264dc161acf01e97ebe39e4cd66e4745fd1a 100644 (file)
     <ClInclude Include="..\Include\cpython\genobject.h" />
     <ClInclude Include="..\Include\cpython\import.h" />
     <ClInclude Include="..\Include\cpython\initconfig.h" />
+    <ClInclude Include="..\Include\cpython\interpreteridobject.h" />
     <ClInclude Include="..\Include\cpython\listobject.h" />
     <ClInclude Include="..\Include\cpython\longintrepr.h" />
     <ClInclude Include="..\Include\cpython\longobject.h" />
     <ClInclude Include="..\Include\internal\pycore_import.h" />
     <ClInclude Include="..\Include\internal\pycore_initconfig.h" />
     <ClInclude Include="..\Include\internal\pycore_interp.h" />
-    <ClInclude Include="..\Include\internal\pycore_interpreteridobject.h" />
     <ClInclude Include="..\Include\internal\pycore_intrinsics.h" />
     <ClInclude Include="..\Include\internal\pycore_list.h" />
     <ClInclude Include="..\Include\internal\pycore_long.h" />
     <ClInclude Include="..\Include\internal\pycore_unicodeobject.h" />
     <ClInclude Include="..\Include\internal\pycore_unicodeobject_generated.h" />
     <ClInclude Include="..\Include\internal\pycore_warnings.h" />
+    <ClInclude Include="..\Include\interpreteridobject.h" />
     <ClInclude Include="..\Include\intrcheck.h" />
     <ClInclude Include="..\Include\iterobject.h" />
     <ClInclude Include="..\Include\listobject.h" />
index 22eb70a0f2dde436054b072ab000ba28a0a13e26..67a32f653de1f87d32f4d40fc64e5965393fb1a1 100644 (file)
     <ClInclude Include="..\Include\pyhash.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\interpreteridobject.h">
+      <Filter>Include</Filter>
+    </ClInclude>
     <ClInclude Include="..\Modules\hashtable.h">
       <Filter>Modules</Filter>
     </ClInclude>
     <ClInclude Include="..\Include\cpython\genobject.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\cpython\interpreteridobject.h">
+      <Filter>Include\cpython</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\cpython\pythonrun.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_interp.h">
       <Filter>Include\internal</Filter>
     </ClInclude>
-    <ClInclude Include="..\Include\internal\pycore_interpreteridobject.h">
-      <Filter>Include\cpython</Filter>
-    </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_intrinsics.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>
index 2ee341f8dd137d8d1db03b355417442704babc69..1587a19716fe0ba166e1dd80f7721724789e8bf2 100644 (file)
@@ -227,6 +227,7 @@ Include/cpython/fileobject.h        Py_CPYTHON_FILEOBJECT_H 1
 Include/cpython/fileutils.h    Py_CPYTHON_FILEUTILS_H  1
 Include/cpython/frameobject.h  Py_CPYTHON_FRAMEOBJECT_H        1
 Include/cpython/import.h       Py_CPYTHON_IMPORT_H     1
+Include/cpython/interpreteridobject.h  Py_CPYTHON_INTERPRETERIDOBJECT_H        1
 Include/cpython/listobject.h   Py_CPYTHON_LISTOBJECT_H 1
 Include/cpython/methodobject.h Py_CPYTHON_METHODOBJECT_H       1
 Include/cpython/object.h       Py_CPYTHON_OBJECT_H     1