PageRenderTime 748ms CodeModel.GetById 246ms app.highlight 138ms RepoModel.GetById 220ms app.codeStats 1ms

/Include/pyerrors.h

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