Skip to content

Commit c5afc97

Browse files
authored
gh-106320: Remove private _PyErr C API functions (#106356)
Remove private _PyErr C API functions: move them to the internal C API (pycore_pyerrors.h).
1 parent 18fedd0 commit c5afc97

File tree

9 files changed

+63
-46
lines changed

9 files changed

+63
-46
lines changed

Include/cpython/pyerrors.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,21 @@ typedef PyOSErrorObject PyWindowsErrorObject;
9191
/* Error handling definitions */
9292

9393
PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
94-
PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
95-
PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
96-
PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
97-
PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
9894

9995
/* Context manipulation (PEP 3134) */
10096

10197
Py_DEPRECATED(3.12) PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
10298
PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
10399

104-
/* Like PyErr_Format(), but saves current exception as __context__ and
105-
__cause__.
106-
*/
107-
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
108-
PyObject *exception,
109-
const char *format, /* ASCII-encoded string */
110-
...
111-
);
112-
113100
/* In exceptions.c */
114101

115-
PyAPI_FUNC(int) _PyException_AddNote(
116-
PyObject *exc,
117-
PyObject *note);
118-
119102
PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
120103
PyObject *orig,
121104
PyObject *excs);
122105

123106
/* In signalmodule.c */
124107

125108
int PySignal_SetWakeupFd(int fd);
126-
PyAPI_FUNC(int) _PyErr_CheckSignals(void);
127109

128110
/* Support for adding program text to SyntaxErrors */
129111

@@ -143,18 +125,6 @@ PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
143125
PyObject *filename,
144126
int lineno);
145127

146-
PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
147-
PyObject *filename,
148-
int lineno,
149-
const char* encoding);
150-
151-
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
152-
PyObject *object,
153-
Py_ssize_t start,
154-
Py_ssize_t end,
155-
const char *reason /* UTF-8 encoded string */
156-
);
157-
158128
PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg(
159129
const char *err_msg,
160130
PyObject *obj);
@@ -163,16 +133,4 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc(
163133
const char *func,
164134
const char *message);
165135

166-
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
167-
const char *func,
168-
const char *format,
169-
...);
170-
171-
extern PyObject *_PyErr_SetImportErrorWithNameFrom(
172-
PyObject *,
173-
PyObject *,
174-
PyObject *,
175-
PyObject *);
176-
177-
178136
#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message))

Include/internal/pycore_pyerrors.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,54 @@ extern "C" {
99
#endif
1010

1111

12+
/* Error handling definitions */
13+
14+
PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
15+
PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
16+
PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
17+
PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
18+
19+
/* Like PyErr_Format(), but saves current exception as __context__ and
20+
__cause__.
21+
*/
22+
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
23+
PyObject *exception,
24+
const char *format, /* ASCII-encoded string */
25+
...
26+
);
27+
28+
PyAPI_FUNC(int) _PyException_AddNote(
29+
PyObject *exc,
30+
PyObject *note);
31+
32+
PyAPI_FUNC(int) _PyErr_CheckSignals(void);
33+
34+
/* Support for adding program text to SyntaxErrors */
35+
36+
PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
37+
PyObject *filename,
38+
int lineno,
39+
const char* encoding);
40+
41+
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
42+
PyObject *object,
43+
Py_ssize_t start,
44+
Py_ssize_t end,
45+
const char *reason /* UTF-8 encoded string */
46+
);
47+
48+
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
49+
const char *func,
50+
const char *format,
51+
...);
52+
53+
extern PyObject *_PyErr_SetImportErrorWithNameFrom(
54+
PyObject *,
55+
PyObject *,
56+
PyObject *,
57+
PyObject *);
58+
59+
1260
/* runtime lifecycle */
1361

1462
extern PyStatus _PyErr_InitTypes(PyInterpreterState *);

Modules/_io/bufferedio.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_call.h" // _PyObject_CallNoArgs()
1212
#include "pycore_object.h"
13+
#include "pycore_pyerrors.h" // _Py_FatalErrorFormat()
1314
#include "structmember.h" // PyMemberDef
1415
#include "_iomodule.h"
1516

Modules/_sqlite/cursor.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@
2121
* 3. This notice may not be removed or altered from any source distribution.
2222
*/
2323

24+
#ifndef Py_BUILD_CORE_BUILTIN
25+
# define Py_BUILD_CORE_MODULE 1
26+
#endif
27+
2428
#include "cursor.h"
2529
#include "microprotocols.h"
2630
#include "module.h"
2731
#include "util.h"
2832

33+
#include "pycore_pyerrors.h" // _PyErr_FormatFromCause()
34+
2935
typedef enum {
3036
TYPE_LONG,
3137
TYPE_FLOAT,

Objects/moduleobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
#include "Python.h"
55
#include "pycore_call.h" // _PyObject_CallNoArgs()
66
#include "pycore_interp.h" // PyInterpreterState.importlib
7-
#include "pycore_object.h" // _PyType_AllocNoTrack
8-
#include "pycore_moduleobject.h" // _PyModule_GetDef()
97
#include "pycore_modsupport.h" // _PyModule_CreateInitialized()
8+
#include "pycore_moduleobject.h" // _PyModule_GetDef()
9+
#include "pycore_object.h" // _PyType_AllocNoTrack
10+
#include "pycore_pyerrors.h" // _PyErr_FormatFromCause()
1011
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1112
#include "structmember.h" // PyMemberDef
1213

Objects/obmalloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#include "Python.h"
44
#include "pycore_code.h" // stats
5-
#include "pycore_pystate.h" // _PyInterpreterState_GET
6-
75
#include "pycore_obmalloc.h"
6+
#include "pycore_pyerrors.h" // _Py_FatalErrorFormat()
87
#include "pycore_pymem.h"
8+
#include "pycore_pystate.h" // _PyInterpreterState_GET
99

1010
#include <stdlib.h> // malloc()
1111
#include <stdbool.h>

Objects/unicodeobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5050
#include "pycore_long.h" // _PyLong_FormatWriter()
5151
#include "pycore_object.h" // _PyObject_GC_TRACK(), _Py_FatalRefcountError()
5252
#include "pycore_pathconfig.h" // _Py_DumpPathConfig()
53+
#include "pycore_pyerrors.h" // _PyUnicodeTranslateError_Create()
5354
#include "pycore_pylifecycle.h" // _Py_SetFileSystemEncoding()
5455
#include "pycore_pystate.h" // _PyInterpreterState_GET()
5556
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI

Parser/pegen_errors.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <Python.h>
22
#include <errcode.h>
33

4+
#include "pycore_pyerrors.h" // _PyErr_ProgramDecodedTextObject()
45
#include "tokenizer.h"
56
#include "pegen.h"
67

Python/importdl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Python.h"
55
#include "pycore_call.h"
66
#include "pycore_import.h"
7+
#include "pycore_pyerrors.h" // _PyErr_FormatFromCause()
78
#include "pycore_pystate.h"
89
#include "pycore_runtime.h"
910

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy