Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_ERRORS_H |
| 2 | #define Py_ERRORS_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 7 | /* Error objects */ |
| 8 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 9 | /* PyException_HEAD defines the initial segment of every exception class. */ |
Collin Winter | 231ff0e | 2007-08-31 00:59:38 +0000 | [diff] [blame] | 10 | #define PyException_HEAD PyObject_HEAD PyObject *dict;\ |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 11 | PyObject *args; PyObject *traceback;\ |
| 12 | PyObject *context; PyObject *cause; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 13 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 14 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 15 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 16 | } PyBaseExceptionObject; |
| 17 | |
| 18 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 19 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 20 | PyObject *msg; |
| 21 | PyObject *filename; |
| 22 | PyObject *lineno; |
| 23 | PyObject *offset; |
| 24 | PyObject *text; |
| 25 | PyObject *print_file_and_line; |
| 26 | } PySyntaxErrorObject; |
| 27 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 28 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 29 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 30 | PyObject *encoding; |
| 31 | PyObject *object; |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 32 | Py_ssize_t start; |
| 33 | Py_ssize_t end; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 34 | PyObject *reason; |
| 35 | } PyUnicodeErrorObject; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 36 | |
| 37 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 38 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 39 | PyObject *code; |
| 40 | } PySystemExitObject; |
| 41 | |
| 42 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 43 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 44 | PyObject *myerrno; |
| 45 | PyObject *strerror; |
| 46 | PyObject *filename; |
| 47 | } PyEnvironmentErrorObject; |
| 48 | |
| 49 | #ifdef MS_WINDOWS |
| 50 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 51 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 52 | PyObject *myerrno; |
| 53 | PyObject *strerror; |
| 54 | PyObject *filename; |
| 55 | PyObject *winerror; |
| 56 | } PyWindowsErrorObject; |
| 57 | #endif |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 58 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 59 | /* Error handling definitions */ |
| 60 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 61 | PyAPI_FUNC(void) PyErr_SetNone(PyObject *); |
| 62 | PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *); |
| 63 | PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *); |
| 64 | PyAPI_FUNC(PyObject *) PyErr_Occurred(void); |
| 65 | PyAPI_FUNC(void) PyErr_Clear(void); |
| 66 | PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **); |
| 67 | PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 68 | |
Raymond Hettinger | 5ba0cbe | 2005-08-06 18:31:24 +0000 | [diff] [blame] | 69 | #ifdef Py_DEBUG |
| 70 | #define _PyErr_OCCURRED() PyErr_Occurred() |
| 71 | #else |
| 72 | #define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type) |
| 73 | #endif |
| 74 | |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 75 | /* Error testing and normalization */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 76 | PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); |
| 77 | PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); |
| 78 | PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 79 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 80 | /* Traceback manipulation (PEP 3134) */ |
| 81 | PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *); |
| 82 | PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *); |
| 83 | |
| 84 | /* Cause manipulation (PEP 3134) */ |
| 85 | PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *); |
| 86 | PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *); |
| 87 | |
| 88 | /* Context manipulation (PEP 3134) */ |
| 89 | PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *); |
| 90 | PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *); |
| 91 | |
| 92 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 93 | /* */ |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 94 | |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 95 | #define PyExceptionClass_Check(x) \ |
| 96 | (PyType_Check((x)) && \ |
| 97 | PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 98 | |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 99 | #define PyExceptionInstance_Check(x) \ |
| 100 | PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 101 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 102 | #define PyExceptionClass_Name(x) \ |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 103 | ((char *)(((PyTypeObject*)(x))->tp_name)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 104 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 105 | #define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 106 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 107 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 108 | /* Predefined exceptions */ |
Guido van Rossum | 5c600e1 | 1990-10-14 20:00:25 +0000 | [diff] [blame] | 109 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 110 | PyAPI_DATA(PyObject *) PyExc_BaseException; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 111 | PyAPI_DATA(PyObject *) PyExc_Exception; |
| 112 | PyAPI_DATA(PyObject *) PyExc_StopIteration; |
Phillip J. Eby | 0d6615f | 2005-08-02 00:46:46 +0000 | [diff] [blame] | 113 | PyAPI_DATA(PyObject *) PyExc_GeneratorExit; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 114 | PyAPI_DATA(PyObject *) PyExc_ArithmeticError; |
| 115 | PyAPI_DATA(PyObject *) PyExc_LookupError; |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 116 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 117 | PyAPI_DATA(PyObject *) PyExc_AssertionError; |
| 118 | PyAPI_DATA(PyObject *) PyExc_AttributeError; |
| 119 | PyAPI_DATA(PyObject *) PyExc_EOFError; |
| 120 | PyAPI_DATA(PyObject *) PyExc_FloatingPointError; |
| 121 | PyAPI_DATA(PyObject *) PyExc_EnvironmentError; |
| 122 | PyAPI_DATA(PyObject *) PyExc_IOError; |
| 123 | PyAPI_DATA(PyObject *) PyExc_OSError; |
| 124 | PyAPI_DATA(PyObject *) PyExc_ImportError; |
| 125 | PyAPI_DATA(PyObject *) PyExc_IndexError; |
| 126 | PyAPI_DATA(PyObject *) PyExc_KeyError; |
| 127 | PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt; |
| 128 | PyAPI_DATA(PyObject *) PyExc_MemoryError; |
| 129 | PyAPI_DATA(PyObject *) PyExc_NameError; |
| 130 | PyAPI_DATA(PyObject *) PyExc_OverflowError; |
| 131 | PyAPI_DATA(PyObject *) PyExc_RuntimeError; |
| 132 | PyAPI_DATA(PyObject *) PyExc_NotImplementedError; |
| 133 | PyAPI_DATA(PyObject *) PyExc_SyntaxError; |
| 134 | PyAPI_DATA(PyObject *) PyExc_IndentationError; |
| 135 | PyAPI_DATA(PyObject *) PyExc_TabError; |
| 136 | PyAPI_DATA(PyObject *) PyExc_ReferenceError; |
| 137 | PyAPI_DATA(PyObject *) PyExc_SystemError; |
| 138 | PyAPI_DATA(PyObject *) PyExc_SystemExit; |
| 139 | PyAPI_DATA(PyObject *) PyExc_TypeError; |
| 140 | PyAPI_DATA(PyObject *) PyExc_UnboundLocalError; |
| 141 | PyAPI_DATA(PyObject *) PyExc_UnicodeError; |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 142 | PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError; |
| 143 | PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError; |
| 144 | PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 145 | PyAPI_DATA(PyObject *) PyExc_ValueError; |
| 146 | PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError; |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 147 | #ifdef MS_WINDOWS |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 148 | PyAPI_DATA(PyObject *) PyExc_WindowsError; |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 149 | #endif |
Martin v. Löwis | 79acb9e | 2002-12-06 12:48:53 +0000 | [diff] [blame] | 150 | #ifdef __VMS |
Neal Norwitz | 21d896c | 2003-07-01 20:15:21 +0000 | [diff] [blame] | 151 | PyAPI_DATA(PyObject *) PyExc_VMSError; |
Martin v. Löwis | 79acb9e | 2002-12-06 12:48:53 +0000 | [diff] [blame] | 152 | #endif |
Guido van Rossum | 3e55cb6 | 1990-10-21 22:09:30 +0000 | [diff] [blame] | 153 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 154 | PyAPI_DATA(PyObject *) PyExc_BufferError; |
| 155 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 156 | PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst; |
Thomas Wouters | 89d996e | 2007-09-08 17:39:28 +0000 | [diff] [blame] | 157 | PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst; |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 158 | |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 159 | /* Predefined warning categories */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 160 | PyAPI_DATA(PyObject *) PyExc_Warning; |
| 161 | PyAPI_DATA(PyObject *) PyExc_UserWarning; |
| 162 | PyAPI_DATA(PyObject *) PyExc_DeprecationWarning; |
| 163 | PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning; |
| 164 | PyAPI_DATA(PyObject *) PyExc_SyntaxWarning; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 165 | PyAPI_DATA(PyObject *) PyExc_RuntimeWarning; |
Barry Warsaw | 9f00739 | 2002-08-14 15:51:29 +0000 | [diff] [blame] | 166 | PyAPI_DATA(PyObject *) PyExc_FutureWarning; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 167 | PyAPI_DATA(PyObject *) PyExc_ImportWarning; |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 168 | PyAPI_DATA(PyObject *) PyExc_UnicodeWarning; |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 169 | PyAPI_DATA(PyObject *) PyExc_BytesWarning; |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 170 | |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 171 | |
Guido van Rossum | 5c600e1 | 1990-10-14 20:00:25 +0000 | [diff] [blame] | 172 | /* Convenience functions */ |
| 173 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 174 | PyAPI_FUNC(int) PyErr_BadArgument(void); |
| 175 | PyAPI_FUNC(PyObject *) PyErr_NoMemory(void); |
| 176 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 177 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 178 | PyObject *, PyObject *); |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 179 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, const char *); |
Hirokazu Yamamoto | 8223c24 | 2009-05-17 04:21:53 +0000 | [diff] [blame] | 180 | #ifdef MS_WINDOWS |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 181 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 182 | PyObject *, const Py_UNICODE *); |
Hirokazu Yamamoto | 8223c24 | 2009-05-17 04:21:53 +0000 | [diff] [blame] | 183 | #endif /* MS_WINDOWS */ |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 184 | |
Walter Dörwald | 573c08c | 2007-05-25 15:46:59 +0000 | [diff] [blame] | 185 | PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 186 | |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 187 | #ifdef MS_WINDOWS |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 188 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 189 | int, const char *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 190 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 191 | int, const char *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 192 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 193 | int, const Py_UNICODE *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 194 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 195 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 196 | PyObject *,int, PyObject *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 197 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 198 | PyObject *,int, const char *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 199 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 200 | PyObject *,int, const Py_UNICODE *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 201 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 202 | #endif /* MS_WINDOWS */ |
Guido van Rossum | 3e55cb6 | 1990-10-21 22:09:30 +0000 | [diff] [blame] | 203 | |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 204 | /* Export the old function so that the existing API remains available: */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 205 | PyAPI_FUNC(void) PyErr_BadInternalCall(void); |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 206 | PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno); |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 207 | /* Mask the old API with a call to the new API for code compiled under |
| 208 | Python 2.0: */ |
| 209 | #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__) |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 210 | |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 211 | /* Function to create a new exception */ |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 212 | PyAPI_FUNC(PyObject *) PyErr_NewException(const char *name, PyObject *base, |
Fred Drake | d5c84ed | 2000-07-08 17:25:55 +0000 | [diff] [blame] | 213 | PyObject *dict); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 214 | PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *); |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 215 | |
Barry Warsaw | f3f41a9 | 1997-01-03 00:15:03 +0000 | [diff] [blame] | 216 | /* In sigcheck.c or signalmodule.c */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 217 | PyAPI_FUNC(int) PyErr_CheckSignals(void); |
| 218 | PyAPI_FUNC(void) PyErr_SetInterrupt(void); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 219 | |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 220 | /* In signalmodule.c */ |
| 221 | int PySignal_SetWakeupFd(int fd); |
| 222 | |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 223 | /* Support for adding program text to SyntaxErrors */ |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 224 | PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int); |
| 225 | PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int); |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 226 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 227 | /* The following functions are used to create and modify unicode |
| 228 | exceptions from C */ |
Walter Dörwald | bf73db8 | 2002-11-21 20:08:33 +0000 | [diff] [blame] | 229 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 230 | /* create a UnicodeDecodeError object */ |
| 231 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 232 | const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 233 | |
| 234 | /* create a UnicodeEncodeError object */ |
| 235 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 236 | const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 237 | |
| 238 | /* create a UnicodeTranslateError object */ |
| 239 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 240 | const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 241 | |
| 242 | /* get the encoding attribute */ |
| 243 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *); |
| 244 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 245 | |
| 246 | /* get the object attribute */ |
| 247 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *); |
| 248 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *); |
| 249 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *); |
| 250 | |
| 251 | /* get the value of the start attribute (the int * may not be NULL) |
| 252 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 253 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); |
| 254 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); |
| 255 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 256 | |
| 257 | /* assign a new value to the start attribute |
| 258 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 259 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t); |
| 260 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t); |
| 261 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 262 | |
| 263 | /* get the value of the end attribute (the int *may not be NULL) |
| 264 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 265 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 266 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 267 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 268 | |
| 269 | /* assign a new value to the end attribute |
| 270 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 271 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t); |
| 272 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t); |
| 273 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 274 | |
| 275 | /* get the value of the reason attribute */ |
| 276 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *); |
| 277 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *); |
| 278 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *); |
| 279 | |
| 280 | /* assign a new value to the reason attribute |
| 281 | return 0 on success, -1 on failure */ |
| 282 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 283 | PyObject *, const char *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 284 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 285 | PyObject *, const char *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 286 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 287 | PyObject *, const char *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 288 | |
| 289 | |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 290 | /* These APIs aren't really part of the error implementation, but |
| 291 | often needed to format error messages; the native C lib APIs are |
| 292 | not available on all platforms, which is why we provide emulations |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 293 | for those platforms in Python/mysnprintf.c, |
| 294 | WARNING: The return value of snprintf varies across platforms; do |
| 295 | not rely on any particular behavior; eventually the C99 defn may |
| 296 | be reliable. |
| 297 | */ |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 298 | #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF) |
| 299 | # define HAVE_SNPRINTF |
| 300 | # define snprintf _snprintf |
| 301 | # define vsnprintf _vsnprintf |
| 302 | #endif |
Marc-André Lemburg | 03d1b18 | 2001-07-31 18:05:33 +0000 | [diff] [blame] | 303 | |
Marc-André Lemburg | cecd9e0 | 2001-07-31 14:23:52 +0000 | [diff] [blame] | 304 | #include <stdarg.h> |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 305 | PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...) |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 306 | Py_GCC_ATTRIBUTE((format(printf, 3, 4))); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 307 | PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) |
Antoine Pitrou | 7f14f0d | 2010-05-09 16:14:21 +0000 | [diff] [blame] | 308 | Py_GCC_ATTRIBUTE((format(printf, 3, 0))); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 309 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 310 | #ifdef __cplusplus |
| 311 | } |
| 312 | #endif |
| 313 | #endif /* !Py_ERRORS_H */ |