Skip to content

Commit 79823c1

Browse files
authored
gh-106320: Remove private _PyErr_ChainExceptions() (#108713)
Remove _PyErr_ChainExceptions(), _PyErr_ChainExceptions1() and _PyErr_SetFromPyStatus() functions from the public C API. * Move the private _PyErr_ChainExceptions() and _PyErr_ChainExceptions1() function to the internal C API (pycore_pyerrors.h). * Move the private _PyErr_SetFromPyStatus() to the internal C API (pycore_initconfig.h). * No longer export the _PyErr_ChainExceptions() function. * Move run_in_subinterp_with_config() from _testcapi to _testinternalcapi.
1 parent 059bd4d commit 79823c1

File tree

18 files changed

+140
-117
lines changed

18 files changed

+140
-117
lines changed

Include/cpython/initconfig.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode);
2525
PyAPI_FUNC(int) PyStatus_IsError(PyStatus err);
2626
PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err);
2727
PyAPI_FUNC(int) PyStatus_Exception(PyStatus err);
28-
PyAPI_FUNC(PyObject *) _PyErr_SetFromPyStatus(PyStatus status);
2928

3029
/* --- PyWideStringList ------------------------------------------------ */
3130

Include/cpython/pyerrors.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ typedef PyOSErrorObject PyEnvironmentErrorObject;
8888
typedef PyOSErrorObject PyWindowsErrorObject;
8989
#endif
9090

91-
/* Context manipulation (PEP 3134) */
92-
93-
Py_DEPRECATED(3.12) PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
94-
PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
95-
9691
/* In exceptions.c */
9792

9893
PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(

Include/internal/pycore_initconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ struct pyruntimestate;
4444
#define _PyStatus_UPDATE_FUNC(err) \
4545
do { (err).func = _PyStatus_GET_FUNC(); } while (0)
4646

47+
// Export for '_testinternalcapi' shared extension
48+
PyAPI_FUNC(PyObject *) _PyErr_SetFromPyStatus(PyStatus status);
49+
50+
4751
/* --- PyWideStringList ------------------------------------------------ */
4852

4953
#define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}

Include/internal/pycore_pyerrors.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
163163

164164
void _PyErr_FormatNote(const char *format, ...);
165165

166+
/* Context manipulation (PEP 3134) */
167+
168+
Py_DEPRECATED(3.12) extern void _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
169+
170+
// Export for '_zoneinfo' shared extension
171+
PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
172+
166173
#ifdef __cplusplus
167174
}
168175
#endif

Lib/test/support/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,11 +1821,11 @@ def run_in_subinterp_with_config(code, *, own_gil=None, **config):
18211821
module is enabled.
18221822
"""
18231823
_check_tracemalloc()
1824-
import _testcapi
1824+
import _testinternalcapi
18251825
if own_gil is not None:
18261826
assert 'gil' not in config, (own_gil, config)
18271827
config['gil'] = 2 if own_gil else 1
1828-
return _testcapi.run_in_subinterp_with_config(code, **config)
1828+
return _testinternalcapi.run_in_subinterp_with_config(code, **config)
18291829

18301830

18311831
def _check_tracemalloc():

Lib/test/test_import/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,12 +1805,12 @@ def check_compatible_fresh(self, name, *, strict=False, isolated=False):
18051805
check_multi_interp_extensions=strict,
18061806
)
18071807
_, out, err = script_helper.assert_python_ok('-c', textwrap.dedent(f'''
1808-
import _testcapi, sys
1808+
import _testinternalcapi, sys
18091809
assert (
18101810
{name!r} in sys.builtin_module_names or
18111811
{name!r} not in sys.modules
18121812
), repr({name!r})
1813-
ret = _testcapi.run_in_subinterp_with_config(
1813+
ret = _testinternalcapi.run_in_subinterp_with_config(
18141814
{self.import_script(name, "sys.stdout.fileno()")!r},
18151815
**{kwargs},
18161816
)
@@ -1829,9 +1829,9 @@ def check_incompatible_fresh(self, name, *, isolated=False):
18291829
check_multi_interp_extensions=True,
18301830
)
18311831
_, out, err = script_helper.assert_python_ok('-c', textwrap.dedent(f'''
1832-
import _testcapi, sys
1832+
import _testinternalcapi, sys
18331833
assert {name!r} not in sys.modules, {name!r}
1834-
ret = _testcapi.run_in_subinterp_with_config(
1834+
ret = _testinternalcapi.run_in_subinterp_with_config(
18351835
{self.import_script(name, "sys.stdout.fileno()")!r},
18361836
**{kwargs},
18371837
)

Modules/_io/_iomodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Python.h"
1111
#include "pycore_abstract.h" // _PyNumber_Index()
1212
#include "pycore_initconfig.h" // _PyStatus_OK()
13+
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
1314
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1415

1516
#include "_iomodule.h"

Modules/_io/fileio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Python.h"
44
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
55
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
6+
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
67

78
#include <stdbool.h>
89
#ifdef HAVE_SYS_TYPES_H

Modules/_io/iobase.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "pycore_call.h" // _PyObject_CallMethod()
1313
#include "pycore_long.h" // _PyLong_GetOne()
1414
#include "pycore_object.h" // _PyType_HasFeature()
15+
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
16+
1517
#include <stddef.h> // offsetof()
1618
#include "_iomodule.h"
1719

Modules/_io/textio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#include "Python.h"
1010
#include "pycore_call.h" // _PyObject_CallMethod()
1111
#include "pycore_codecs.h" // _PyCodecInfo_GetIncrementalDecoder()
12+
#include "pycore_fileutils.h" // _Py_GetLocaleEncoding()
1213
#include "pycore_interp.h" // PyInterpreterState.fs_codec
1314
#include "pycore_long.h" // _PyLong_GetZero()
14-
#include "pycore_fileutils.h" // _Py_GetLocaleEncoding()
1515
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
16+
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
1617
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1718

1819
#include "_iomodule.h"

0 commit comments

Comments
 (0)