bpo-36763: Implement the PEP 587 (GH-13592)

* Add a whole new documentation page:
  "Python Initialization Configuration"
* PyWideStringList_Append() return type is now PyStatus,
  instead of int
* PyInterpreterState_New() now calls PyConfig_Clear() if
  PyConfig_InitPythonConfig() fails.
* Rename files:

  * Python/coreconfig.c => Python/initconfig.c
  * Include/cpython/coreconfig.h => Include/cpython/initconfig.h
  * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h

* Rename structures

  * _PyCoreConfig => PyConfig
  * _PyPreConfig => PyPreConfig
  * _PyInitError => PyStatus
  * _PyWstrList => PyWideStringList

* Rename PyConfig fields:

  * use_module_search_paths => module_search_paths_set
  * module_search_path_env => pythonpath_env

* Rename PyStatus field: _func => func
* PyInterpreterState: rename core_config field to config
* Rename macros and functions:

  * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv()
  * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv()
  * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString()
  * _PyInitError_Failed() => PyStatus_Exception()
  * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx
  * _Py_UnixMain() => Py_BytesMain()
  * _Py_ExitInitError() => Py_ExitStatusException()
  * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs()
  * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs()
  * _Py_PreInitialize() => Py_PreInitialize()
  * _Py_RunMain() => Py_RunMain()
  * _Py_InitializeFromConfig() => Py_InitializeFromConfig()
  * _Py_INIT_XXX() => _PyStatus_XXX()
  * _Py_INIT_FAILED() => _PyStatus_EXCEPTION()

* Rename 'err' PyStatus variables to 'status'
* Convert RUN_CODE() macro to config_run_code() static inline function
* Remove functions:

  * _Py_InitializeFromArgs()
  * _Py_InitializeFromWideArgs()
  * _PyInterpreterState_GetCoreConfig()
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 8d5ba54..c7c2831 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -999,7 +999,7 @@
 static PyObject *
 bytearray_str(PyObject *op)
 {
-    _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
+    PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
     if (config->bytes_warning) {
         if (PyErr_WarnEx(PyExc_BytesWarning,
                          "str() on a bytearray instance", 1)) {
@@ -1025,7 +1025,7 @@
     if (rc < 0)
         return NULL;
     if (rc) {
-        _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
+        PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
         if (config->bytes_warning && (op == Py_EQ || op == Py_NE)) {
             if (PyErr_WarnEx(PyExc_BytesWarning,
                             "Comparison between bytearray and string", 1))
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 41453b2..0a3ed86 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1421,7 +1421,7 @@
 static PyObject *
 bytes_str(PyObject *op)
 {
-    _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
+    PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
     if (config->bytes_warning) {
         if (PyErr_WarnEx(PyExc_BytesWarning,
                          "str() on a bytes instance", 1)) {
@@ -1579,7 +1579,7 @@
 
     /* Make sure both arguments are strings. */
     if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
-        _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
+        PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
         if (config->bytes_warning && (op == Py_EQ || op == Py_NE)) {
             rc = PyObject_IsInstance((PyObject*)a,
                                      (PyObject*)&PyUnicode_Type);
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 4dad0b2..8456a8f 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -6,7 +6,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include <Python.h>
-#include "pycore_coreconfig.h"
+#include "pycore_initconfig.h"
 #include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
@@ -2499,13 +2499,13 @@
 #endif
 #endif /* MS_WINDOWS */
 
-_PyInitError
+PyStatus
 _PyExc_Init(void)
 {
 #define PRE_INIT(TYPE) \
     if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
         if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \
-            return _Py_INIT_ERR("exceptions bootstrapping error."); \
+            return _PyStatus_ERR("exceptions bootstrapping error."); \
         } \
         Py_INCREF(PyExc_ ## TYPE); \
     }
@@ -2515,7 +2515,7 @@
         PyObject *_code = PyLong_FromLong(CODE); \
         assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \
         if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) \
-            return _Py_INIT_ERR("errmap insertion problem."); \
+            return _PyStatus_ERR("errmap insertion problem."); \
         Py_DECREF(_code); \
     } while (0)
 
@@ -2589,14 +2589,14 @@
     PRE_INIT(TimeoutError);
 
     if (preallocate_memerrors() < 0) {
-        return _Py_INIT_ERR("Could not preallocate MemoryError object");
+        return _PyStatus_ERR("Could not preallocate MemoryError object");
     }
 
     /* Add exceptions to errnomap */
     if (!errnomap) {
         errnomap = PyDict_New();
         if (!errnomap) {
-            return _Py_INIT_ERR("Cannot allocate map from errnos to OSError subclasses");
+            return _PyStatus_ERR("Cannot allocate map from errnos to OSError subclasses");
         }
     }
 
@@ -2622,7 +2622,7 @@
     ADD_ERRNO(ProcessLookupError, ESRCH);
     ADD_ERRNO(TimeoutError, ETIMEDOUT);
 
-    return _Py_INIT_OK();
+    return _PyStatus_OK();
 
 #undef PRE_INIT
 #undef ADD_ERRNO
@@ -2630,12 +2630,12 @@
 
 
 /* Add exception types to the builtins module */
-_PyInitError
+PyStatus
 _PyBuiltins_AddExceptions(PyObject *bltinmod)
 {
 #define POST_INIT(TYPE) \
     if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \
-        return _Py_INIT_ERR("Module dictionary insertion problem."); \
+        return _PyStatus_ERR("Module dictionary insertion problem."); \
     }
 
 #define INIT_ALIAS(NAME, TYPE) \
@@ -2644,7 +2644,7 @@
         Py_XDECREF(PyExc_ ## NAME); \
         PyExc_ ## NAME = PyExc_ ## TYPE; \
         if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \
-            return _Py_INIT_ERR("Module dictionary insertion problem."); \
+            return _PyStatus_ERR("Module dictionary insertion problem."); \
         } \
     } while (0)
 
@@ -2652,7 +2652,7 @@
 
     bdict = PyModule_GetDict(bltinmod);
     if (bdict == NULL) {
-        return _Py_INIT_ERR("exceptions bootstrapping error.");
+        return _PyStatus_ERR("exceptions bootstrapping error.");
     }
 
     POST_INIT(BaseException);
@@ -2729,7 +2729,7 @@
     POST_INIT(ProcessLookupError);
     POST_INIT(TimeoutError);
 
-    return _Py_INIT_OK();
+    return _PyStatus_OK();
 
 #undef POST_INIT
 #undef INIT_ALIAS
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 3185957..b210c00 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -104,7 +104,7 @@
 show_alloc(void)
 {
     PyInterpreterState *interp = _PyInterpreterState_Get();
-    if (!interp->core_config.show_alloc_count) {
+    if (!interp->config.show_alloc_count) {
         return;
     }
 
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index e570107c..20e7d44 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -590,7 +590,7 @@
     Py_ssize_t pos;
     PyObject *key, *value;
 
-    int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
+    int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
 
     /* First, clear only names starting with a single underscore */
     pos = 0;
@@ -677,7 +677,7 @@
 static void
 module_dealloc(PyModuleObject *m)
 {
-    int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
+    int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
 
     PyObject_GC_UnTrack(m);
     if (verbose && m->md_name) {
diff --git a/Objects/object.c b/Objects/object.c
index 6d79165..270716f 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -2,7 +2,7 @@
 /* Generic object operations; and implementation of None */
 
 #include "Python.h"
-#include "pycore_coreconfig.h"
+#include "pycore_initconfig.h"
 #include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "pycore_context.h"
@@ -124,7 +124,7 @@
 _Py_dump_counts(FILE* f)
 {
     PyInterpreterState *interp = _PyInterpreterState_Get();
-    if (!interp->core_config.show_alloc_count) {
+    if (!interp->config.show_alloc_count) {
         return;
     }
 
@@ -1767,13 +1767,13 @@
     1, &_PyNotImplemented_Type
 };
 
-_PyInitError
+PyStatus
 _PyTypes_Init(void)
 {
 #define INIT_TYPE(TYPE, NAME) \
     do { \
         if (PyType_Ready(TYPE) < 0) { \
-            return _Py_INIT_ERR("Can't initialize " NAME " type"); \
+            return _PyStatus_ERR("Can't initialize " NAME " type"); \
         } \
     } while (0)
 
@@ -1843,7 +1843,7 @@
     INIT_TYPE(&PyCoro_Type, "coroutine");
     INIT_TYPE(&_PyCoroWrapper_Type, "coroutine wrapper");
     INIT_TYPE(&_PyInterpreterID_Type, "interpreter ID");
-    return _Py_INIT_OK();
+    return _PyStatus_OK();
 
 #undef INIT_TYPE
 }
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index dc1d0e5..72556ad 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -46,7 +46,7 @@
 show_track(void)
 {
     PyInterpreterState *interp = _PyInterpreterState_Get();
-    if (!interp->core_config.show_alloc_count) {
+    if (!interp->config.show_alloc_count) {
         return;
     }
 
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 0aa5e4a..0fe7b56 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -40,7 +40,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
-#include "pycore_coreconfig.h"
+#include "pycore_initconfig.h"
 #include "pycore_fileutils.h"
 #include "pycore_object.h"
 #include "pycore_pylifecycle.h"
@@ -3549,9 +3549,9 @@
                                    interp->fs_codec.errors);
     }
     else {
-        const _PyCoreConfig *config = &interp->core_config;
+        const wchar_t *filesystem_errors = interp->config.filesystem_errors;
         _Py_error_handler errors;
-        errors = get_error_handler_wide(config->filesystem_errors);
+        errors = get_error_handler_wide(filesystem_errors);
         assert(errors != _Py_ERROR_UNKNOWN);
         return unicode_encode_utf8(unicode, errors, NULL);
     }
@@ -3567,9 +3567,9 @@
                                          interp->fs_codec.errors);
     }
     else {
-        const _PyCoreConfig *config = &interp->core_config;
+        const wchar_t *filesystem_errors = interp->config.filesystem_errors;
         _Py_error_handler errors;
-        errors = get_error_handler_wide(config->filesystem_errors);
+        errors = get_error_handler_wide(filesystem_errors);
         assert(errors != _Py_ERROR_UNKNOWN);
         return unicode_encode_locale(unicode, errors, 0);
     }
@@ -3787,9 +3787,9 @@
                                    NULL);
     }
     else {
-        const _PyCoreConfig *config = &interp->core_config;
+        const wchar_t *filesystem_errors = interp->config.filesystem_errors;
         _Py_error_handler errors;
-        errors = get_error_handler_wide(config->filesystem_errors);
+        errors = get_error_handler_wide(filesystem_errors);
         assert(errors != _Py_ERROR_UNKNOWN);
         return unicode_decode_utf8(s, size, errors, NULL, NULL);
     }
@@ -3805,9 +3805,9 @@
                                 interp->fs_codec.errors);
     }
     else {
-        const _PyCoreConfig *config = &interp->core_config;
+        const wchar_t *filesystem_errors = interp->config.filesystem_errors;
         _Py_error_handler errors;
-        errors = get_error_handler_wide(config->filesystem_errors);
+        errors = get_error_handler_wide(filesystem_errors);
         return unicode_decode_locale(s, size, errors, 0);
     }
 #endif
@@ -15200,7 +15200,7 @@
 
 /* Initialize the Unicode implementation */
 
-_PyInitError
+PyStatus
 _PyUnicode_Init(void)
 {
     /* XXX - move this array to unicodectype.c ? */
@@ -15218,12 +15218,12 @@
     /* Init the implementation */
     _Py_INCREF_UNICODE_EMPTY();
     if (!unicode_empty) {
-        return _Py_INIT_ERR("Can't create empty string");
+        return _PyStatus_ERR("Can't create empty string");
     }
     Py_DECREF(unicode_empty);
 
     if (PyType_Ready(&PyUnicode_Type) < 0) {
-        return _Py_INIT_ERR("Can't initialize unicode type");
+        return _PyStatus_ERR("Can't initialize unicode type");
     }
 
     /* initialize the linebreak bloom filter */
@@ -15232,15 +15232,15 @@
         Py_ARRAY_LENGTH(linebreak));
 
     if (PyType_Ready(&EncodingMapType) < 0) {
-         return _Py_INIT_ERR("Can't initialize encoding map type");
+         return _PyStatus_ERR("Can't initialize encoding map type");
     }
     if (PyType_Ready(&PyFieldNameIter_Type) < 0) {
-        return _Py_INIT_ERR("Can't initialize field name iterator type");
+        return _PyStatus_ERR("Can't initialize field name iterator type");
     }
     if (PyType_Ready(&PyFormatterIter_Type) < 0) {
-        return _Py_INIT_ERR("Can't initialize formatter iter type");
+        return _PyStatus_ERR("Can't initialize formatter iter type");
     }
-    return _Py_INIT_OK();
+    return _PyStatus_OK();
 }
 
 /* Finalize the Unicode implementation */
@@ -15718,23 +15718,23 @@
 }
 
 
-static _PyInitError
+static PyStatus
 init_stdio_encoding(PyInterpreterState *interp)
 {
     /* Update the stdio encoding to the normalized Python codec name. */
-    _PyCoreConfig *config = &interp->core_config;
+    PyConfig *config = &interp->config;
     if (config_get_codec_name(&config->stdio_encoding) < 0) {
-        return _Py_INIT_ERR("failed to get the Python codec name "
+        return _PyStatus_ERR("failed to get the Python codec name "
                             "of the stdio encoding");
     }
-    return _Py_INIT_OK();
+    return _PyStatus_OK();
 }
 
 
 static int
 init_fs_codec(PyInterpreterState *interp)
 {
-    _PyCoreConfig *config = &interp->core_config;
+    PyConfig *config = &interp->config;
 
     _Py_error_handler error_handler;
     error_handler = get_error_handler_wide(config->filesystem_errors);
@@ -15778,31 +15778,31 @@
 }
 
 
-static _PyInitError
+static PyStatus
 init_fs_encoding(PyInterpreterState *interp)
 {
     /* Update the filesystem encoding to the normalized Python codec name.
        For example, replace "ANSI_X3.4-1968" (locale encoding) with "ascii"
        (Python codec name). */
-    _PyCoreConfig *config = &interp->core_config;
+    PyConfig *config = &interp->config;
     if (config_get_codec_name(&config->filesystem_encoding) < 0) {
-        return _Py_INIT_ERR("failed to get the Python codec "
+        return _PyStatus_ERR("failed to get the Python codec "
                             "of the filesystem encoding");
     }
 
     if (init_fs_codec(interp) < 0) {
-        return _Py_INIT_ERR("cannot initialize filesystem codec");
+        return _PyStatus_ERR("cannot initialize filesystem codec");
     }
-    return _Py_INIT_OK();
+    return _PyStatus_OK();
 }
 
 
-_PyInitError
+PyStatus
 _PyUnicode_InitEncodings(PyInterpreterState *interp)
 {
-    _PyInitError err = init_fs_encoding(interp);
-    if (_Py_INIT_FAILED(err)) {
-        return err;
+    PyStatus status = init_fs_encoding(interp);
+    if (_PyStatus_EXCEPTION(status)) {
+        return status;
     }
 
     return init_stdio_encoding(interp);
@@ -15814,7 +15814,7 @@
 _PyUnicode_EnableLegacyWindowsFSEncoding(void)
 {
     PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
-    _PyCoreConfig *config = &interp->core_config;
+    PyConfig *config = &interp->config;
 
     /* Set the filesystem encoding to mbcs/replace (PEP 529) */
     wchar_t *encoding = _PyMem_RawWcsdup(L"mbcs");