bpo-42260: Fix _PyConfig_Read() if compute_path_config=0 by vstinner · Pull Request #23220 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Doc/c-api/init.rst
38 changes: 21 additions & 17 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ There are two kinds of configuration:
environments variables are ignored, the LC_CTYPE locale is left unchanged and
no signal handler is registred.

The :c:func:`Py_RunMain` function can be used to write a customized Python
program.

See also :ref:`Initialization, Finalization, and Threads <initialization>`.

.. seealso::
:pep:`587` "Python Initialization Configuration".


Example
=======

Expand Down Expand Up @@ -532,7 +536,7 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` output.
Part of the :ref:`Python Path Configuration <init-path-config>` output.

.. c:member:: wchar_t* base_executable

Expand All @@ -544,15 +548,15 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` output.
Part of the :ref:`Python Path Configuration <init-path-config>` output.

.. c:member:: wchar_t* base_prefix

:data:`sys.base_prefix`.

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` output.
Part of the :ref:`Python Path Configuration <init-path-config>` output.

.. c:member:: int buffered_stdio

Expand Down Expand Up @@ -634,7 +638,7 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` output.
Part of the :ref:`Python Path Configuration <init-path-config>` output.

.. c:member:: wchar_t* executable

Expand All @@ -643,7 +647,7 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` output.
Part of the :ref:`Python Path Configuration <init-path-config>` output.

.. c:member:: int faulthandler

Expand Down Expand Up @@ -726,7 +730,7 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` input.
Part of the :ref:`Python Path Configuration <init-path-config>` input.

.. c:member:: int import_time

Expand Down Expand Up @@ -817,7 +821,7 @@ PyConfig
Default: value of the ``PLATLIBDIR`` macro which is set at configure time
by ``--with-platlibdir`` (default: ``"lib"``).

Part of the :ref:`Path Configuration <init-path-config>` input.
Part of the :ref:`Python Path Configuration <init-path-config>` input.

.. versionadded:: 3.9

Expand All @@ -830,22 +834,22 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` input.
Part of the :ref:`Python Path Configuration <init-path-config>` input.

.. c:member:: PyWideStringList module_search_paths
.. c:member:: int module_search_paths_set

Module search paths: :data:`sys.path`.

If :c:member:`~PyConfig.module_search_paths_set` is equal to 0, the
function calculating the :ref:`Path Configuration <init-path-config>`
function calculating the :ref:`Python Path Configuration <init-path-config>`
overrides the :c:member:`~PyConfig.module_search_paths` and sets
:c:member:`~PyConfig.module_search_paths_set` to ``1``.

Default: empty list (``module_search_paths``) and ``0``
(``module_search_paths_set``).

Part of the :ref:`Path Configuration <init-path-config>` output.
Part of the :ref:`Python Path Configuration <init-path-config>` output.

.. c:member:: int optimization_level

Expand Down Expand Up @@ -911,15 +915,15 @@ PyConfig

.. c:member:: int pathconfig_warnings

On Unix, if non-zero, calculating the :ref:`Path Configuration
On Unix, if non-zero, calculating the :ref:`Python Path Configuration
<init-path-config>` can log warnings into ``stderr``. If equals to 0,
suppress these warnings.

It has no effect on Windows.

Default: ``1`` in Python mode, ``0`` in isolated mode.

Part of the :ref:`Path Configuration <init-path-config>` input.
Part of the :ref:`Python Path Configuration <init-path-config>` input.

.. c:member:: wchar_t* prefix

Expand All @@ -928,7 +932,7 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` output.
Part of the :ref:`Python Path Configuration <init-path-config>` output.

.. c:member:: wchar_t* program_name

Expand All @@ -946,7 +950,7 @@ PyConfig

Default: ``NULL``.

Part of the :ref:`Path Configuration <init-path-config>` input.
Part of the :ref:`Python Path Configuration <init-path-config>` input.

.. c:member:: wchar_t* pycache_prefix

Expand Down Expand Up @@ -1262,7 +1266,7 @@ and user site directory. The C standard streams (ex: ``stdout``) and the
LC_CTYPE locale are left unchanged. Signal handlers are not installed.

Configuration files are still used with this configuration. Set the
:ref:`Path Configuration <init-path-config>` ("output fields") to ignore these
:ref:`Python Path Configuration <init-path-config>` ("output fields") to ignore these
configuration files and avoid the function computing the default path
configuration.

Expand All @@ -1287,8 +1291,8 @@ and :ref:`Python UTF-8 Mode <utf8-mode>`

.. _init-path-config:

Path Configuration
==================
Python Path Configuration
=========================

:c:type:`PyConfig` contains multiple fields for the path configuration:

Expand Down
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ Porting to Python 3.10
``unicodedata.ucnhash_CAPI`` has been moved to the internal C API.
(Contributed by Victor Stinner in :issue:`42157`.)

* :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and
:c:func:`Py_GetProgramName` functions now return ``NULL`` if called before
:c:func:`Py_Initialize` (before Python is initialized). Use the new
:ref:`Python Initialization Configuration API <init-config>` to get the
:ref:`Python Path Configuration. <init-path-config>`.
(Contributed by Victor Stinner in :issue:`42260`.)

Deprecated
----------

Expand Down
4 changes: 3 additions & 1 deletion Include/internal/pycore_initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
extern PyStatus _PyConfig_Copy(
PyConfig *config,
const PyConfig *config2);
extern PyStatus _PyConfig_InitPathConfig(PyConfig *config);
extern PyStatus _PyConfig_InitPathConfig(
PyConfig *config,
int compute_path_config);
extern PyStatus _PyConfig_Read(PyConfig *config, int compute_path_config);
extern PyStatus _PyConfig_Write(const PyConfig *config,
struct pyruntimestate *runtime);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and
:c:func:`Py_GetProgramName` functions now return ``NULL`` if called before
:c:func:`Py_Initialize` (before Python is initialized). Use the new
:ref:`Python Initialization Configuration API <init-config>` to get the
:ref:`Python Path Configuration. <init-path-config>`. Patch by Victor
Stinner.
4 changes: 2 additions & 2 deletions Python/initconfig.c
Loading