[Python-checkins] bpo-35081: And pycore_lifecycle.h and pycore_pathconfig.h (GH-10273)

Victor Stinner webhook-mailer at python.org
Wed Oct 31 22:16:02 EDT 2018


https://github.com/python/cpython/commit/a1c249c40517917d2e0971d55aea8d14a44b2cc8
commit: a1c249c40517917d2e0971d55aea8d14a44b2cc8
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-11-01T03:15:58+01:00
summary:

bpo-35081: And pycore_lifecycle.h and pycore_pathconfig.h (GH-10273)

* And pycore_lifecycle.h and pycore_pathconfig.h headers to
  Include/internal/
* Move Py_BUILD_CORE specific code from coreconfig.h and
  pylifecycle.h to pycore_pathconfig.h and pycore_lifecycle.h
* Move _Py_wstrlist_XXX() definitions and _PyPathConfig code
  from pycore_state.h to pycore_pathconfig.h
* Move "Init" and "Fini" function definitions from pylifecycle.c to
  pycore_lifecycle.h.

files:
A Include/internal/pycore_lifecycle.h
A Include/internal/pycore_pathconfig.h
M Include/coreconfig.h
M Include/internal/pycore_state.h
M Include/pylifecycle.h
M Makefile.pre.in
M Modules/_testcapimodule.c
M Modules/getpath.c
M Modules/main.c
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters
M Programs/python.c
M Python/coreconfig.c
M Python/import.c
M Python/pathconfig.c
M Python/pylifecycle.c
M Python/sysmodule.c

diff --git a/Include/coreconfig.h b/Include/coreconfig.h
index 83c4e7ee4dbe..ff7b684a1fa5 100644
--- a/Include/coreconfig.h
+++ b/Include/coreconfig.h
@@ -361,17 +361,6 @@ PyAPI_FUNC(int) _PyCoreConfig_GetEnvDup(
 #endif
 
 
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _Py_SetFileSystemEncoding(
-    const char *encoding,
-    const char *errors);
-PyAPI_FUNC(void) _Py_ClearFileSystemEncoding(void);
-#endif
-
-#ifndef Py_LIMITED_API
-PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(int len, wchar_t **list);
-#endif
-
 
 #ifdef __cplusplus
 }
diff --git a/Include/internal/pycore_lifecycle.h b/Include/internal/pycore_lifecycle.h
new file mode 100644
index 000000000000..cf36440eabcf
--- /dev/null
+++ b/Include/internal/pycore_lifecycle.h
@@ -0,0 +1,50 @@
+#ifndef Py_INTERNAL_LIFECYCLE_H
+#define Py_INTERNAL_LIFECYCLE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_BUILD_CORE
+#  error "Py_BUILD_CORE must be defined to include this header"
+#endif
+
+PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
+
+PyAPI_FUNC(int) _Py_SetFileSystemEncoding(
+    const char *encoding,
+    const char *errors);
+PyAPI_FUNC(void) _Py_ClearFileSystemEncoding(void);
+
+PyAPI_FUNC(void) _Py_ClearStandardStreamEncoding(void);
+
+PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
+
+extern int _PyUnicode_Init(void);
+extern int _PyStructSequence_Init(void);
+extern int _PyLong_Init(void);
+extern _PyInitError _PyFaulthandler_Init(int enable);
+extern int _PyTraceMalloc_Init(int enable);
+
+extern void _Py_ReadyTypes(void);
+
+PyAPI_FUNC(void) _PyExc_Fini(void);
+PyAPI_FUNC(void) _PyImport_Fini(void);
+PyAPI_FUNC(void) _PyImport_Fini2(void);
+PyAPI_FUNC(void) _PyGC_Fini(void);
+PyAPI_FUNC(void) _PyType_Fini(void);
+PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
+extern void _PyUnicode_Fini(void);
+extern void PyLong_Fini(void);
+extern void _PyFaulthandler_Fini(void);
+extern void _PyHash_Fini(void);
+extern int _PyTraceMalloc_Fini(void);
+
+extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
+extern void _PyGILState_Fini(void);
+
+PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_LIFECYCLE_H */
diff --git a/Include/internal/pycore_pathconfig.h b/Include/internal/pycore_pathconfig.h
new file mode 100644
index 000000000000..395df498a0dc
--- /dev/null
+++ b/Include/internal/pycore_pathconfig.h
@@ -0,0 +1,68 @@
+#ifndef Py_INTERNAL_PATHCONFIG_H
+#define Py_INTERNAL_PATHCONFIG_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_FUNC(void) _Py_wstrlist_clear(
+    int len,
+    wchar_t **list);
+PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
+    int len,
+    wchar_t **list);
+PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
+    int *len,
+    wchar_t ***list,
+    const wchar_t *str);
+PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(
+    int len,
+    wchar_t **list);
+
+typedef struct _PyPathConfig {
+    /* Full path to the Python program */
+    wchar_t *program_full_path;
+    wchar_t *prefix;
+#ifdef MS_WINDOWS
+    wchar_t *dll_path;
+#else
+    wchar_t *exec_prefix;
+#endif
+    /* Set by Py_SetPath(), or computed by _PyPathConfig_Init() */
+    wchar_t *module_search_path;
+    /* Python program name */
+    wchar_t *program_name;
+    /* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
+    wchar_t *home;
+    /* isolated and site_import are used to set Py_IsolatedFlag and
+       Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
+       are ignored when their value are equal to -1 (unset). */
+    int isolated;
+    int site_import;
+} _PyPathConfig;
+
+#define _PyPathConfig_INIT \
+    {.module_search_path = NULL, \
+     .isolated = -1, \
+     .site_import = -1}
+/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
+
+PyAPI_DATA(_PyPathConfig) _Py_path_config;
+
+PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
+PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
+    const struct _PyPathConfig *config);
+
+PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
+    _PyPathConfig *config,
+    const _PyCoreConfig *core_config);
+PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
+PyAPI_FUNC(int) _Py_FindEnvConfigValue(
+    FILE *env_file,
+    const wchar_t *key,
+    wchar_t *value,
+    size_t value_size);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_PATHCONFIG_H */
diff --git a/Include/internal/pycore_state.h b/Include/internal/pycore_state.h
index 9a084f7f4d84..6285ecf5f5dc 100644
--- a/Include/internal/pycore_state.h
+++ b/Include/internal/pycore_state.h
@@ -11,8 +11,9 @@ extern "C" {
 #include "pystate.h"
 #include "pythread.h"
 
-#include "pycore_mem.h"
 #include "pycore_ceval.h"
+#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
 #include "pycore_warnings.h"
 
 
@@ -40,52 +41,6 @@ struct _gilstate_runtime_state {
 #define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
 
 
-typedef struct _PyPathConfig {
-    /* Full path to the Python program */
-    wchar_t *program_full_path;
-    wchar_t *prefix;
-#ifdef MS_WINDOWS
-    wchar_t *dll_path;
-#else
-    wchar_t *exec_prefix;
-#endif
-    /* Set by Py_SetPath(), or computed by _PyPathConfig_Init() */
-    wchar_t *module_search_path;
-    /* Python program name */
-    wchar_t *program_name;
-    /* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
-    wchar_t *home;
-    /* isolated and site_import are used to set Py_IsolatedFlag and
-       Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
-       are ignored when their value are equal to -1 (unset). */
-    int isolated;
-    int site_import;
-} _PyPathConfig;
-
-#define _PyPathConfig_INIT \
-    {.module_search_path = NULL, \
-     .isolated = -1, \
-     .site_import = -1}
-/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
-
-PyAPI_DATA(_PyPathConfig) _Py_path_config;
-
-PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
-    _PyPathConfig *config,
-    const _PyCoreConfig *core_config);
-PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
-
-PyAPI_FUNC(void) _Py_wstrlist_clear(
-    int len,
-    wchar_t **list);
-PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
-    int len,
-    wchar_t **list);
-PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
-    int *len,
-    wchar_t ***list,
-    const wchar_t *str);
-
 /* interpreter state */
 
 PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpID(PY_INT64_T);
diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h
index 04e672e96e17..ca1f24f2a174 100644
--- a/Include/pylifecycle.h
+++ b/Include/pylifecycle.h
@@ -20,9 +20,6 @@ PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
 PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
                                              const char *errors);
 #endif
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(void) _Py_ClearStandardStreamEncoding(void);
-#endif
 
 
 #ifndef Py_LIMITED_API
@@ -82,27 +79,12 @@ PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
 
 /* Bootstrap __main__ (defined in Modules/main.c) */
 PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
-#endif
 
 /* In getpath.c */
 PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
 PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
 PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
 PyAPI_FUNC(wchar_t *) Py_GetPath(void);
-#ifdef Py_BUILD_CORE
-struct _PyPathConfig;
-
-PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
-    const struct _PyPathConfig *config);
-PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
-PyAPI_FUNC(int) _Py_FindEnvConfigValue(
-    FILE *env_file,
-    const wchar_t *key,
-    wchar_t *value,
-    size_t value_size);
-#endif
 PyAPI_FUNC(void)      Py_SetPath(const wchar_t *);
 #ifdef MS_WINDOWS
 int _Py_CheckPython3(void);
@@ -134,16 +116,6 @@ PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(const _PyCoreConfig *);
 
 /* Various internal finalizers */
 
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(void) _PyExc_Fini(void);
-PyAPI_FUNC(void) _PyImport_Fini(void);
-PyAPI_FUNC(void) _PyImport_Fini2(void);
-PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
-PyAPI_FUNC(void) _PyGC_Fini(void);
-PyAPI_FUNC(void) _PyType_Fini(void);
-PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
-#endif   /* Py_BUILD_CORE */
-
 #ifndef Py_LIMITED_API
 PyAPI_FUNC(void) PyMethod_Fini(void);
 PyAPI_FUNC(void) PyFrame_Fini(void);
@@ -179,9 +151,6 @@ PyAPI_FUNC(void) _Py_CoerceLegacyLocale(int warn);
 PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void);
 PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
 #endif
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
-#endif
 
 #ifdef __cplusplus
 }
diff --git a/Makefile.pre.in b/Makefile.pre.in
index fc8b1e4e7334..15f3687be5b1 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1030,7 +1030,9 @@ PYTHON_HEADERS= \
 		$(srcdir)/Include/internal/pycore_context.h \
 		$(srcdir)/Include/internal/pycore_getopt.h \
 		$(srcdir)/Include/internal/pycore_gil.h \
+		$(srcdir)/Include/internal/pycore_lifecycle.h \
 		$(srcdir)/Include/internal/pycore_mem.h \
+		$(srcdir)/Include/internal/pycore_pathconfig.h \
 		$(srcdir)/Include/internal/pycore_state.h \
 		$(srcdir)/Include/internal/pycore_warnings.h \
 		$(DTRACE_HEADERS)
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 018af4a13707..e2deb2603da8 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -8,10 +8,12 @@
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
-#include <float.h>
-#include "structmember.h"
 #include "datetime.h"
 #include "marshal.h"
+#include "pycore_pathconfig.h"
+#include "pythread.h"
+#include "structmember.h"
+#include <float.h>
 #include <signal.h>
 
 #ifdef MS_WINDOWS
@@ -22,7 +24,6 @@
 #include <sys/wait.h>           /* For W_STOPCODE */
 #endif
 
-#include "pythread.h"
 static PyObject *TestError;     /* set to exception object in init */
 
 /* Raise TestError with test_name + ": " + msg, and return NULL. */
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 53e5c2b889a6..0e210710ecf4 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -1,8 +1,9 @@
 /* Return the initial module search path. */
 
 #include "Python.h"
-#include "pycore_state.h"
 #include "osdefs.h"
+#include "pycore_pathconfig.h"
+#include "pycore_state.h"
 
 #include <sys/types.h>
 #include <string.h>
diff --git a/Modules/main.c b/Modules/main.c
index 1918f4f9b8ff..c847d1acedb7 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -2,8 +2,10 @@
 
 #include "Python.h"
 #include "osdefs.h"
-#include "pycore_mem.h"
 #include "pycore_getopt.h"
+#include "pycore_lifecycle.h"
+#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
 #include "pycore_state.h"
 
 #include <locale.h>
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 6becb8a3682c..460500cc2b1b 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -119,7 +119,9 @@
     <ClInclude Include="..\Include\internal\pycore_getopt.h" />
     <ClInclude Include="..\Include\internal\pycore_gil.h" />
     <ClInclude Include="..\Include\internal\pycore_hamt.h" />
+    <ClInclude Include="..\Include\internal\pycore_lifecycle.h" />
     <ClInclude Include="..\Include\internal\pycore_mem.h" />
+    <ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
     <ClInclude Include="..\Include\internal\pycore_state.h" />
     <ClInclude Include="..\Include\internal\pycore_warnings.h" />
     <ClInclude Include="..\Include\intrcheck.h" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index bc118c636cde..64fb77b867c4 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -156,9 +156,15 @@
     <ClInclude Include="..\Include\internal\pycore_hamt.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\internal\pycore_lifecycle.h">
+      <Filter>Include</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_mem.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\internal\pycore_pathconfig.h">
+      <Filter>Include</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_state.h">
       <Filter>Include</Filter>
     </ClInclude>
diff --git a/Programs/python.c b/Programs/python.c
index 78e48f800c95..079bf9a2f039 100644
--- a/Programs/python.c
+++ b/Programs/python.c
@@ -1,6 +1,7 @@
 /* Minimal main program -- everything is loaded from the library */
 
 #include "Python.h"
+#include "pycore_lifecycle.h"
 
 #ifdef MS_WINDOWS
 int
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index ad14a8a457da..b21e9344cd16 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -1,5 +1,7 @@
 #include "Python.h"
+#include "pycore_lifecycle.h"
 #include "pycore_mem.h"
+#include "pycore_pathconfig.h"
 #include "pycore_state.h"
 #include <locale.h>
 #ifdef HAVE_LANGINFO_H
diff --git a/Python/import.c b/Python/import.c
index 18cd29df7e93..67911ff0e41b 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -5,6 +5,7 @@
 #include "Python-ast.h"
 #undef Yield /* undefine macro conflicting with winbase.h */
 #include "pycore_hash.h"
+#include "pycore_lifecycle.h"
 #include "pycore_mem.h"
 #include "pycore_state.h"
 #include "errcode.h"
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index 04064159f86b..f8bcc2886a1c 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -3,6 +3,7 @@
 #include "Python.h"
 #include "osdefs.h"
 #include "pycore_mem.h"
+#include "pycore_pathconfig.h"
 #include "pycore_state.h"
 #include <wchar.h>
 
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 160f30ce6d6e..4c5cb5342917 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -6,7 +6,9 @@
 #undef Yield /* undefine macro conflicting with winbase.h */
 #include "pycore_context.h"
 #include "pycore_hamt.h"
+#include "pycore_lifecycle.h"
 #include "pycore_mem.h"
+#include "pycore_pathconfig.h"
 #include "pycore_state.h"
 #include "grammar.h"
 #include "node.h"
@@ -62,20 +64,6 @@ static _PyInitError initsigs(void);
 static void call_py_exitfuncs(PyInterpreterState *);
 static void wait_for_thread_shutdown(void);
 static void call_ll_exitfuncs(void);
-extern int _PyUnicode_Init(void);
-extern int _PyStructSequence_Init(void);
-extern void _PyUnicode_Fini(void);
-extern int _PyLong_Init(void);
-extern void PyLong_Fini(void);
-extern _PyInitError _PyFaulthandler_Init(int enable);
-extern void _PyFaulthandler_Fini(void);
-extern void _PyHash_Fini(void);
-extern int _PyTraceMalloc_Init(int enable);
-extern int _PyTraceMalloc_Fini(void);
-extern void _Py_ReadyTypes(void);
-
-extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
-extern void _PyGILState_Fini(void);
 
 _PyRuntimeState _PyRuntime = _PyRuntimeState_INIT;
 
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 830f0a88e4fb..21647083d683 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -15,10 +15,12 @@ Data members:
 */
 
 #include "Python.h"
-#include "pycore_mem.h"
-#include "pycore_state.h"
 #include "code.h"
 #include "frameobject.h"
+#include "pycore_lifecycle.h"
+#include "pycore_mem.h"
+#include "pycore_pathconfig.h"
+#include "pycore_state.h"
 #include "pythread.h"
 
 #include "osdefs.h"



More information about the Python-checkins mailing list