| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 52d1b86 commit 441b10c
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | <init-python-config>`. | |
| 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 | <init-isolated-conf>`. | |
| 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)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,8 +45,10 @@ PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list, | |||
| 45 | 45 | /* --- PyPreConfig ----------------------------------------------- */ | |
| 46 | 46 | ||
| 47 | 47 | typedef struct { | |
| 48 | - int _config_version; /* Internal configuration version, | ||
| 49 | - used for ABI compatibility */ | ||
| 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 | + | ||
| 50 | 52 | int _config_init; /* _PyConfigInitEnum value */ | |
| 51 | 53 | ||
| 52 | 54 | /* Parse Py_PreInitializeFromBytesArgs() arguments? | |
@@ -122,15 +124,17 @@ typedef struct { | |||
| 122 | 124 | int allocator; | |
| 123 | 125 | } PyPreConfig; | |
| 124 | 126 | ||
| 125 | - PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config); | ||
| 126 | - PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config); | ||
| 127 | + PyAPI_FUNC(PyStatus) PyPreConfig_InitPythonConfig(PyPreConfig *config); | ||
| 128 | + PyAPI_FUNC(PyStatus) PyPreConfig_InitIsolatedConfig(PyPreConfig *config); | ||
| 127 | 129 | ||
| 128 | 130 | ||
| 129 | 131 | /* --- PyConfig ---------------------------------------------- */ | |
| 130 | 132 | ||
| 131 | 133 | typedef struct { | |
| 132 | - int _config_version; /* Internal configuration version, | ||
| 133 | - used for ABI compatibility */ | ||
| 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 | + | ||
| 134 | 138 | int _config_init; /* _PyConfigInitEnum value */ | |
| 135 | 139 | ||
| 136 | 140 | int isolated; /* Isolated mode? see PyPreConfig.isolated */ | |
@@ -403,7 +407,6 @@ typedef struct { | |||
| 403 | 407 | ||
| 404 | 408 | /* If equal to 0, stop Python initialization before the "main" phase */ | |
| 405 | 409 | int _init_main; | |
| 406 | - | ||
| 407 | 410 | } PyConfig; | |
| 408 | 411 | ||
| 409 | 412 | PyAPI_FUNC(PyStatus) PyConfig_InitPythonConfig(PyConfig *config); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,8 @@ extern "C" { | |||
| 40 | 40 | (err._type == _PyStatus_TYPE_EXIT) | |
| 41 | 41 | #define _PyStatus_EXCEPTION(err) \ | |
| 42 | 42 | (err._type != _PyStatus_TYPE_OK) | |
| 43 | + #define _PyStatus_UPDATE_FUNC(err) \ | ||
| 44 | + do { err.func = _PyStatus_GET_FUNC(); } while (0) | ||
| 43 | 45 | ||
| 44 | 46 | /* --- PyWideStringList ------------------------------------------------ */ | |
| 45 | 47 | ||
@@ -118,11 +120,11 @@ extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline, | |||
| 118 | 120 | ||
| 119 | 121 | /* --- PyPreConfig ----------------------------------------------- */ | |
| 120 | 122 | ||
| 121 | - PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig); | ||
| 122 | - extern void _PyPreConfig_InitFromConfig( | ||
| 123 | + PyAPI_FUNC(PyStatus) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig); | ||
| 124 | + extern PyStatus _PyPreConfig_InitFromConfig( | ||
| 123 | 125 | PyPreConfig *preconfig, | |
| 124 | 126 | const PyConfig *config); | |
| 125 | - extern void _PyPreConfig_InitFromPreConfig( | ||
| 127 | + extern PyStatus _PyPreConfig_InitFromPreConfig( | ||
| 126 | 128 | PyPreConfig *preconfig, | |
| 127 | 129 | const PyPreConfig *config2); | |
| 128 | 130 | extern PyObject* _PyPreConfig_AsDict(const PyPreConfig *preconfig); | |
@@ -135,16 +137,14 @@ extern PyStatus _PyPreConfig_Write(const PyPreConfig *preconfig); | |||
| 135 | 137 | ||
| 136 | 138 | /* --- PyConfig ---------------------------------------------- */ | |
| 137 | 139 | ||
| 138 | - #define _Py_CONFIG_VERSION 1 | ||
| 139 | - | ||
| 140 | 140 | typedef enum { | |
| 141 | 141 | /* Py_Initialize() API: backward compatibility with Python 3.6 and 3.7 */ | |
| 142 | 142 | _PyConfig_INIT_COMPAT = 1, | |
| 143 | 143 | _PyConfig_INIT_PYTHON = 2, | |
| 144 | 144 | _PyConfig_INIT_ISOLATED = 3 | |
| 145 | 145 | } _PyConfigInitEnum; | |
| 146 | 146 | ||
| 147 | - PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config); | ||
| 147 | + PyAPI_FUNC(PyStatus) _PyConfig_InitCompatConfig(PyConfig *config); | ||
| 148 | 148 | extern PyStatus _PyConfig_Copy( | |
| 149 | 149 | PyConfig *config, | |
| 150 | 150 | const PyConfig *config2); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Add a new ``struct_size`` field to :c:type:`PyPreConfig` and :c:type:`PyConfig` | ||
| 2 | + structures to allow to modify these structures in the future without breaking | ||
| 3 | + the backward compatibility. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,13 +53,20 @@ pymain_init(const _PyArgv *args) | |||
| 53 | 53 | #endif | |
| 54 | 54 | ||
| 55 | 55 | PyPreConfig preconfig; | |
| 56 | - PyPreConfig_InitPythonConfig(&preconfig); | ||
| 56 | + preconfig.struct_size = sizeof(PyPreConfig); | ||
| 57 | + | ||
| 58 | + status = PyPreConfig_InitPythonConfig(&preconfig); | ||
| 59 | + if (_PyStatus_EXCEPTION(status)) { | ||
| 60 | + return status; | ||
| 61 | + } | ||
| 62 | + | ||
| 57 | 63 | status = _Py_PreInitializeFromPyArgv(&preconfig, args); | |
| 58 | 64 | if (_PyStatus_EXCEPTION(status)) { | |
| 59 | 65 | return status; | |
| 60 | 66 | } | |
| 61 | 67 | ||
| 62 | 68 | PyConfig config; | |
| 69 | + config.struct_size = sizeof(PyConfig); | ||
| 63 | 70 | status = PyConfig_InitPythonConfig(&config); | |
| 64 | 71 | if (_PyStatus_EXCEPTION(status)) { | |
| 65 | 72 | goto done; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,6 +78,7 @@ main(int argc, char *argv[]) | |||
| 78 | 78 | ||
| 79 | 79 | PyStatus status; | |
| 80 | 80 | PyConfig config; | |
| 81 | + config.struct_size = sizeof(PyConfig); | ||
| 81 | 82 | ||
| 82 | 83 | status = PyConfig_InitIsolatedConfig(&config); | |
| 83 | 84 | if (PyStatus_Exception(status)) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments