Skip to content

Commit 5a8c240

Browse files
authored
bpo-35134: Add Include/cpython/pyerrors.h (GH-10727)
Move pyerrors.h code surrounded by "#ifndef Py_LIMITED_API" to a new Include/cpython/pyerrors.h header file.
1 parent 65c216e commit 5a8c240

File tree

2 files changed

+182
-168
lines changed

2 files changed

+182
-168
lines changed

Include/cpython/pyerrors.h

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#ifndef Py_CPYTHON_ERRORS_H
2+
# error "this header file must not be included directly"
3+
#endif
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
/* Error objects */
10+
11+
/* PyException_HEAD defines the initial segment of every exception class. */
12+
#define PyException_HEAD PyObject_HEAD PyObject *dict;\
13+
PyObject *args; PyObject *traceback;\
14+
PyObject *context; PyObject *cause;\
15+
char suppress_context;
16+
17+
typedef struct {
18+
PyException_HEAD
19+
} PyBaseExceptionObject;
20+
21+
typedef struct {
22+
PyException_HEAD
23+
PyObject *msg;
24+
PyObject *filename;
25+
PyObject *lineno;
26+
PyObject *offset;
27+
PyObject *text;
28+
PyObject *print_file_and_line;
29+
} PySyntaxErrorObject;
30+
31+
typedef struct {
32+
PyException_HEAD
33+
PyObject *msg;
34+
PyObject *name;
35+
PyObject *path;
36+
} PyImportErrorObject;
37+
38+
typedef struct {
39+
PyException_HEAD
40+
PyObject *encoding;
41+
PyObject *object;
42+
Py_ssize_t start;
43+
Py_ssize_t end;
44+
PyObject *reason;
45+
} PyUnicodeErrorObject;
46+
47+
typedef struct {
48+
PyException_HEAD
49+
PyObject *code;
50+
} PySystemExitObject;
51+
52+
typedef struct {
53+
PyException_HEAD
54+
PyObject *myerrno;
55+
PyObject *strerror;
56+
PyObject *filename;
57+
PyObject *filename2;
58+
#ifdef MS_WINDOWS
59+
PyObject *winerror;
60+
#endif
61+
Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */
62+
} PyOSErrorObject;
63+
64+
typedef struct {
65+
PyException_HEAD
66+
PyObject *value;
67+
} PyStopIterationObject;
68+
69+
/* Compatibility typedefs */
70+
typedef PyOSErrorObject PyEnvironmentErrorObject;
71+
#ifdef MS_WINDOWS
72+
typedef PyOSErrorObject PyWindowsErrorObject;
73+
#endif
74+
75+
/* Error handling definitions */
76+
77+
PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
78+
_PyErr_StackItem *_PyErr_GetTopmostException(PyThreadState *tstate);
79+
80+
/* Context manipulation (PEP 3134) */
81+
82+
PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
83+
84+
/* */
85+
86+
#define PyExceptionClass_Name(x) (((PyTypeObject*)(x))->tp_name)
87+
88+
/* Convenience functions */
89+
90+
#ifdef MS_WINDOWS
91+
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
92+
PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3);
93+
#endif /* MS_WINDOWS */
94+
95+
/* Like PyErr_Format(), but saves current exception as __context__ and
96+
__cause__.
97+
*/
98+
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
99+
PyObject *exception,
100+
const char *format, /* ASCII-encoded string */
101+
...
102+
);
103+
104+
#ifdef MS_WINDOWS
105+
/* XXX redeclare to use WSTRING */
106+
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
107+
int, const Py_UNICODE *) Py_DEPRECATED(3.3);
108+
109+
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
110+
PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3);
111+
#endif
112+
113+
/* In exceptions.c */
114+
115+
/* Helper that attempts to replace the current exception with one of the
116+
* same type but with a prefix added to the exception text. The resulting
117+
* exception description looks like:
118+
*
119+
* prefix (exc_type: original_exc_str)
120+
*
121+
* Only some exceptions can be safely replaced. If the function determines
122+
* it isn't safe to perform the replacement, it will leave the original
123+
* unmodified exception in place.
124+
*
125+
* Returns a borrowed reference to the new exception (if any), NULL if the
126+
* existing exception was left in place.
127+
*/
128+
PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
129+
const char *prefix_format, /* ASCII-encoded string */
130+
...
131+
);
132+
133+
/* In signalmodule.c */
134+
135+
int PySignal_SetWakeupFd(int fd);
136+
137+
/* Support for adding program text to SyntaxErrors */
138+
139+
PyAPI_FUNC(void) PyErr_SyntaxLocationObject(
140+
PyObject *filename,
141+
int lineno,
142+
int col_offset);
143+
144+
PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
145+
PyObject *filename,
146+
int lineno);
147+
148+
/* Create a UnicodeEncodeError object */
149+
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
150+
const char *encoding, /* UTF-8 encoded string */
151+
const Py_UNICODE *object,
152+
Py_ssize_t length,
153+
Py_ssize_t start,
154+
Py_ssize_t end,
155+
const char *reason /* UTF-8 encoded string */
156+
) Py_DEPRECATED(3.3);
157+
158+
/* Create a UnicodeTranslateError object */
159+
PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
160+
const Py_UNICODE *object,
161+
Py_ssize_t length,
162+
Py_ssize_t start,
163+
Py_ssize_t end,
164+
const char *reason /* UTF-8 encoded string */
165+
) Py_DEPRECATED(3.3);
166+
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
167+
PyObject *object,
168+
Py_ssize_t start,
169+
Py_ssize_t end,
170+
const char *reason /* UTF-8 encoded string */
171+
);
172+
173+
174+
#ifdef __cplusplus
175+
}
176+
#endif

0 commit comments

Comments
 (0)