Skip to content

Commit a1c249c

Browse files
authored
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.
1 parent e281f7d commit a1c249c

File tree

17 files changed

+150
-110
lines changed

17 files changed

+150
-110
lines changed

‎Include/coreconfig.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,6 @@ PyAPI_FUNC(int) _PyCoreConfig_GetEnvDup(
361361
#endif
362362

363363

364-
#ifdef Py_BUILD_CORE
365-
PyAPI_FUNC(int) _Py_SetFileSystemEncoding(
366-
const char *encoding,
367-
const char *errors);
368-
PyAPI_FUNC(void) _Py_ClearFileSystemEncoding(void);
369-
#endif
370-
371-
#ifndef Py_LIMITED_API
372-
PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(int len, wchar_t **list);
373-
#endif
374-
375364

376365
#ifdef __cplusplus
377366
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef Py_INTERNAL_LIFECYCLE_H
2+
#define Py_INTERNAL_LIFECYCLE_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "Py_BUILD_CORE must be defined to include this header"
9+
#endif
10+
11+
PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
12+
13+
PyAPI_FUNC(int) _Py_SetFileSystemEncoding(
14+
const char *encoding,
15+
const char *errors);
16+
PyAPI_FUNC(void) _Py_ClearFileSystemEncoding(void);
17+
18+
PyAPI_FUNC(void) _Py_ClearStandardStreamEncoding(void);
19+
20+
PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
21+
22+
extern int _PyUnicode_Init(void);
23+
extern int _PyStructSequence_Init(void);
24+
extern int _PyLong_Init(void);
25+
extern _PyInitError _PyFaulthandler_Init(int enable);
26+
extern int _PyTraceMalloc_Init(int enable);
27+
28+
extern void _Py_ReadyTypes(void);
29+
30+
PyAPI_FUNC(void) _PyExc_Fini(void);
31+
PyAPI_FUNC(void) _PyImport_Fini(void);
32+
PyAPI_FUNC(void) _PyImport_Fini2(void);
33+
PyAPI_FUNC(void) _PyGC_Fini(void);
34+
PyAPI_FUNC(void) _PyType_Fini(void);
35+
PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
36+
extern void _PyUnicode_Fini(void);
37+
extern void PyLong_Fini(void);
38+
extern void _PyFaulthandler_Fini(void);
39+
extern void _PyHash_Fini(void);
40+
extern int _PyTraceMalloc_Fini(void);
41+
42+
extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
43+
extern void _PyGILState_Fini(void);
44+
45+
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
#endif /* !Py_INTERNAL_LIFECYCLE_H */
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef Py_INTERNAL_PATHCONFIG_H
2+
#define Py_INTERNAL_PATHCONFIG_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
PyAPI_FUNC(void) _Py_wstrlist_clear(
8+
int len,
9+
wchar_t **list);
10+
PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
11+
int len,
12+
wchar_t **list);
13+
PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
14+
int *len,
15+
wchar_t ***list,
16+
const wchar_t *str);
17+
PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(
18+
int len,
19+
wchar_t **list);
20+
21+
typedef struct _PyPathConfig {
22+
/* Full path to the Python program */
23+
wchar_t *program_full_path;
24+
wchar_t *prefix;
25+
#ifdef MS_WINDOWS
26+
wchar_t *dll_path;
27+
#else
28+
wchar_t *exec_prefix;
29+
#endif
30+
/* Set by Py_SetPath(), or computed by _PyPathConfig_Init() */
31+
wchar_t *module_search_path;
32+
/* Python program name */
33+
wchar_t *program_name;
34+
/* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
35+
wchar_t *home;
36+
/* isolated and site_import are used to set Py_IsolatedFlag and
37+
Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
38+
are ignored when their value are equal to -1 (unset). */
39+
int isolated;
40+
int site_import;
41+
} _PyPathConfig;
42+
43+
#define _PyPathConfig_INIT \
44+
{.module_search_path = NULL, \
45+
.isolated = -1, \
46+
.site_import = -1}
47+
/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
48+
49+
PyAPI_DATA(_PyPathConfig) _Py_path_config;
50+
51+
PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
52+
PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
53+
const struct _PyPathConfig *config);
54+
55+
PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
56+
_PyPathConfig *config,
57+
const _PyCoreConfig *core_config);
58+
PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
59+
PyAPI_FUNC(int) _Py_FindEnvConfigValue(
60+
FILE *env_file,
61+
const wchar_t *key,
62+
wchar_t *value,
63+
size_t value_size);
64+
65+
#ifdef __cplusplus
66+
}
67+
#endif
68+
#endif /* !Py_INTERNAL_PATHCONFIG_H */

‎Include/internal/pycore_state.h‎

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ extern "C" {
1111
#include "pystate.h"
1212
#include "pythread.h"
1313

14-
#include "pycore_mem.h"
1514
#include "pycore_ceval.h"
15+
#include "pycore_mem.h"
16+
#include "pycore_pathconfig.h"
1617
#include "pycore_warnings.h"
1718

1819

@@ -40,52 +41,6 @@ struct _gilstate_runtime_state {
4041
#define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
4142

4243

43-
typedef struct _PyPathConfig {
44-
/* Full path to the Python program */
45-
wchar_t *program_full_path;
46-
wchar_t *prefix;
47-
#ifdef MS_WINDOWS
48-
wchar_t *dll_path;
49-
#else
50-
wchar_t *exec_prefix;
51-
#endif
52-
/* Set by Py_SetPath(), or computed by _PyPathConfig_Init() */
53-
wchar_t *module_search_path;
54-
/* Python program name */
55-
wchar_t *program_name;
56-
/* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
57-
wchar_t *home;
58-
/* isolated and site_import are used to set Py_IsolatedFlag and
59-
Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
60-
are ignored when their value are equal to -1 (unset). */
61-
int isolated;
62-
int site_import;
63-
} _PyPathConfig;
64-
65-
#define _PyPathConfig_INIT \
66-
{.module_search_path = NULL, \
67-
.isolated = -1, \
68-
.site_import = -1}
69-
/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
70-
71-
PyAPI_DATA(_PyPathConfig) _Py_path_config;
72-
73-
PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
74-
_PyPathConfig *config,
75-
const _PyCoreConfig *core_config);
76-
PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
77-
78-
PyAPI_FUNC(void) _Py_wstrlist_clear(
79-
int len,
80-
wchar_t **list);
81-
PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
82-
int len,
83-
wchar_t **list);
84-
PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
85-
int *len,
86-
wchar_t ***list,
87-
const wchar_t *str);
88-
8944
/* interpreter state */
9045

9146
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpID(PY_INT64_T);

‎Include/pylifecycle.h‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
2020
PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
2121
const char *errors);
2222
#endif
23-
#ifdef Py_BUILD_CORE
24-
PyAPI_FUNC(void) _Py_ClearStandardStreamEncoding(void);
25-
#endif
2623

2724

2825
#ifndef Py_LIMITED_API
@@ -82,27 +79,12 @@ PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
8279

8380
/* Bootstrap __main__ (defined in Modules/main.c) */
8481
PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
85-
#ifdef Py_BUILD_CORE
86-
PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
87-
#endif
8882

8983
/* In getpath.c */
9084
PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
9185
PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
9286
PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
9387
PyAPI_FUNC(wchar_t *) Py_GetPath(void);
94-
#ifdef Py_BUILD_CORE
95-
struct _PyPathConfig;
96-
97-
PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
98-
const struct _PyPathConfig *config);
99-
PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
100-
PyAPI_FUNC(int) _Py_FindEnvConfigValue(
101-
FILE *env_file,
102-
const wchar_t *key,
103-
wchar_t *value,
104-
size_t value_size);
105-
#endif
10688
PyAPI_FUNC(void) Py_SetPath(const wchar_t *);
10789
#ifdef MS_WINDOWS
10890
int _Py_CheckPython3(void);
@@ -134,16 +116,6 @@ PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(const _PyCoreConfig *);
134116

135117
/* Various internal finalizers */
136118

137-
#ifdef Py_BUILD_CORE
138-
PyAPI_FUNC(void) _PyExc_Fini(void);
139-
PyAPI_FUNC(void) _PyImport_Fini(void);
140-
PyAPI_FUNC(void) _PyImport_Fini2(void);
141-
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
142-
PyAPI_FUNC(void) _PyGC_Fini(void);
143-
PyAPI_FUNC(void) _PyType_Fini(void);
144-
PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
145-
#endif /* Py_BUILD_CORE */
146-
147119
#ifndef Py_LIMITED_API
148120
PyAPI_FUNC(void) PyMethod_Fini(void);
149121
PyAPI_FUNC(void) PyFrame_Fini(void);
@@ -179,9 +151,6 @@ PyAPI_FUNC(void) _Py_CoerceLegacyLocale(int warn);
179151
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void);
180152
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
181153
#endif
182-
#ifdef Py_BUILD_CORE
183-
PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
184-
#endif
185154

186155
#ifdef __cplusplus
187156
}

‎Makefile.pre.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,9 @@ PYTHON_HEADERS= \
10301030
$(srcdir)/Include/internal/pycore_context.h \
10311031
$(srcdir)/Include/internal/pycore_getopt.h \
10321032
$(srcdir)/Include/internal/pycore_gil.h \
1033+
$(srcdir)/Include/internal/pycore_lifecycle.h \
10331034
$(srcdir)/Include/internal/pycore_mem.h \
1035+
$(srcdir)/Include/internal/pycore_pathconfig.h \
10341036
$(srcdir)/Include/internal/pycore_state.h \
10351037
$(srcdir)/Include/internal/pycore_warnings.h \
10361038
$(DTRACE_HEADERS)

‎Modules/_testcapimodule.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
#define PY_SSIZE_T_CLEAN
99

1010
#include "Python.h"
11-
#include <float.h>
12-
#include "structmember.h"
1311
#include "datetime.h"
1412
#include "marshal.h"
13+
#include "pycore_pathconfig.h"
14+
#include "pythread.h"
15+
#include "structmember.h"
16+
#include <float.h>
1517
#include <signal.h>
1618

1719
#ifdef MS_WINDOWS
@@ -22,7 +24,6 @@
2224
#include <sys/wait.h> /* For W_STOPCODE */
2325
#endif
2426

25-
#include "pythread.h"
2627
static PyObject *TestError; /* set to exception object in init */
2728

2829
/* Raise TestError with test_name + ": " + msg, and return NULL. */

‎Modules/getpath.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* Return the initial module search path. */
22

33
#include "Python.h"
4-
#include "pycore_state.h"
54
#include "osdefs.h"
5+
#include "pycore_pathconfig.h"
6+
#include "pycore_state.h"
67

78
#include <sys/types.h>
89
#include <string.h>

‎Modules/main.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
#include "Python.h"
44
#include "osdefs.h"
5-
#include "pycore_mem.h"
65
#include "pycore_getopt.h"
6+
#include "pycore_lifecycle.h"
7+
#include "pycore_mem.h"
8+
#include "pycore_pathconfig.h"
79
#include "pycore_state.h"
810

911
#include <locale.h>

‎PCbuild/pythoncore.vcxproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@
119119
<ClInclude Include="..\Include\internal\pycore_getopt.h" />
120120
<ClInclude Include="..\Include\internal\pycore_gil.h" />
121121
<ClInclude Include="..\Include\internal\pycore_hamt.h" />
122+
<ClInclude Include="..\Include\internal\pycore_lifecycle.h" />
122123
<ClInclude Include="..\Include\internal\pycore_mem.h" />
124+
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
123125
<ClInclude Include="..\Include\internal\pycore_state.h" />
124126
<ClInclude Include="..\Include\internal\pycore_warnings.h" />
125127
<ClInclude Include="..\Include\intrcheck.h" />

0 commit comments

Comments
 (0)