@@ -194,18 +194,25 @@ 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+
197200 Function to initialize a preconfiguration:
198201
199- .. c :function :: void PyPreConfig_InitIsolatedConfig (PyPreConfig *preconfig)
202+ .. c :function :: PyStatus PyPreConfig_InitIsolatedConfig (PyPreConfig *preconfig)
200203
201204 Initialize the preconfiguration with :ref: `Python Configuration
202205 <init-python-config>`.
203206
204- .. c :function :: void PyPreConfig_InitPythonConfig (PyPreConfig *preconfig)
207+ .. c :function :: PyStatus PyPreConfig_InitPythonConfig (PyPreConfig *preconfig)
205208
206209 Initialize the preconfiguration with :ref: `Isolated Configuration
207210 <init-isolated-conf>`.
208211
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+
209216 Structure fields:
210217
211218 .. c:member:: int allocator
@@ -267,6 +274,13 @@ PyPreConfig
267274 same way the regular Python parses command line arguments: see
268275 :ref: `Command Line Arguments <using-on-cmdline >`.
269276
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+
270284 .. c :member :: int use_environment
271285
272286 See :c:member: `PyConfig.use_environment `.
@@ -316,12 +330,18 @@ the preinitialization.
316330
317331Example using the preinitialization to enable the UTF-8 Mode::
318332
333+ PyStatus status;
319334 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+ }
321341
322342 preconfig.utf8_mode = 1;
323343
324- PyStatus status = Py_PreInitialize(&preconfig);
344+ status = Py_PreInitialize(&preconfig);
325345 if (PyStatus_Exception(status)) {
326346 Py_ExitStatusException (status);
327347 }
@@ -340,6 +360,9 @@ PyConfig
340360
341361 Structure containing most parameters to configure Python.
342362
363+ The :c:member: `struct_size ` field must be explicitly initialized to
364+ ``sizeof(PyConfig) ``.
365+
343366 Structure methods:
344367
345368 .. c :function :: PyStatus PyConfig_InitPythonConfig (PyConfig *config)
@@ -656,6 +679,13 @@ PyConfig
656679 Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and
657680 :data:`sys.stderr`.
658681
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+
659689 .. c:member:: int tracemalloc
660690
661691 If non-zero, call :func:`tracemalloc.start` at startup.
@@ -718,6 +748,7 @@ Example setting the program name::
718748 {
719749 PyStatus status;
720750 PyConfig config;
751+ config.struct_size = sizeof (PyConfig);
721752
722753 status = PyConfig_InitPythonConfig (&config);
723754 if (PyStatus_Exception (status)) {
@@ -750,6 +781,7 @@ configuration, and then override some parameters::
750781 {
751782 PyStatus status;
752783 PyConfig config;
784+ config.struct_size = sizeof(PyConfig);
753785
754786 status = PyConfig_InitPythonConfig(&config);
755787 if (PyStatus_Exception(status)) {
@@ -835,8 +867,9 @@ Example of customized Python always running in isolated mode::
835867
836868 int main(int argc, char **argv)
837869 {
838- PyConfig config;
839870 PyStatus status;
871+ PyConfig config;
872+ config.struct_size = sizeof(PyConfig);
840873
841874 status = PyConfig_InitPythonConfig(&config);
842875 if (PyStatus_Exception(status)) {
@@ -1028,6 +1061,7 @@ phases::
10281061 {
10291062 PyStatus status;
10301063 PyConfig config;
1064+ config.struct_size = sizeof (PyConfig);
10311065
10321066 status = PyConfig_InitPythonConfig (&config);
10331067 if (PyStatus_Exception (status)) {
0 commit comments