Fix py3k warnings in bsddb
[python.git] / Include / pyerrors.h
blobfedf91333df7613688f1393422312c9da019c5e6
1 #ifndef Py_ERRORS_H
2 #define Py_ERRORS_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
7 /* Error objects */
9 typedef struct {
10 PyObject_HEAD
11 PyObject *dict;
12 PyObject *args;
13 PyObject *message;
14 } PyBaseExceptionObject;
16 typedef struct {
17 PyObject_HEAD
18 PyObject *dict;
19 PyObject *args;
20 PyObject *message;
21 PyObject *msg;
22 PyObject *filename;
23 PyObject *lineno;
24 PyObject *offset;
25 PyObject *text;
26 PyObject *print_file_and_line;
27 } PySyntaxErrorObject;
29 #ifdef Py_USING_UNICODE
30 typedef struct {
31 PyObject_HEAD
32 PyObject *dict;
33 PyObject *args;
34 PyObject *message;
35 PyObject *encoding;
36 PyObject *object;
37 Py_ssize_t start;
38 Py_ssize_t end;
39 PyObject *reason;
40 } PyUnicodeErrorObject;
41 #endif
43 typedef struct {
44 PyObject_HEAD
45 PyObject *dict;
46 PyObject *args;
47 PyObject *message;
48 PyObject *code;
49 } PySystemExitObject;
51 typedef struct {
52 PyObject_HEAD
53 PyObject *dict;
54 PyObject *args;
55 PyObject *message;
56 PyObject *myerrno;
57 PyObject *strerror;
58 PyObject *filename;
59 } PyEnvironmentErrorObject;
61 #ifdef MS_WINDOWS
62 typedef struct {
63 PyObject_HEAD
64 PyObject *dict;
65 PyObject *args;
66 PyObject *message;
67 PyObject *myerrno;
68 PyObject *strerror;
69 PyObject *filename;
70 PyObject *winerror;
71 } PyWindowsErrorObject;
72 #endif
74 /* Error handling definitions */
76 PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
77 PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
78 PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);
79 PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
80 PyAPI_FUNC(void) PyErr_Clear(void);
81 PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
82 PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
84 #ifdef Py_DEBUG
85 #define _PyErr_OCCURRED() PyErr_Occurred()
86 #else
87 #define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)
88 #endif
90 /* Error testing and normalization */
91 PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
92 PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
93 PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
95 /* */
97 #define PyExceptionClass_Check(x) \
98 (PyClass_Check((x)) || (PyType_Check((x)) && \
99 PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)))
101 #define PyExceptionInstance_Check(x) \
102 (PyInstance_Check((x)) || \
103 PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS))
105 #define PyExceptionClass_Name(x) \
106 (PyClass_Check((x)) \
107 ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
108 : (char *)(((PyTypeObject*)(x))->tp_name))
110 #define PyExceptionInstance_Class(x) \
111 ((PyInstance_Check((x)) \
112 ? (PyObject*)((PyInstanceObject*)(x))->in_class \
113 : (PyObject*)((x)->ob_type)))
116 /* Predefined exceptions */
118 PyAPI_DATA(PyObject *) PyExc_BaseException;
119 PyAPI_DATA(PyObject *) PyExc_Exception;
120 PyAPI_DATA(PyObject *) PyExc_StopIteration;
121 PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
122 PyAPI_DATA(PyObject *) PyExc_StandardError;
123 PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
124 PyAPI_DATA(PyObject *) PyExc_LookupError;
126 PyAPI_DATA(PyObject *) PyExc_AssertionError;
127 PyAPI_DATA(PyObject *) PyExc_AttributeError;
128 PyAPI_DATA(PyObject *) PyExc_EOFError;
129 PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
130 PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
131 PyAPI_DATA(PyObject *) PyExc_IOError;
132 PyAPI_DATA(PyObject *) PyExc_OSError;
133 PyAPI_DATA(PyObject *) PyExc_ImportError;
134 PyAPI_DATA(PyObject *) PyExc_IndexError;
135 PyAPI_DATA(PyObject *) PyExc_KeyError;
136 PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
137 PyAPI_DATA(PyObject *) PyExc_MemoryError;
138 PyAPI_DATA(PyObject *) PyExc_NameError;
139 PyAPI_DATA(PyObject *) PyExc_OverflowError;
140 PyAPI_DATA(PyObject *) PyExc_RuntimeError;
141 PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
142 PyAPI_DATA(PyObject *) PyExc_SyntaxError;
143 PyAPI_DATA(PyObject *) PyExc_IndentationError;
144 PyAPI_DATA(PyObject *) PyExc_TabError;
145 PyAPI_DATA(PyObject *) PyExc_ReferenceError;
146 PyAPI_DATA(PyObject *) PyExc_SystemError;
147 PyAPI_DATA(PyObject *) PyExc_SystemExit;
148 PyAPI_DATA(PyObject *) PyExc_TypeError;
149 PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
150 PyAPI_DATA(PyObject *) PyExc_UnicodeError;
151 PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
152 PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
153 PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
154 PyAPI_DATA(PyObject *) PyExc_ValueError;
155 PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
156 #ifdef MS_WINDOWS
157 PyAPI_DATA(PyObject *) PyExc_WindowsError;
158 #endif
159 #ifdef __VMS
160 PyAPI_DATA(PyObject *) PyExc_VMSError;
161 #endif
163 PyAPI_DATA(PyObject *) PyExc_BufferError;
165 PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
166 PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;
168 /* Predefined warning categories */
169 PyAPI_DATA(PyObject *) PyExc_Warning;
170 PyAPI_DATA(PyObject *) PyExc_UserWarning;
171 PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
172 PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
173 PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
174 PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
175 PyAPI_DATA(PyObject *) PyExc_FutureWarning;
176 PyAPI_DATA(PyObject *) PyExc_ImportWarning;
177 PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
178 PyAPI_DATA(PyObject *) PyExc_BytesWarning;
181 /* Convenience functions */
183 PyAPI_FUNC(int) PyErr_BadArgument(void);
184 PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
185 PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
186 PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
187 PyObject *, PyObject *);
188 PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
189 PyObject *, const char *);
190 #ifdef MS_WINDOWS
191 PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
192 PyObject *, const Py_UNICODE *);
193 #endif /* MS_WINDOWS */
195 PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
196 Py_GCC_ATTRIBUTE((format(printf, 2, 3)));
198 #ifdef MS_WINDOWS
199 PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
200 int, const char *);
201 PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
202 int, const char *);
203 PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
204 int, const Py_UNICODE *);
205 PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
206 PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
207 PyObject *,int, PyObject *);
208 PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
209 PyObject *,int, const char *);
210 PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
211 PyObject *,int, const Py_UNICODE *);
212 PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
213 #endif /* MS_WINDOWS */
215 /* Export the old function so that the existing API remains available: */
216 PyAPI_FUNC(void) PyErr_BadInternalCall(void);
217 PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
218 /* Mask the old API with a call to the new API for code compiled under
219 Python 2.0: */
220 #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
222 /* Function to create a new exception */
223 PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base,
224 PyObject *dict);
225 PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
227 /* In sigcheck.c or signalmodule.c */
228 PyAPI_FUNC(int) PyErr_CheckSignals(void);
229 PyAPI_FUNC(void) PyErr_SetInterrupt(void);
231 /* In signalmodule.c */
232 int PySignal_SetWakeupFd(int fd);
234 /* Support for adding program text to SyntaxErrors */
235 PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
236 PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
238 #ifdef Py_USING_UNICODE
239 /* The following functions are used to create and modify unicode
240 exceptions from C */
242 /* create a UnicodeDecodeError object */
243 PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
244 const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
246 /* create a UnicodeEncodeError object */
247 PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
248 const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
250 /* create a UnicodeTranslateError object */
251 PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
252 const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
254 /* get the encoding attribute */
255 PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
256 PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
258 /* get the object attribute */
259 PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
260 PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
261 PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
263 /* get the value of the start attribute (the int * may not be NULL)
264 return 0 on success, -1 on failure */
265 PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
266 PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
267 PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);
269 /* assign a new value to the start attribute
270 return 0 on success, -1 on failure */
271 PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
272 PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
273 PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
275 /* get the value of the end attribute (the int *may not be NULL)
276 return 0 on success, -1 on failure */
277 PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
278 PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
279 PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
281 /* assign a new value to the end attribute
282 return 0 on success, -1 on failure */
283 PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
284 PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
285 PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
287 /* get the value of the reason attribute */
288 PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
289 PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
290 PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
292 /* assign a new value to the reason attribute
293 return 0 on success, -1 on failure */
294 PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
295 PyObject *, const char *);
296 PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
297 PyObject *, const char *);
298 PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
299 PyObject *, const char *);
300 #endif
303 /* These APIs aren't really part of the error implementation, but
304 often needed to format error messages; the native C lib APIs are
305 not available on all platforms, which is why we provide emulations
306 for those platforms in Python/mysnprintf.c,
307 WARNING: The return value of snprintf varies across platforms; do
308 not rely on any particular behavior; eventually the C99 defn may
309 be reliable.
311 #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
312 # define HAVE_SNPRINTF
313 # define snprintf _snprintf
314 # define vsnprintf _vsnprintf
315 #endif
317 #include <stdarg.h>
318 PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
319 Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
320 PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
321 Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
323 #ifdef __cplusplus
325 #endif
326 #endif /* !Py_ERRORS_H */