summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-11-04 23:45:56 (GMT)
committerGitHub <noreply@github.com>2020-11-04 23:45:56 (GMT)
commit048a35659aa8074afe7d7d054e7cea1f8ee6d366 (patch)
treee9a019387bbd73cdbfcdceb76af7d21e15bc30d0 /Include
parent100964e0310d3a2040d0db976f7984d0507b2dbd (diff)
downloadcpython-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 'Include')
-rw-r--r--Include/cpython/pystate.h30
-rw-r--r--Include/internal/pycore_initconfig.h2
-rw-r--r--Include/internal/pycore_interp.h6
3 files changed, 32 insertions, 6 deletions
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index 25522b4..0e6cc29 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -193,6 +193,36 @@ PyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc(
PyAPI_FUNC(const PyConfig*) _PyInterpreterState_GetConfig(PyInterpreterState *interp);
+/* Get a copy of the current interpreter configuration.
+
+ Return 0 on success. Raise an exception and return -1 on error.
+
+ The caller must initialize 'config', using PyConfig_InitPythonConfig()
+ for example.
+
+ Python must be preinitialized to call this method.
+ The caller must hold the GIL. */
+PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
+ struct PyConfig *config);
+
+/* Set the configuration of the current interpreter.
+
+ This function should be called during or just after the Python
+ initialization.
+
+ Update the sys module with the new configuration. If the sys module was
+ modified directly after the Python initialization, these changes are lost.
+
+ Some configuration like faulthandler or warnoptions can be updated in the
+ configuration, but don't reconfigure Python (don't enable/disable
+ faulthandler and don't reconfigure warnings filters).
+
+ Return 0 on success. Raise an exception and return -1 on error.
+
+ The configuration should come from _PyInterpreterState_GetConfigCopy(). */
+PyAPI_FUNC(int) _PyInterpreterState_SetConfig(
+ const struct PyConfig *config);
+
// Get the configuration of the currrent interpreter.
// The caller must hold the GIL.
PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
diff --git a/Include/internal/pycore_initconfig.h b/Include/internal/pycore_initconfig.h
index 457a005..df7ad77 100644
--- a/Include/internal/pycore_initconfig.h
+++ b/Include/internal/pycore_initconfig.h
@@ -44,6 +44,8 @@ struct pyruntimestate;
#define _PyStatus_UPDATE_FUNC(err) \
do { err.func = _PyStatus_GET_FUNC(); } while (0)
+PyObject* _PyErr_SetFromPyStatus(PyStatus status);
+
/* --- PyWideStringList ------------------------------------------------ */
#define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}
diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h
index 9923b6b..4b67a86 100644
--- a/Include/internal/pycore_interp.h
+++ b/Include/internal/pycore_interp.h
@@ -263,13 +263,7 @@ struct _is {
struct ast_state ast;
};
-/* Used by _PyImport_Cleanup() */
extern void _PyInterpreterState_ClearModules(PyInterpreterState *interp);
-
-extern PyStatus _PyInterpreterState_SetConfig(
- PyInterpreterState *interp,
- const PyConfig *config);
-
extern void _PyInterpreterState_Clear(PyThreadState *tstate);