Skip to content

Commit e1b2995

Browse files
authored
bpo-32030: Make _PySys_AddXOptionWithError() private (GH-10236)
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.
1 parent 905f1ac commit e1b2995

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Include/sysmodule.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);
3737
PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *);
3838
#endif
3939

40-
#ifdef Py_BUILD_CORE
41-
PyAPI_FUNC(int) _PySys_AddXOptionWithError(const wchar_t *s);
42-
PyAPI_FUNC(int) _PySys_AddWarnOptionWithError(PyObject *option);
43-
#endif
44-
4540
#ifdef __cplusplus
4641
}
4742
#endif

Python/sysmodule.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ PySys_ResetWarnOptions(void)
18071807
PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);
18081808
}
18091809

1810-
int
1810+
static int
18111811
_PySys_AddWarnOptionWithError(PyObject *option)
18121812
{
18131813
PyObject *warnoptions = get_warnoptions();
@@ -1823,7 +1823,12 @@ _PySys_AddWarnOptionWithError(PyObject *option)
18231823
void
18241824
PySys_AddWarnOptionUnicode(PyObject *option)
18251825
{
1826-
(void)_PySys_AddWarnOptionWithError(option);
1826+
if (_PySys_AddWarnOptionWithError(option) < 0) {
1827+
/* No return value, therefore clear error state if possible */
1828+
if (_PyThreadState_UncheckedGet()) {
1829+
PyErr_Clear();
1830+
}
1831+
}
18271832
}
18281833

18291834
void
@@ -1877,7 +1882,7 @@ get_xoptions(void)
18771882
return xoptions;
18781883
}
18791884

1880-
int
1885+
static int
18811886
_PySys_AddXOptionWithError(const wchar_t *s)
18821887
{
18831888
PyObject *name = NULL, *value = NULL;

0 commit comments

Comments
 (0)