bpo-38304: Add PyConfig.struct_size (GH-16451) (GH-16453) · python/cpython@6e12838 (original) (raw)
`@@ -194,18 +194,25 @@ PyPreConfig
`
194
194
` * Configure the LC_CTYPE locale
`
195
195
` * Set the UTF-8 mode
`
196
196
``
``
197
`` +
The :c:member:struct_size
field must be explicitly initialized to
``
``
198
``sizeof(PyPreConfig)``.
``
199
+
197
200
` Function to initialize a preconfiguration:
`
198
201
``
199
``
`-
.. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
`
``
202
`+
.. c:function:: PyStatus PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
`
200
203
``
201
204
`` Initialize the preconfiguration with :ref:`Python Configuration
``
202
205
`` `.
``
203
206
``
204
``
`-
.. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
`
``
207
`+
.. c:function:: PyStatus PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
`
205
208
``
206
209
`` Initialize the preconfiguration with :ref:`Isolated Configuration
``
207
210
`` `.
``
208
211
``
``
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
+
209
216
` Structure fields:
`
210
217
``
211
218
` .. c:member:: int allocator
`
`@@ -267,6 +274,13 @@ PyPreConfig
`
267
274
` same way the regular Python parses command line arguments: see
`
268
275
`` :ref:Command Line Arguments <using-on-cmdline>
.
``
269
276
``
``
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
+
270
284
` .. c:member:: int use_environment
`
271
285
``
272
286
`` See :c:member:PyConfig.use_environment
.
``
`@@ -316,12 +330,18 @@ the preinitialization.
`
316
330
``
317
331
`Example using the preinitialization to enable the UTF-8 Mode::
`
318
332
``
``
333
`+
PyStatus status;
`
319
334
` PyPreConfig preconfig;
`
320
``
`-
PyPreConfig_InitPythonConfig(&preconfig);
`
``
335
`+
preconfig.struct_size = sizeof(PyPreConfig);
`
``
336
+
``
337
`+
status = PyPreConfig_InitPythonConfig(&preconfig);
`
``
338
`+
if (PyStatus_Exception(status)) {
`
``
339
`+
Py_ExitStatusException(status);
`
``
340
`+
}
`
321
341
``
322
342
` preconfig.utf8_mode = 1;
`
323
343
``
324
``
`-
PyStatus status = Py_PreInitialize(&preconfig);
`
``
344
`+
status = Py_PreInitialize(&preconfig);
`
325
345
` if (PyStatus_Exception(status)) {
`
326
346
`Py_ExitStatusException(status);
`
327
347
` }
`
`@@ -340,6 +360,9 @@ PyConfig
`
340
360
``
341
361
` Structure containing most parameters to configure Python.
`
342
362
``
``
363
`` +
The :c:member:struct_size
field must be explicitly initialized to
``
``
364
``sizeof(PyConfig)``.
``
365
+
343
366
` Structure methods:
`
344
367
``
345
368
` .. c:function:: PyStatus PyConfig_InitPythonConfig(PyConfig *config)
`
`@@ -656,6 +679,13 @@ PyConfig
`
656
679
`` Encoding and encoding errors of :data:sys.stdin
, :data:sys.stdout
and
``
657
680
`` :data:sys.stderr
.
``
658
681
``
``
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
+
659
689
` .. c:member:: int tracemalloc
`
660
690
``
661
691
`` If non-zero, call :func:tracemalloc.start
at startup.
``
`@@ -718,6 +748,7 @@ Example setting the program name::
`
718
748
` {
`
719
749
` PyStatus status;
`
720
750
` PyConfig config;
`
``
751
`+
config.struct_size = sizeof(PyConfig);
`
721
752
``
722
753
` status = PyConfig_InitPythonConfig(&config);
`
723
754
` if (PyStatus_Exception(status)) {
`
`@@ -750,6 +781,7 @@ configuration, and then override some parameters::
`
750
781
` {
`
751
782
` PyStatus status;
`
752
783
` PyConfig config;
`
``
784
`+
config.struct_size = sizeof(PyConfig);
`
753
785
``
754
786
` status = PyConfig_InitPythonConfig(&config);
`
755
787
` if (PyStatus_Exception(status)) {
`
`@@ -835,8 +867,9 @@ Example of customized Python always running in isolated mode::
`
835
867
``
836
868
` int main(int argc, char **argv)
`
837
869
` {
`
838
``
`-
PyConfig config;
`
839
870
` PyStatus status;
`
``
871
`+
PyConfig config;
`
``
872
`+
config.struct_size = sizeof(PyConfig);
`
840
873
``
841
874
` status = PyConfig_InitPythonConfig(&config);
`
842
875
`if (PyStatus_Exception(status)) {
`
`@@ -1028,6 +1061,7 @@ phases::
`
1028
1061
` {
`
1029
1062
` PyStatus status;
`
1030
1063
` PyConfig config;
`
``
1064
`+
config.struct_size = sizeof(PyConfig);
`
1031
1065
``
1032
1066
` status = PyConfig_InitPythonConfig(&config);
`
1033
1067
` if (PyStatus_Exception(status)) {
`