]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-32030: Make _PySys_AddXOptionWithError() private (GH-10236)
authorVictor Stinner <vstinner@redhat.com>
Tue, 30 Oct 2018 13:31:42 +0000 (14:31 +0100)
committerGitHub <noreply@github.com>
Tue, 30 Oct 2018 13:31:42 +0000 (14:31 +0100)
Make _PySys_AddXOptionWithError() and _PySys_AddWarnOptionWithError()
functions private again. They are no longer needed to initialize Python:
_PySys_EndInit() is now responsible to add these options instead.

Moreover, PySys_AddWarnOptionUnicode() now clears the exception on
failure if possible.

Include/sysmodule.h
Python/sysmodule.c

index 719ecfcf61f2e7ef5c45650ea56bbecf5b8c48b8..c5547ff6742e068833f4c982b36093033b2e850a 100644 (file)
@@ -37,11 +37,6 @@ PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);
 PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *);
 #endif
 
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _PySys_AddXOptionWithError(const wchar_t *s);
-PyAPI_FUNC(int) _PySys_AddWarnOptionWithError(PyObject *option);
-#endif
-
 #ifdef __cplusplus
 }
 #endif
index f88b273e26b1e7ba3f553a7a5fd7362327f86b58..9579eae4ff5f4d28b11919789a22a4f600668446 100644 (file)
@@ -1807,7 +1807,7 @@ PySys_ResetWarnOptions(void)
     PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);
 }
 
-int
+static int
 _PySys_AddWarnOptionWithError(PyObject *option)
 {
     PyObject *warnoptions = get_warnoptions();
@@ -1823,7 +1823,12 @@ _PySys_AddWarnOptionWithError(PyObject *option)
 void
 PySys_AddWarnOptionUnicode(PyObject *option)
 {
-    (void)_PySys_AddWarnOptionWithError(option);
+    if (_PySys_AddWarnOptionWithError(option) < 0) {
+        /* No return value, therefore clear error state if possible */
+        if (_PyThreadState_UncheckedGet()) {
+            PyErr_Clear();
+        }
+    }
 }
 
 void
@@ -1877,7 +1882,7 @@ get_xoptions(void)
     return xoptions;
 }
 
-int
+static int
 _PySys_AddXOptionWithError(const wchar_t *s)
 {
     PyObject *name = NULL, *value = NULL;