]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Remove private pylifecycle.h functions (#106400)
authorVictor Stinner <vstinner@python.org>
Tue, 4 Jul 2023 09:41:43 +0000 (11:41 +0200)
committerGitHub <noreply@github.com>
Tue, 4 Jul 2023 09:41:43 +0000 (09:41 +0000)
Remove private pylifecycle.h functions: move them to the internal C
API ( pycore_atexit.h, pycore_pylifecycle.h and pycore_signal.h). No
longer export most of these functions.

Move _testcapi.test_atexit() to _testinternalcapi.

19 files changed:
Include/cpython/pylifecycle.h
Include/internal/pycore_atexit.h
Include/internal/pycore_pylifecycle.h
Include/internal/pycore_signal.h
Modules/_asynciomodule.c
Modules/_io/bufferedio.c
Modules/_posixsubprocess.c
Modules/_randommodule.c
Modules/_sqlite/connection.c
Modules/_testcapimodule.c
Modules/_testinternalcapi.c
Modules/_xxinterpchannelsmodule.c
Modules/getbuildinfo.c
Modules/posixmodule.c
Modules/readline.c
Modules/signalmodule.c
Python/_warnings.c
Python/bootstrap_hash.c
Python/preconfig.c

index 1ca9ee91a72b1554c901102ad33c35b77d1ce1dc..8af34b056425120146f07f4c959c426b9b2655a0 100644 (file)
@@ -19,13 +19,13 @@ PyAPI_FUNC(PyStatus) Py_PreInitializeFromArgs(
     Py_ssize_t argc,
     wchar_t **argv);
 
-PyAPI_FUNC(int) _Py_IsCoreInitialized(void);
-
 
 /* Initialization and finalization */
 
 PyAPI_FUNC(PyStatus) Py_InitializeFromConfig(
     const PyConfig *config);
+
+// Python 3.8 provisional API (PEP 587)
 PyAPI_FUNC(PyStatus) _Py_InitializeMain(void);
 
 PyAPI_FUNC(int) Py_RunMain(void);
@@ -33,31 +33,8 @@ PyAPI_FUNC(int) Py_RunMain(void);
 
 PyAPI_FUNC(void) _Py_NO_RETURN Py_ExitStatusException(PyStatus err);
 
-/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
-PyAPI_FUNC(void) _Py_RestoreSignals(void);
-
 PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
-PyAPI_FUNC(int) _Py_FdIsInteractive(FILE *fp, PyObject *filename);
-
-PyAPI_FUNC(const char *) _Py_gitidentifier(void);
-PyAPI_FUNC(const char *) _Py_gitversion(void);
-
-PyAPI_FUNC(int) _Py_IsFinalizing(void);
-PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp);
-
-/* Random */
-PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
-PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
-
-/* Legacy locale support */
-PyAPI_FUNC(int) _Py_CoerceLegacyLocale(int warn);
-PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn);
-PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
 
 PyAPI_FUNC(PyStatus) Py_NewInterpreterFromConfig(
     PyThreadState **tstate_p,
     const PyInterpreterConfig *config);
-
-typedef void (*atexit_datacallbackfunc)(void *);
-PyAPI_FUNC(int) _Py_AtExit(
-        PyInterpreterState *, atexit_datacallbackfunc, void *);
index 63a2cd5d507d2c78b2d684840dcaebfb7d8a1a36..fc5cb6d8826435a62575d080f369f36689eea83b 100644 (file)
@@ -25,7 +25,8 @@ struct _atexit_runtime_state {
 //###################
 // interpreter atexit
 
-struct atexit_callback;
+typedef void (*atexit_datacallbackfunc)(void *);
+
 typedef struct atexit_callback {
     atexit_datacallbackfunc func;
     void *data;
@@ -50,6 +51,10 @@ struct atexit_state {
     int callback_len;
 };
 
+PyAPI_FUNC(int) _Py_AtExit(
+    PyInterpreterState *interp,
+    atexit_datacallbackfunc func,
+    void *data);
 
 #ifdef __cplusplus
 }
index b07c2dba8de847c29a48faa11c4cc3fa0128113c..fb28652515909d3cea496e19fa07707a2f201294 100644 (file)
@@ -23,7 +23,7 @@ extern PyStatus _PyUnicode_InitEncodings(PyThreadState *tstate);
 extern int _PyUnicode_EnableLegacyWindowsFSEncoding(void);
 #endif
 
-PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
+extern int _Py_IsLocaleCoercionTarget(const char *ctype_loc);
 
 /* Various one-time initializers */
 
@@ -67,30 +67,49 @@ extern PyStatus _PyGILState_Init(PyInterpreterState *interp);
 extern PyStatus _PyGILState_SetTstate(PyThreadState *tstate);
 extern void _PyGILState_Fini(PyInterpreterState *interp);
 
-PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyInterpreterState *interp);
+extern void _PyGC_DumpShutdownStats(PyInterpreterState *interp);
 
-PyAPI_FUNC(PyStatus) _Py_PreInitializeFromPyArgv(
+extern PyStatus _Py_PreInitializeFromPyArgv(
     const PyPreConfig *src_config,
     const struct _PyArgv *args);
-PyAPI_FUNC(PyStatus) _Py_PreInitializeFromConfig(
+extern PyStatus _Py_PreInitializeFromConfig(
     const PyConfig *config,
     const struct _PyArgv *args);
 
-PyAPI_FUNC(wchar_t *) _Py_GetStdlibDir(void);
+extern wchar_t * _Py_GetStdlibDir(void);
 
-PyAPI_FUNC(int) _Py_HandleSystemExit(int *exitcode_p);
+extern int _Py_HandleSystemExit(int *exitcode_p);
 
-PyAPI_FUNC(PyObject*) _PyErr_WriteUnraisableDefaultHook(PyObject *unraisable);
+extern PyObject* _PyErr_WriteUnraisableDefaultHook(PyObject *unraisable);
 
-PyAPI_FUNC(void) _PyErr_Print(PyThreadState *tstate);
-PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception,
+extern void _PyErr_Print(PyThreadState *tstate);
+extern void _PyErr_Display(PyObject *file, PyObject *exception,
                                 PyObject *value, PyObject *tb);
-PyAPI_FUNC(void) _PyErr_DisplayException(PyObject *file, PyObject *exc);
+extern void _PyErr_DisplayException(PyObject *file, PyObject *exc);
 
-PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(PyThreadState *tstate);
+extern void _PyThreadState_DeleteCurrent(PyThreadState *tstate);
 
 extern void _PyAtExit_Call(PyInterpreterState *interp);
 
+extern int _Py_IsCoreInitialized(void);
+
+extern int _Py_FdIsInteractive(FILE *fp, PyObject *filename);
+
+extern const char* _Py_gitidentifier(void);
+extern const char* _Py_gitversion(void);
+
+extern int _Py_IsFinalizing(void);
+PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp);
+
+/* Random */
+extern int _PyOS_URandom(void *buffer, Py_ssize_t size);
+PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
+
+/* Legacy locale support */
+extern int _Py_CoerceLegacyLocale(int warn);
+extern int _Py_LegacyLocaleDetected(int warn);
+PyAPI_FUNC(char*) _Py_SetLocaleFromEnv(int category);
+
 #ifdef __cplusplus
 }
 #endif
index ca3f69d09fc0c138b15c72887872dd0b476694ad..1a454ba6f4e8fb4f6be2bb9d5d15ce02431e3313 100644 (file)
@@ -11,10 +11,12 @@ extern "C" {
 #endif
 
 #include "pycore_atomic.h"         // _Py_atomic_address
-
 #include <signal.h>                // NSIG
 
 
+/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
+PyAPI_FUNC(void) _Py_RestoreSignals(void);
+
 #ifdef _SIG_MAXSIG
    // gh-91145: On FreeBSD, <signal.h> defines NSIG as 32: it doesn't include
    // realtime signals: [SIGRTMIN,SIGRTMAX]. Use _SIG_MAXSIG instead. For
index 05f94ef9ed281608c03248124733b228492a26c8..3843f9c45d7236cb66b2ac261e2192927efee912 100644 (file)
@@ -3,10 +3,11 @@
 #endif
 
 #include "Python.h"
+#include "pycore_moduleobject.h"  // _PyModule_GetState()
 #include "pycore_pyerrors.h"      // _PyErr_ClearExcState()
+#include "pycore_pylifecycle.h"   // _Py_IsInterpreterFinalizing()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_runtime_init.h"  // _Py_ID()
-#include "pycore_moduleobject.h"  // _PyModule_GetState()
 #include "structmember.h"         // PyMemberDef
 #include <stddef.h>               // offsetof()
 
index 4d120d4e8af3a7d7ef1b574485f4f416d7622305..e58e87926f6731fffc7b462c176082ba4a391226 100644 (file)
@@ -11,6 +11,7 @@
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_object.h"
 #include "pycore_pyerrors.h"      // _Py_FatalErrorFormat()
+#include "pycore_pylifecycle.h"   // _Py_IsInterpreterFinalizing()
 #include "structmember.h"         // PyMemberDef
 #include "_iomodule.h"
 
index 6caa4b8852911e3cce761b1f1e3cbdbddf75790a..ac2b0d4f55468c42d5c0b3135fffde18936ac7d9 100644 (file)
@@ -6,6 +6,7 @@
 #include "Python.h"
 #include "pycore_fileutils.h"
 #include "pycore_pystate.h"
+#include "pycore_signal.h"        // _Py_RestoreSignals()
 #if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
 # define _GNU_SOURCE
 #endif
@@ -739,8 +740,9 @@ child_exec(char *const exec_array[],
     if (child_umask >= 0)
         umask(child_umask);  /* umask() always succeeds. */
 
-    if (restore_signals)
+    if (restore_signals) {
         _Py_RestoreSignals();
+    }
 
 #ifdef VFORK_USABLE
     if (child_sigmask) {
index fda5ef267fb470b9cd4bae5adb9584106386abde..7daa1f9327966fa3b9448baa0ad8908c3785aaed 100644 (file)
@@ -72,6 +72,7 @@
 
 #include "Python.h"
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
+#include "pycore_pylifecycle.h"   // _PyOS_URandomNonblock()
 #include "pycore_runtime.h"
 #ifdef HAVE_PROCESS_H
 #  include <process.h>            // getpid()
index d71cef14779e5109df1460f352b8e3f0ab163181..bab743674b666da411b0b02964639f67aff8e791 100644 (file)
@@ -34,6 +34,7 @@
 #include "prepare_protocol.h"
 #include "util.h"
 #include "pycore_import.h"        // _PyImport_GetModuleAttrString()
+#include "pycore_pylifecycle.h"   // _Py_IsInterpreterFinalizing()
 #include "pycore_weakref.h"       // _PyWeakref_IS_DEAD()
 
 #include <stdbool.h>
index d1044b5445202dbdb38579ab7d4a2e42a37bcc77..2baf453f71026746ec7455e7066bde2b2e9a0d23 100644 (file)
@@ -3293,37 +3293,6 @@ function_set_kw_defaults(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
-struct atexit_data {
-    int called;
-};
-
-static void
-callback(void *data)
-{
-    ((struct atexit_data *)data)->called += 1;
-}
-
-static PyObject *
-test_atexit(PyObject *self, PyObject *Py_UNUSED(args))
-{
-    PyThreadState *oldts = PyThreadState_Swap(NULL);
-    PyThreadState *tstate = Py_NewInterpreter();
-
-    struct atexit_data data = {0};
-    int res = _Py_AtExit(tstate->interp, callback, (void *)&data);
-    Py_EndInterpreter(tstate);
-    PyThreadState_Swap(oldts);
-    if (res < 0) {
-        return NULL;
-    }
-    if (data.called == 0) {
-        PyErr_SetString(PyExc_RuntimeError, "atexit callback not called");
-        return NULL;
-    }
-    Py_RETURN_NONE;
-}
-
-
 static PyObject *
 check_pyimport_addmodule(PyObject *self, PyObject *args)
 {
@@ -3613,7 +3582,6 @@ static PyMethodDef TestMethods[] = {
     {"function_set_defaults", function_set_defaults, METH_VARARGS, NULL},
     {"function_get_kw_defaults", function_get_kw_defaults, METH_O, NULL},
     {"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
-    {"test_atexit", test_atexit, METH_NOARGS},
     {"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS},
     {"test_weakref_capi", test_weakref_capi, METH_NOARGS},
     {NULL, NULL} /* sentinel */
index 14f91e8da1716adb1277c41666d0057d22896a2a..84511d27e37f459cf4a35ecd4534682aa9ed2ee7 100644 (file)
@@ -1264,6 +1264,38 @@ unicode_transformdecimalandspacetoascii(PyObject *self, PyObject *arg)
 }
 
 
+struct atexit_data {
+    int called;
+};
+
+static void
+callback(void *data)
+{
+    ((struct atexit_data *)data)->called += 1;
+}
+
+static PyObject *
+test_atexit(PyObject *self, PyObject *Py_UNUSED(args))
+{
+    PyThreadState *oldts = PyThreadState_Swap(NULL);
+    PyThreadState *tstate = Py_NewInterpreter();
+
+    struct atexit_data data = {0};
+    int res = _Py_AtExit(tstate->interp, callback, (void *)&data);
+    Py_EndInterpreter(tstate);
+    PyThreadState_Swap(oldts);
+    if (res < 0) {
+        return NULL;
+    }
+
+    if (data.called == 0) {
+        PyErr_SetString(PyExc_RuntimeError, "atexit callback not called");
+        return NULL;
+    }
+    Py_RETURN_NONE;
+}
+
+
 static PyMethodDef module_functions[] = {
     {"get_configs", get_configs, METH_NOARGS},
     {"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -1316,6 +1348,7 @@ static PyMethodDef module_functions[] = {
     {"_PyTraceMalloc_GetTraceback", tracemalloc_get_traceback, METH_VARARGS},
     {"test_tstate_capi", test_tstate_capi, METH_NOARGS, NULL},
     {"_PyUnicode_TransformDecimalAndSpaceToASCII", unicode_transformdecimalandspacetoascii, METH_O},
+    {"test_atexit", test_atexit, METH_NOARGS},
     {NULL, NULL} /* sentinel */
 };
 
index 1d7e7f1d71af3eda55736655da3267b3e9207553..82472555ec7d621d5f785e16058d5ae8d8c9ddc2 100644 (file)
@@ -1,9 +1,13 @@
-
 /* interpreters module */
 /* low-level access to interpreter primitives */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "interpreteridobject.h"
+#include "pycore_atexit.h"        // _Py_AtExit()
 
 
 /*
index a24750b76c09bc291223e6fc9151630de4f899e2..8d553d106c6ab5bd108e2d1a4f67d305b4a8c39f 100644 (file)
@@ -1,4 +1,9 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
+#include "pycore_pylifecycle.h"   // _Py_gitidentifier()
 
 #ifndef DONT_HAVE_STDIO_H
 #include <stdio.h>
index b9f42476e6b82c82ba0d4834483cb1f885736f90..aef802c232c6ce921c8af4209205b84de8701cde 100644 (file)
@@ -19,6 +19,7 @@
 #include "pycore_initconfig.h"    // _PyStatus_EXCEPTION()
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
 #include "pycore_object.h"        // _PyObject_LookupSpecial()
+#include "pycore_pylifecycle.h"   // _PyOS_URandom()
 #include "pycore_pystate.h"       // _PyInterpreterState_GET()
 #include "pycore_signal.h"        // Py_NSIG
 
index ff7075c6822e27909f5df9f426024172e155160e..a592919692cb8363217e9039ccdcc62f7430e011 100644 (file)
@@ -4,8 +4,13 @@
  * recently, it was largely rewritten by Guido van Rossum.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 /* Standard definitions */
 #include "Python.h"
+#include "pycore_pylifecycle.h"   // _Py_SetLocaleFromEnv()
 
 #include <errno.h>
 #include <signal.h>
index 00ea4343735dabf63c3131a2d5dc9546dae9ab29..3adb2e8dfe58d8d6d73723e29dc65f51649bb53b 100644 (file)
@@ -13,7 +13,7 @@
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
 #include "pycore_pyerrors.h"      // _PyErr_SetString()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
-#include "pycore_signal.h"        // Py_NSIG
+#include "pycore_signal.h"        // _Py_RestoreSignals()
 
 #ifndef MS_WINDOWS
 #  include "posixmodule.h"
index e4941f7b068d3f54ae334955b16cb5deb15dc0d2..e0580f01d9361dec23c746319177252eed783dae 100644 (file)
@@ -1,10 +1,11 @@
 #include "Python.h"
+#include "pycore_frame.h"
 #include "pycore_initconfig.h"
 #include "pycore_interp.h"        // PyInterpreterState.warnings
 #include "pycore_long.h"          // _PyLong_GetZero()
 #include "pycore_pyerrors.h"
+#include "pycore_pylifecycle.h"   // _Py_IsInterpreterFinalizing()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
-#include "pycore_frame.h"
 #include "clinic/_warnings.c.h"
 
 #define MODULE_NAME "_warnings"
index 587063ef1ab29aa4a3f667877ab32c056edfd287..ef693e5df1fcc415ed85c6a229f8934a51a6f6af 100644 (file)
@@ -1,6 +1,7 @@
 #include "Python.h"
-#include "pycore_initconfig.h"
 #include "pycore_fileutils.h"     // _Py_fstat_noraise()
+#include "pycore_initconfig.h"
+#include "pycore_pylifecycle.h"   // _PyOS_URandomNonblock()
 #include "pycore_runtime.h"       // _PyRuntime
 
 #ifdef MS_WINDOWS
index 77a86d651eb0f4cc67e5c39c9057dcdef7909d57..5b26c75de8b3a00d255d180525cff1ba10368b7a 100644 (file)
@@ -2,6 +2,7 @@
 #include "pycore_fileutils.h"     // DECODE_LOCALE_ERR
 #include "pycore_getopt.h"        // _PyOS_GetOpt()
 #include "pycore_initconfig.h"    // _PyArgv
+#include "pycore_pylifecycle.h"   // _Py_LegacyLocaleDetected()
 #include "pycore_pymem.h"         // _PyMem_GetAllocatorName()
 #include "pycore_runtime.h"       // _PyRuntime_Initialize()