| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a5a4659 commit 2a92baf
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,15 +116,14 @@ Error Handling | |||
| 116 | 116 | ||
| 117 | 117 | Get the *config* exit code. | |
| 118 | 118 | ||
| 119 | - * Set *\*exitcode* and return ``1`` if *config* has an exit code set. | ||
| 120 | - * Return ``0`` if *config* has no exit code set. | ||
| 119 | + Return ``0``. | ||
| 121 | 120 | ||
| 122 | - Only the ``Py_InitializeFromInitConfig()`` function can set an exit | ||
| 123 | - code if the ``parse_argv`` option is non-zero. | ||
| 121 | + In Python 3.15, :c:func:`Py_InitializeFromInitConfig` sets an exit code if a | ||
| 122 | + command line option wants to exit Python. This is no longer the case in | ||
| 123 | + Python 3.16. Instead, the option is processed in :c:func:`Py_RunMain`. This | ||
| 124 | + function became useless. | ||
| 124 | 125 | ||
| 125 | - An exit code can be set when parsing the command line failed (exit | ||
| 126 | - code ``2``) or when a command line option asks to display the command | ||
| 127 | - line help (exit code ``0``). | ||
| 126 | + .. deprecated:: next | ||
| 128 | 127 | ||
| 129 | 128 | ||
| 130 | 129 | Get Options | |
@@ -247,10 +246,10 @@ Initialize Python | |||
| 247 | 246 | ||
| 248 | 247 | * Return ``0`` on success. | |
| 249 | 248 | * Set an error in *config* and return ``-1`` on error. | |
| 250 | - * Set an exit code in *config* and return ``-1`` if Python wants to | ||
| 251 | - exit. | ||
| 252 | 249 | ||
| 253 | - See ``PyInitConfig_GetExitcode()`` for the exit code case. | ||
| 250 | + .. versionchanged:: next | ||
| 251 | + The function no longer sets an exit code if a command line option wants | ||
| 252 | + to exit Python. Instead, the option is processed in :c:func:`Py_RunMain`. | ||
| 254 | 253 | ||
| 255 | 254 | ||
| 256 | 255 | .. _pyinitconfig-opts: | |
@@ -690,9 +689,6 @@ Example of customized Python always running in isolated mode:: | |||
| 690 | 689 | ||
| 691 | 690 | exception: | |
| 692 | 691 | PyConfig_Clear(&config); | |
| 693 | - if (PyStatus_IsExit(status)) { | ||
| 694 | - return status.exitcode; | ||
| 695 | - } | ||
| 696 | 692 | /* Display the error message and exit the process with | |
| 697 | 693 | non-zero exit code */ | |
| 698 | 694 | Py_ExitStatusException(status); | |
@@ -758,6 +754,8 @@ PyStatus | |||
| 758 | 754 | ||
| 759 | 755 | Exit code. Argument passed to ``exit()``. | |
| 760 | 756 | ||
| 757 | + .. deprecated:: next | ||
| 758 | + | ||
| 761 | 759 | .. c:member:: const char *err_msg | |
| 762 | 760 | ||
| 763 | 761 | Error message. | |
@@ -788,6 +786,11 @@ PyStatus | |||
| 788 | 786 | ||
| 789 | 787 | Exit Python with the specified exit code. | |
| 790 | 788 | ||
| 789 | + .. deprecated:: next | ||
| 790 | + :c:func:`Py_InitializeFromInitConfig` no longer sets an exit code if a | ||
| 791 | + command line option wants to exit Python. Instead, the option is | ||
| 792 | + processed in :c:func:`Py_RunMain`. | ||
| 793 | + | ||
| 791 | 794 | Functions to handle a status: | |
| 792 | 795 | ||
| 793 | 796 | .. c:function:: int PyStatus_Exception(PyStatus status) | |
@@ -803,6 +806,11 @@ PyStatus | |||
| 803 | 806 | ||
| 804 | 807 | Is the result an exit? | |
| 805 | 808 | ||
| 809 | + .. deprecated:: next | ||
| 810 | + :c:func:`Py_InitializeFromInitConfig` no longer sets an exit code if a | ||
| 811 | + command line option wants to exit Python. Instead, the option is | ||
| 812 | + processed in :c:func:`Py_RunMain`. | ||
| 813 | + | ||
| 806 | 814 | .. c:function:: void Py_ExitStatusException(PyStatus status) | |
| 807 | 815 | ||
| 808 | 816 | Call ``exit(exitcode)`` if *status* is an exit. Print the error | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -399,6 +399,11 @@ Initializing and finalizing the interpreter | |||
| 399 | 399 | interpreter, populating the runtime configuration structure, and querying | |
| 400 | 400 | the returned status structure. | |
| 401 | 401 | ||
| 402 | + .. versionchanged:: next | ||
| 403 | + The function no longer returns an exit code if a command line option | ||
| 404 | + wants to exit Python. Instead, the option is processed in | ||
| 405 | + :c:func:`Py_RunMain`. | ||
| 406 | + | ||
| 402 | 407 | ||
| 403 | 408 | .. c:function:: int Py_IsInitialized() | |
| 404 | 409 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1128,6 +1128,14 @@ Deprecated C APIs | |||
| 1128 | 1128 | and :c:func:`PyAsyncGen_New` are deprecated. | |
| 1129 | 1129 | They are scheduled for removal in 3.18. | |
| 1130 | 1130 | ||
| 1131 | + * Deprecate :c:func:`PyInitConfig_GetExitCode`, :c:func:`PyStatus_Exit`, | ||
| 1132 | + and :c:func:`PyStatus_IsExit` functions, and :c:member:`PyStatus.exitcode` | ||
| 1133 | + member. :c:func:`Py_InitializeFromInitConfig` and | ||
| 1134 | + :c:func:`Py_InitializeFromConfig` can no longer return an exit code. | ||
| 1135 | + Instead, if a command line option wants to exit Python, the option is | ||
| 1136 | + processed in :c:func:`Py_RunMain`. | ||
| 1137 | + (Contributed by Victor Stinner in :gh:`158080`.) | ||
| 1138 | + | ||
| 1131 | 1139 | .. Add C API deprecations above alphabetically, not here at the end. | |
| 1132 | 1140 | ||
| 1133 | 1141 | .. include:: ../deprecations/c-api-pending-removal-in-3.18.rst | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,19 +11,19 @@ typedef struct { | |||
| 11 | 11 | enum { | |
| 12 | 12 | _PyStatus_TYPE_OK=0, | |
| 13 | 13 | _PyStatus_TYPE_ERROR=1, | |
| 14 | - _PyStatus_TYPE_EXIT=2 | ||
| 14 | + _PyStatus_TYPE_EXIT=2 // deprecated | ||
| 15 | 15 | } _type; | |
| 16 | 16 | const char *func; | |
| 17 | 17 | const char *err_msg; | |
| 18 | - int exitcode; | ||
| 18 | + Py_DEPRECATED(3.16) int exitcode; | ||
| 19 | 19 | } PyStatus; | |
| 20 | 20 | ||
| 21 | 21 | PyAPI_FUNC(PyStatus) PyStatus_Ok(void); | |
| 22 | 22 | PyAPI_FUNC(PyStatus) PyStatus_Error(const char *err_msg); | |
| 23 | 23 | PyAPI_FUNC(PyStatus) PyStatus_NoMemory(void); | |
| 24 | - PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode); | ||
| 24 | + Py_DEPRECATED(3.16) PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode); | ||
| 25 | 25 | PyAPI_FUNC(int) PyStatus_IsError(PyStatus err); | |
| 26 | - PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err); | ||
| 26 | + Py_DEPRECATED(3.16) PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err); | ||
| 27 | 27 | PyAPI_FUNC(int) PyStatus_Exception(PyStatus err); | |
| 28 | 28 | ||
| 29 | 29 | /* --- PyWideStringList ------------------------------------------------ */ | |
@@ -242,6 +242,11 @@ typedef struct PyConfig { | |||
| 242 | 242 | // PYTHON_PRESITE=package.module or -X presite=package.module | |
| 243 | 243 | wchar_t *run_presite; | |
| 244 | 244 | #endif | |
| 245 | + | ||
| 246 | + // If a command line option wants to exit Python, store it in this member | ||
| 247 | + // and only process the option in Py_RunMain() instead of PyConfig_Read(). | ||
| 248 | + // If equals to -1, there is no option. | ||
| 249 | + int _deferred_cmdline_option; | ||
| 245 | 250 | } PyConfig; | |
| 246 | 251 | ||
| 247 | 252 | PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config); | |
@@ -293,7 +298,7 @@ PyAPI_FUNC(void) PyInitConfig_Free(PyInitConfig *config); | |||
| 293 | 298 | ||
| 294 | 299 | PyAPI_FUNC(int) PyInitConfig_GetError(PyInitConfig* config, | |
| 295 | 300 | const char **err_msg); | |
| 296 | - PyAPI_FUNC(int) PyInitConfig_GetExitCode(PyInitConfig* config, | ||
| 301 | + Py_DEPRECATED(3.16) PyAPI_FUNC(int) PyInitConfig_GetExitCode(PyInitConfig* config, | ||
| 297 | 302 | int *exitcode); | |
| 298 | 303 | ||
| 299 | 304 | PyAPI_FUNC(int) PyInitConfig_HasOption(PyInitConfig *config, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,6 +182,8 @@ extern PyObject* _PyConfig_CreateXOptionsDict(const PyConfig *config); | |||
| 182 | 182 | ||
| 183 | 183 | extern void _Py_DumpPathConfig(PyThreadState *tstate); | |
| 184 | 184 | ||
| 185 | + extern int _PyConfig_ProcessDeferredCmdlineOption(PyConfig *config); | ||
| 186 | + | ||
| 185 | 187 | ||
| 186 | 188 | /* --- Function used for testing ---------------------------------- */ | |
| 187 | 189 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + Deprecate :c:func:`PyInitConfig_GetExitCode`, :c:func:`PyStatus_Exit`, and | ||
| 2 | + :c:func:`PyStatus_IsExit` functions, and :c:member:`PyStatus.exitcode` | ||
| 3 | + member. :c:func:`Py_InitializeFromInitConfig` and | ||
| 4 | + :c:func:`Py_InitializeFromConfig` can no longer return an exit code. | ||
| 5 | + Instead, if a command line option wants to exit Python, the option is | ||
| 6 | + processed in :c:func:`Py_RunMain`. Patch by Victor Stinner. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -749,13 +749,21 @@ pymain_set_path0(PyObject *main_importer_path) | |||
| 749 | 749 | static void | |
| 750 | 750 | pymain_run_python(int *exitcode) | |
| 751 | 751 | { | |
| 752 | - int set_running_main = 0; | ||
| 753 | - | ||
| 754 | - PyObject *main_importer_path = NULL; | ||
| 755 | 752 | PyInterpreterState *interp = _PyInterpreterState_GET(); | |
| 756 | 753 | /* pymain_repl() and pymain_run_stdin() modify the config */ | |
| 757 | 754 | PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(interp); | |
| 758 | 755 | ||
| 756 | + // Process command line options which want to exit Python | ||
| 757 | + int cmdline_exitcode = _PyConfig_ProcessDeferredCmdlineOption(config); | ||
| 758 | + if (cmdline_exitcode >= 0) { | ||
| 759 | + *exitcode = cmdline_exitcode; | ||
| 760 | + return; | ||
| 761 | + } | ||
| 762 | + | ||
| 763 | + int set_running_main = 0; | ||
| 764 | + | ||
| 765 | + PyObject *main_importer_path = NULL; | ||
| 766 | + | ||
| 759 | 767 | /* ensure path config is written into global variables */ | |
| 760 | 768 | PyStatus status = _PyPathConfig_UpdateGlobal(config); | |
| 761 | 769 | if (_PyStatus_EXCEPTION(status)) { | |
@@ -910,10 +918,7 @@ static int | |||
| 910 | 918 | pymain_main(_PyArgv *args) | |
| 911 | 919 | { | |
| 912 | 920 | PyStatus status = pymain_init(args); | |
| 913 | - if (_PyStatus_IS_EXIT(status)) { | ||
| 914 | - pymain_free(); | ||
| 915 | - return status.exitcode; | ||
| 916 | - } | ||
| 921 | + assert(!_PyStatus_IS_EXIT(status)); | ||
| 917 | 922 | if (_PyStatus_EXCEPTION(status)) { | |
| 918 | 923 | pymain_exit_error(status); | |
| 919 | 924 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,9 +104,6 @@ main(int argc, char **argv) | |||
| 104 | 104 | ||
| 105 | 105 | error: | |
| 106 | 106 | PyConfig_Clear(&config); | |
| 107 | - if (PyStatus_IsExit(status)) { | ||
| 108 | - return status.exitcode; | ||
| 109 | - } | ||
| 110 | 107 | Py_ExitStatusException(status); | |
| 111 | 108 | } | |
| 112 | 109 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,10 +41,10 @@ static const wchar_t *opt_ptr = L""; | |||
| 41 | 41 | ||
| 42 | 42 | static const _PyOS_LongOption longopts[] = { | |
| 43 | 43 | /* name, has_arg, val (used in switch in initconfig.c) */ | |
| 44 | - {L"check-hash-based-pycs", 1, 0}, | ||
| 45 | - {L"help-all", 0, 1}, | ||
| 46 | - {L"help-env", 0, 2}, | ||
| 47 | - {L"help-xoptions", 0, 3}, | ||
| 44 | + {L"check-hash-based-pycs", 1, 1}, | ||
| 45 | + {L"help-all", 0, 2}, | ||
| 46 | + {L"help-env", 0, 3}, | ||
| 47 | + {L"help-xoptions", 0, 4}, | ||
| 48 | 48 | {NULL, 0, -1}, /* sentinel */ | |
| 49 | 49 | }; | |
| 50 | 50 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments