bpo-42260: Fix _PyConfig_Read() if compute_path_config=0 (GH-23220)

Fix _PyConfig_Read() if compute_path_config=0: use values set by
Py_SetPath(), Py_SetPythonHome() and Py_SetProgramName(). Add
compute_path_config parameter to _PyConfig_InitPathConfig().

The following functions now return NULL if called before
Py_Initialize():

* Py_GetExecPrefix()
* Py_GetPath()
* Py_GetPrefix()
* Py_GetProgramFullPath()
* Py_GetProgramName()
* Py_GetPythonHome()

These functions no longer automatically computes the Python Path
Configuration. Moreover, Py_SetPath() no longer computes
program_full_path.
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 3d18bb3..5736b83 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -376,6 +376,12 @@
    The returned string points into static storage; the caller should not modify its
    value.
 
+   This function should not be called before :c:func:`Py_Initialize`, otherwise
+   it returns ``NULL``.
+
+   .. versionchanged:: 3.10
+      It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
+
 
 .. c:function:: wchar_t* Py_GetPrefix()
 
@@ -389,6 +395,12 @@
    script at build time.  The value is available to Python code as ``sys.prefix``.
    It is only useful on Unix.  See also the next function.
 
+   This function should not be called before :c:func:`Py_Initialize`, otherwise
+   it returns ``NULL``.
+
+   .. versionchanged:: 3.10
+      It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
+
 
 .. c:function:: wchar_t* Py_GetExecPrefix()
 
@@ -424,6 +436,12 @@
    while having :file:`/usr/local/plat` be a different filesystem for each
    platform.
 
+   This function should not be called before :c:func:`Py_Initialize`, otherwise
+   it returns ``NULL``.
+
+   .. versionchanged:: 3.10
+      It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
+
 
 .. c:function:: wchar_t* Py_GetProgramFullPath()
 
@@ -437,6 +455,12 @@
    static storage; the caller should not modify its value.  The value is available
    to Python code as ``sys.executable``.
 
+   This function should not be called before :c:func:`Py_Initialize`, otherwise
+   it returns ``NULL``.
+
+   .. versionchanged:: 3.10
+      It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
+
 
 .. c:function:: wchar_t* Py_GetPath()
 
@@ -455,8 +479,14 @@
    can be (and usually is) modified later to change the search path for loading
    modules.
 
+   This function should not be called before :c:func:`Py_Initialize`, otherwise
+   it returns ``NULL``.
+
    .. XXX should give the exact rules
 
+   .. versionchanged:: 3.10
+      It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
+
 
 .. c:function::  void Py_SetPath(const wchar_t *)
 
@@ -638,6 +668,12 @@
    :c:func:`Py_SetPythonHome`, or the value of the :envvar:`PYTHONHOME`
    environment variable if it is set.
 
+   This function should not be called before :c:func:`Py_Initialize`, otherwise
+   it returns ``NULL``.
+
+   .. versionchanged:: 3.10
+      It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
+
 
 .. _threads:
 
diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst
index edfeba5..db7c1f4 100644
--- a/Doc/c-api/init_config.rst
+++ b/Doc/c-api/init_config.rst
@@ -24,11 +24,15 @@
   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
 =======
 
@@ -532,7 +536,7 @@
 
       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
 
@@ -544,7 +548,7 @@
 
       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
 
@@ -552,7 +556,7 @@
 
       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
 
@@ -634,7 +638,7 @@
 
       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
 
@@ -643,7 +647,7 @@
 
       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
 
@@ -726,7 +730,7 @@
 
       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
 
@@ -817,7 +821,7 @@
       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
 
@@ -830,7 +834,7 @@
 
       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
@@ -838,14 +842,14 @@
       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
 
@@ -911,7 +915,7 @@
 
    .. 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.
 
@@ -919,7 +923,7 @@
 
       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
 
@@ -928,7 +932,7 @@
 
       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
 
@@ -946,7 +950,7 @@
 
       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
 
@@ -1262,7 +1266,7 @@
 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.
 
@@ -1287,8 +1291,8 @@
 
 .. _init-path-config:
 
-Path Configuration
-==================
+Python Path Configuration
+=========================
 
 :c:type:`PyConfig` contains multiple fields for the path configuration:
 
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 95cdb06..76e11f0 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -493,6 +493,14 @@
   ``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
 ----------