PEP 741: Add PyInitConfig_GetExitcode() function (#3718)
This commit is contained in:
parent
b69e2daa81
commit
a8cc9106bc
|
@ -114,7 +114,7 @@ configure Python, there is no public API to get
|
|||
Users of the limited C API are asking for a public API to get the
|
||||
current runtime configuration.
|
||||
|
||||
Cython needs to access the ``optimization_level`` configuration option:
|
||||
Cython needs to get the ``optimization_level`` configuration option:
|
||||
`issue <https://github.com/python/cpython/issues/99872>`_.
|
||||
|
||||
When global configuration variables were deprecated in 2022, `Marc-André
|
||||
|
@ -331,6 +331,18 @@ a C API to **set** the value of some configuration options at runtime:
|
|||
* ``inspect``
|
||||
* ``write_bytecode``
|
||||
|
||||
Previously, it was possible to set directly global configuration
|
||||
variables:
|
||||
|
||||
* ``Py_OptimizeFlag``
|
||||
* ``Py_VerboseFlag``
|
||||
* ``Py_DebugFlag``
|
||||
* ``Py_InspectFlag``
|
||||
* ``Py_DontWriteBytecodeFlag``
|
||||
|
||||
But these configuration flags were deprecated in Python 3.12 and are
|
||||
scheduled for removal in Python 3.14.
|
||||
|
||||
|
||||
Specification
|
||||
=============
|
||||
|
@ -375,6 +387,7 @@ initialization:
|
|||
* Error handling:
|
||||
|
||||
* ``PyInitConfig_GetError(config, &err_msg)``.
|
||||
* ``PyInitConfig_GetExitcode(config, &exitcode)``.
|
||||
|
||||
Add C API functions to get and set the current runtime configuration:
|
||||
|
||||
|
@ -890,6 +903,10 @@ Initialize Python
|
|||
|
||||
* Return ``0`` on success.
|
||||
* Set an error in *config* and return ``-1`` on error.
|
||||
* Set an exit code in *config* and return ``-1`` if Python wants to
|
||||
exit.
|
||||
|
||||
See ``PyInitConfig_GetExitcode()`` for the exitcode case.
|
||||
|
||||
|
||||
Error Handling
|
||||
|
@ -903,10 +920,28 @@ Error Handling
|
|||
|
||||
An error message is an UTF-8 encoded string.
|
||||
|
||||
If *config* has an exit code, format the exit code as an error
|
||||
message.
|
||||
|
||||
The error message remains valid until another ``PyInitConfig``
|
||||
function is called with *config*. The caller doesn't have to free the
|
||||
error message.
|
||||
|
||||
``int PyInitConfig_GetExitcode(PyInitConfig* config, int *exitcode)``:
|
||||
Get the *config* exit code.
|
||||
|
||||
* Set *\*exitcode* and return ``1`` if Python wants to exit.
|
||||
* Return ``0`` if *config* has no exit code set.
|
||||
|
||||
Only the ``Py_InitializeFromInitConfig()`` function can set an exit
|
||||
code if the ``parse_argv`` option is non-zero. For example, an
|
||||
isolated configuration cannot set an exit code by default, since
|
||||
``parse_argv`` is zero by default.
|
||||
|
||||
An exit code can be set when parsing the command line failed (exit
|
||||
code 2) or when a command line option asks to display the command
|
||||
line help (exit code 0).
|
||||
|
||||
|
||||
Get and Set the Runtime Configuration
|
||||
-------------------------------------
|
||||
|
|
Loading…
Reference in New Issue