@@ -239,14 +239,23 @@ The ``PyPreConfig`` structure is used to preinitialize Python:
239
239
* Configure the LC_CTYPE locale
240
240
* Set the UTF-8 mode
241
241
242
+ The ``struct_size `` field must be explicitly initialized to
243
+ ``sizeof(PyPreConfig) ``.
244
+
242
245
Example using the preinitialization to enable the UTF-8 Mode::
243
246
247
+ PyStatus status;
244
248
PyPreConfig preconfig;
245
- PyPreConfig_InitPythonConfig(&preconfig);
249
+ preconfig.struct_size = sizeof(PyPreConfig);
250
+
251
+ status = PyPreConfig_InitPythonConfig(&preconfig);
252
+ if (PyStatus_Exception(status)) {
253
+ Py_ExitStatusException(status);
254
+ }
246
255
247
256
preconfig.utf8_mode = 1;
248
257
249
- PyStatus status = Py_PreInitialize(&preconfig);
258
+ status = Py_PreInitialize(&preconfig);
250
259
if (PyStatus_Exception(status)) {
251
260
Py_ExitStatusException(status);
252
261
}
@@ -259,8 +268,8 @@ Example using the preinitialization to enable the UTF-8 Mode::
259
268
260
269
Function to initialize a preconfiguration:
261
270
262
- * ``void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig) ``
263
- * ``void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig) ``
271
+ * ``PyStatus PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig) ``
272
+ * ``PyStatus PyPreConfig_InitPythonConfig(PyPreConfig *preconfig) ``
264
273
265
274
Functions to preinitialize Python:
266
275
@@ -318,6 +327,9 @@ an effect on the pre-configuration like encodings. For example, the
318
327
``Py_PreInitializeFromBytesArgs() `` parse their ``argv `` argument the
319
328
same way the regular Python parses command line arguments: see
320
329
`Command Line Arguments `_.
330
+ * ``struct_size `` (``size_t ``:
331
+ Size of the structure in bytes: must be initialized to
332
+ ``sizeof(PyPreConfig) ``. Field used for API and ABI compatibility.
321
333
* ``use_environment `` (``int ``):
322
334
See ``PyConfig.use_environment ``.
323
335
* ``utf8_mode `` (``int ``):
@@ -328,8 +340,6 @@ The ``legacy_windows_fs_encoding`` field is only available on Windows.
328
340
329
341
``PyPreConfig `` private fields, for internal use only:
330
342
331
- * ``_config_version `` (``int ``):
332
- Configuration version, used for ABI compatibility.
333
343
* ``_config_init `` (``int ``):
334
344
Function used to initialize ``PyConfig ``, used for preinitialization.
335
345
@@ -349,12 +359,16 @@ Initialization with PyConfig
349
359
350
360
The ``PyConfig `` structure contains most parameters to configure Python.
351
361
362
+ The ``struct_size `` field must be explicitly initialized to
363
+ ``sizeof(PyConfig) ``.
364
+
352
365
Example setting the program name::
353
366
354
367
void init_python(void)
355
368
{
356
369
PyStatus status;
357
370
PyConfig config;
371
+ config.struct_size = sizeof(PyConfig);
358
372
359
373
status = PyConfig_InitPythonConfig(&config);
360
374
if (PyStatus_Exception(status)) {
@@ -557,6 +571,9 @@ exceptions (error or exit) using ``PyStatus_Exception()`` and
557
571
``stdio_errors `` (``wchar_t* ``):
558
572
Encoding and encoding errors of ``sys.stdin ``, ``sys.stdout ``
559
573
and ``sys.stderr ``.
574
+ * ``struct_size `` (``size_t ``:
575
+ Size of the structure in bytes: must be initialized to
576
+ ``sizeof(PyConfig) ``. Field used for API and ABI compatibility.
560
577
* ``tracemalloc `` (``int ``):
561
578
If non-zero, call ``tracemalloc.start(value) ``.
562
579
* ``user_site_directory `` (``int ``):
@@ -582,8 +599,6 @@ Options`_.
582
599
583
600
``PyConfig `` private fields, for internal use only:
584
601
585
- * ``_config_version `` (``int ``):
586
- Configuration version, used for ABI compatibility.
587
602
* ``_config_init `` (``int ``):
588
603
Function used to initialize ``PyConfig ``, used for preinitialization.
589
604
* ``_install_importlib `` (``int ``):
@@ -599,6 +614,7 @@ configuration, and then override some parameters::
599
614
{
600
615
PyStatus status;
601
616
PyConfig config;
617
+ config.struct_size = sizeof(PyConfig);
602
618
603
619
status = PyConfig_InitPythonConfig(&config);
604
620
if (PyStatus_Exception(status)) {
@@ -685,8 +701,9 @@ Example of customized Python always running in isolated mode::
685
701
686
702
int main(int argc, char **argv)
687
703
{
688
- PyConfig config;
689
704
PyStatus status;
705
+ PyConfig config;
706
+ config.struct_size = sizeof(PyConfig);
690
707
691
708
status = PyConfig_InitPythonConfig(&config);
692
709
if (PyStatus_Exception(status)) {
@@ -862,6 +879,7 @@ phases::
862
879
{
863
880
PyStatus status;
864
881
PyConfig config;
882
+ config.struct_size = sizeof(PyConfig);
865
883
866
884
status = PyConfig_InitPythonConfig(&config);
867
885
if (PyStatus_Exception(status)) {
0 commit comments