diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-04 23:45:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 23:45:56 (GMT) |
commit | 048a35659aa8074afe7d7d054e7cea1f8ee6d366 (patch) | |
tree | e9a019387bbd73cdbfcdceb76af7d21e15bc30d0 /Python/initconfig.c | |
parent | 100964e0310d3a2040d0db976f7984d0507b2dbd (diff) | |
download | cpython-048a35659aa8074afe7d7d054e7cea1f8ee6d366.zip cpython-048a35659aa8074afe7d7d054e7cea1f8ee6d366.tar.gz cpython-048a35659aa8074afe7d7d054e7cea1f8ee6d366.tar.bz2 |
bpo-42260: Add _PyInterpreterState_SetConfig() (GH-23158)
* Inline _PyInterpreterState_SetConfig(): replace it with
_PyConfig_Copy().
* Add _PyErr_SetFromPyStatus()
* Add _PyInterpreterState_GetConfigCopy()
* Add a new _PyInterpreterState_SetConfig() function.
* Add an unit which gets, modifies, and sets the config.
Diffstat (limited to 'Python/initconfig.c')
-rw-r--r-- | Python/initconfig.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Python/initconfig.c b/Python/initconfig.c index 15fb3e4..de496ac 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -242,8 +242,9 @@ PyStatus PyStatus_Ok(void) PyStatus PyStatus_Error(const char *err_msg) { + assert(err_msg != NULL); return (PyStatus){._type = _PyStatus_TYPE_ERROR, - .err_msg = err_msg}; + .err_msg = err_msg}; } PyStatus PyStatus_NoMemory(void) @@ -262,6 +263,23 @@ int PyStatus_IsExit(PyStatus status) int PyStatus_Exception(PyStatus status) { return _PyStatus_EXCEPTION(status); } +PyObject* +_PyErr_SetFromPyStatus(PyStatus status) +{ + if (!_PyStatus_IS_ERROR(status)) { + PyErr_Format(PyExc_SystemError, + "%s() expects an error PyStatus", + _PyStatus_GET_FUNC()); + } + else if (status.func) { + PyErr_Format(PyExc_ValueError, "%s: %s", status.func, status.err_msg); + } + else { + PyErr_Format(PyExc_ValueError, "%s", status.err_msg); + } + return NULL; +} + /* --- PyWideStringList ------------------------------------------------ */ |