summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-27 14:39:22 (GMT)
committerGitHub <noreply@github.com>2019-05-27 14:39:22 (GMT)
commit331a6a56e9a9c72f3e4605987fabdaec72677702 (patch)
tree49d20cedd9df4371f2410b2fb24255535ca02c50 /Objects/unicodeobject.c
parent8cd5165ba05ff57cfdbbc71c393bddad1ce1ab87 (diff)
downloadcpython-331a6a56e9a9c72f3e4605987fabdaec72677702.zip
cpython-331a6a56e9a9c72f3e4605987fabdaec72677702.tar.gz
cpython-331a6a56e9a9c72f3e4605987fabdaec72677702.tar.bz2
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()
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c62
1 files changed, 31 insertions, 31 deletions
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 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#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 @@ PyUnicode_EncodeFSDefault(PyObject *unicode)
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 @@ PyUnicode_EncodeFSDefault(PyObject *unicode)
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 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
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 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
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 @@ PyTypeObject PyUnicode_Type = {
/* Initialize the Unicode implementation */
-_PyInitError
+PyStatus
_PyUnicode_Init(void)
{
/* XXX - move this array to unicodectype.c ? */
@@ -15218,12 +15218,12 @@ _PyUnicode_Init(void)
/* 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 @@ _PyUnicode_Init(void)
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 @@ error:
}
-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 @@ init_fs_codec(PyInterpreterState *interp)
}
-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 @@ int
_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");