Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit bdace21

Browse files
vstinnerncoghlan
authored andcommitted
bpo-38304: Remove PyConfig.struct_size (pythonGH-16500)
For now, we'll rely on the fact that the config structures aren't covered by the stable ABI. We may revisit this in the future if we further explore the idea of offering a stable embedding API.
1 parent 92ca515 commit bdace21

14 files changed

+39
-273
lines changed

Doc/c-api/init_config.rst

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,18 @@ PyPreConfig
194194
* Configure the LC_CTYPE locale
195195
* Set the UTF-8 mode
196196
197-
The :c:member:`struct_size` field must be explicitly initialized to
198-
``sizeof(PyPreConfig)``.
199-
200197
Function to initialize a preconfiguration:
201198
202-
.. c:function:: PyStatus PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
199+
.. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
203200
204201
Initialize the preconfiguration with :ref:`Python Configuration
205202
<init-python-config>`.
206203
207-
.. c:function:: PyStatus PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
204+
.. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
208205
209206
Initialize the preconfiguration with :ref:`Isolated Configuration
210207
<init-isolated-conf>`.
211208
212-
The caller of these functions is responsible to handle exceptions (error or
213-
exit) using :c:func:`PyStatus_Exception` and
214-
:c:func:`Py_ExitStatusException`.
215-
216209
Structure fields:
217210
218211
.. c:member:: int allocator
@@ -274,13 +267,6 @@ PyPreConfig
274267
same way the regular Python parses command line arguments: see
275268
:ref:`Command Line Arguments <using-on-cmdline>`.
276269
277-
.. c:member:: size_t struct_size
278-
279-
Size of the structure in bytes: must be initialized to
280-
``sizeof(PyPreConfig)``.
281-
282-
Field used for API and ABI compatibility.
283-
284270
.. c:member:: int use_environment
285271
286272
See :c:member:`PyConfig.use_environment`.
@@ -332,12 +318,7 @@ Example using the preinitialization to enable the UTF-8 Mode::
332318
333319
PyStatus status;
334320
PyPreConfig preconfig;
335-
preconfig.struct_size = sizeof(PyPreConfig);
336-
337-
status = PyPreConfig_InitPythonConfig(&preconfig);
338-
if (PyStatus_Exception(status)) {
339-
Py_ExitStatusException(status);
340-
}
321+
PyPreConfig_InitPythonConfig(&preconfig);
341322
342323
preconfig.utf8_mode = 1;
343324
@@ -360,9 +341,6 @@ PyConfig
360341
361342
Structure containing most parameters to configure Python.
362343
363-
The :c:member:`struct_size` field must be explicitly initialized to
364-
``sizeof(PyConfig)``.
365-
366344
Structure methods:
367345
368346
.. c:function:: PyStatus PyConfig_InitPythonConfig(PyConfig *config)
@@ -679,13 +657,6 @@ PyConfig
679657
Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and
680658
:data:`sys.stderr`.
681659
682-
.. c:member:: size_t struct_size
683-
684-
Size of the structure in bytes: must be initialized to
685-
``sizeof(PyConfig)``.
686-
687-
Field used for API and ABI compatibility.
688-
689660
.. c:member:: int tracemalloc
690661
691662
If non-zero, call :func:`tracemalloc.start` at startup.
@@ -754,7 +725,6 @@ Example setting the program name::
754725
{
755726
PyStatus status;
756727
PyConfig config;
757-
config.struct_size = sizeof(PyConfig);
758728
759729
status = PyConfig_InitPythonConfig(&config);
760730
if (PyStatus_Exception(status)) {
@@ -787,7 +757,6 @@ configuration, and then override some parameters::
787757
{
788758
PyStatus status;
789759
PyConfig config;
790-
config.struct_size = sizeof(PyConfig);
791760
792761
status = PyConfig_InitPythonConfig(&config);
793762
if (PyStatus_Exception(status)) {
@@ -875,7 +844,6 @@ Example of customized Python always running in isolated mode::
875844
{
876845
PyStatus status;
877846
PyConfig config;
878-
config.struct_size = sizeof(PyConfig);
879847
880848
status = PyConfig_InitPythonConfig(&config);
881849
if (PyStatus_Exception(status)) {
@@ -1067,7 +1035,6 @@ phases::
10671035
{
10681036
PyStatus status;
10691037
PyConfig config;
1070-
config.struct_size = sizeof(PyConfig);
10711038
10721039
status = PyConfig_InitPythonConfig(&config);
10731040
if (PyStatus_Exception(status)) {

Include/cpython/initconfig.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
4545
/* --- PyPreConfig ----------------------------------------------- */
4646

4747
typedef struct {
48-
/* Size of the structure in bytes: must be initialized to
49-
sizeof(PyPreConfig). Field used for API and ABI compatibility. */
50-
size_t struct_size;
51-
5248
int _config_init; /* _PyConfigInitEnum value */
5349

5450
/* Parse Py_PreInitializeFromBytesArgs() arguments?
@@ -124,17 +120,13 @@ typedef struct {
124120
int allocator;
125121
} PyPreConfig;
126122

127-
PyAPI_FUNC(PyStatus) PyPreConfig_InitPythonConfig(PyPreConfig *config);
128-
PyAPI_FUNC(PyStatus) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
123+
PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
124+
PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
129125

130126

131127
/* --- PyConfig ---------------------------------------------- */
132128

133129
typedef struct {
134-
/* Size of the structure in bytes: must be initialized to
135-
sizeof(PyConfig). Field used for API and ABI compatibility. */
136-
size_t struct_size;
137-
138130
int _config_init; /* _PyConfigInitEnum value */
139131

140132
int isolated; /* Isolated mode? see PyPreConfig.isolated */

Include/internal/pycore_initconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
120120

121121
/* --- PyPreConfig ----------------------------------------------- */
122122

123-
PyAPI_FUNC(PyStatus) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
124-
extern PyStatus _PyPreConfig_InitFromConfig(
123+
PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
124+
extern void _PyPreConfig_InitFromConfig(
125125
PyPreConfig *preconfig,
126126
const PyConfig *config);
127127
extern PyStatus _PyPreConfig_InitFromPreConfig(

Misc/NEWS.d/next/C API/2019-09-28-03-43-27.bpo-38304.RqHAwd.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

Modules/main.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,15 @@ pymain_init(const _PyArgv *args)
5353
#endif
5454

5555
PyPreConfig preconfig;
56-
preconfig.struct_size = sizeof(PyPreConfig);
57-
58-
status = PyPreConfig_InitPythonConfig(&preconfig);
59-
if (_PyStatus_EXCEPTION(status)) {
60-
return status;
61-
}
56+
PyPreConfig_InitPythonConfig(&preconfig);
6257

6358
status = _Py_PreInitializeFromPyArgv(&preconfig, args);
6459
if (_PyStatus_EXCEPTION(status)) {
6560
return status;
6661
}
6762

6863
PyConfig config;
69-
config.struct_size = sizeof(PyConfig);
64+
7065
status = PyConfig_InitPythonConfig(&config);
7166
if (_PyStatus_EXCEPTION(status)) {
7267
goto done;

PC/python_uwp.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,8 @@ int
165165
wmain(int argc, wchar_t **argv)
166166
{
167167
PyStatus status;
168-
169168
PyPreConfig preconfig;
170-
preconfig.struct_size = sizeof(PyPreConfig);
171-
172169
PyConfig config;
173-
config.struct_size = sizeof(PyConfig);
174170

175171
const wchar_t *moduleName = NULL;
176172
const wchar_t *p = wcsrchr(argv[0], L'\\');
@@ -189,10 +185,7 @@ wmain(int argc, wchar_t **argv)
189185
}
190186
}
191187

192-
status = PyPreConfig_InitPythonConfig(&preconfig);
193-
if (PyStatus_Exception(status)) {
194-
goto fail_without_config;
195-
}
188+
PyPreConfig_InitPythonConfig(&preconfig);
196189
if (!moduleName) {
197190
status = Py_PreInitializeFromArgs(&preconfig, argc, argv);
198191
if (PyStatus_Exception(status)) {

Programs/_freeze_importlib.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ main(int argc, char *argv[])
7878

7979
PyStatus status;
8080
PyConfig config;
81-
config.struct_size = sizeof(PyConfig);
8281

8382
status = PyConfig_InitIsolatedConfig(&config);
8483
if (PyStatus_Exception(status)) {

0 commit comments

Comments
 (0)