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 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 9 | #ifndef Py_LIMITED_API |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 10 | /* PyException_HEAD defines the initial segment of every exception class. */ |
Collin Winter | 231ff0e | 2007-08-31 00:59:38 +0000 | [diff] [blame] | 11 | #define PyException_HEAD PyObject_HEAD PyObject *dict;\ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 12 | PyObject *args; PyObject *traceback;\ |
Benjamin Peterson | d5a1c44 | 2012-05-14 22:09:31 -0700 | [diff] [blame] | 13 | PyObject *context; PyObject *cause;\ |
Benjamin Peterson | 1a1367b | 2012-08-08 17:22:50 -0700 | [diff] [blame] | 14 | char suppress_context; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 15 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 16 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 17 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 18 | } PyBaseExceptionObject; |
| 19 | |
| 20 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 21 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 22 | PyObject *msg; |
| 23 | PyObject *filename; |
| 24 | PyObject *lineno; |
| 25 | PyObject *offset; |
| 26 | PyObject *text; |
| 27 | PyObject *print_file_and_line; |
| 28 | } PySyntaxErrorObject; |
| 29 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 30 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 31 | PyException_HEAD |
Benjamin Peterson | 633b32a | 2012-04-12 21:50:35 -0400 | [diff] [blame] | 32 | PyObject *msg; |
| 33 | PyObject *name; |
| 34 | PyObject *path; |
| 35 | } PyImportErrorObject; |
| 36 | |
| 37 | typedef struct { |
| 38 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 39 | PyObject *encoding; |
| 40 | PyObject *object; |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 41 | Py_ssize_t start; |
| 42 | Py_ssize_t end; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 43 | PyObject *reason; |
| 44 | } PyUnicodeErrorObject; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 45 | |
| 46 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 47 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 48 | PyObject *code; |
| 49 | } PySystemExitObject; |
| 50 | |
| 51 | typedef struct { |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 52 | PyException_HEAD |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 53 | PyObject *myerrno; |
| 54 | PyObject *strerror; |
| 55 | PyObject *filename; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 56 | #ifdef MS_WINDOWS |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 57 | PyObject *winerror; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 58 | #endif |
Antoine Pitrou | 6b4883d | 2011-10-12 02:54:14 +0200 | [diff] [blame] | 59 | Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */ |
| 60 | } PyOSErrorObject; |
| 61 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 62 | typedef struct { |
| 63 | PyException_HEAD |
| 64 | PyObject *value; |
| 65 | } PyStopIterationObject; |
| 66 | |
Antoine Pitrou | 6b4883d | 2011-10-12 02:54:14 +0200 | [diff] [blame] | 67 | /* Compatibility typedefs */ |
| 68 | typedef PyOSErrorObject PyEnvironmentErrorObject; |
| 69 | #ifdef MS_WINDOWS |
| 70 | typedef PyOSErrorObject PyWindowsErrorObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 71 | #endif |
Antoine Pitrou | 6b4883d | 2011-10-12 02:54:14 +0200 | [diff] [blame] | 72 | #endif /* !Py_LIMITED_API */ |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 73 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 74 | /* Error handling definitions */ |
| 75 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 76 | PyAPI_FUNC(void) PyErr_SetNone(PyObject *); |
| 77 | PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *); |
Victor Stinner | 257d38f | 2010-10-09 10:12:11 +0000 | [diff] [blame] | 78 | PyAPI_FUNC(void) PyErr_SetString( |
| 79 | PyObject *exception, |
| 80 | const char *string /* decoded from utf-8 */ |
| 81 | ); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 82 | PyAPI_FUNC(PyObject *) PyErr_Occurred(void); |
| 83 | PyAPI_FUNC(void) PyErr_Clear(void); |
| 84 | PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **); |
| 85 | PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); |
Martin v. Löwis | aa2efcb | 2012-04-19 14:33:43 +0200 | [diff] [blame] | 86 | PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **); |
| 87 | PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *); |
Brett Cannon | b94767f | 2011-02-22 20:15:44 +0000 | [diff] [blame] | 88 | |
| 89 | #if defined(__clang__) || \ |
Benjamin Peterson | ca75b00 | 2012-06-03 18:15:15 -0700 | [diff] [blame] | 90 | (defined(__GNUC_MAJOR__) && \ |
Brett Cannon | b94767f | 2011-02-22 20:15:44 +0000 | [diff] [blame] | 91 | ((__GNUC_MAJOR__ >= 3) || \ |
| 92 | (__GNUC_MAJOR__ == 2) && (__GNUC_MINOR__ >= 5))) |
| 93 | #define _Py_NO_RETURN __attribute__((__noreturn__)) |
| 94 | #else |
| 95 | #define _Py_NO_RETURN |
| 96 | #endif |
| 97 | |
| 98 | PyAPI_FUNC(void) Py_FatalError(const char *message) _Py_NO_RETURN; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 99 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 100 | #if defined(Py_DEBUG) || defined(Py_LIMITED_API) |
Raymond Hettinger | 5ba0cbe | 2005-08-06 18:31:24 +0000 | [diff] [blame] | 101 | #define _PyErr_OCCURRED() PyErr_Occurred() |
| 102 | #else |
| 103 | #define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type) |
| 104 | #endif |
| 105 | |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 106 | /* Error testing and normalization */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 107 | PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); |
| 108 | PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); |
| 109 | PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 110 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 111 | /* Traceback manipulation (PEP 3134) */ |
| 112 | PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *); |
| 113 | PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *); |
| 114 | |
| 115 | /* Cause manipulation (PEP 3134) */ |
| 116 | PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *); |
| 117 | PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *); |
| 118 | |
| 119 | /* Context manipulation (PEP 3134) */ |
| 120 | PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *); |
| 121 | PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *); |
| 122 | |
| 123 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 124 | /* */ |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 125 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 126 | #define PyExceptionClass_Check(x) \ |
| 127 | (PyType_Check((x)) && \ |
| 128 | PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 129 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 130 | #define PyExceptionInstance_Check(x) \ |
| 131 | PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 132 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 133 | #define PyExceptionClass_Name(x) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 134 | ((char *)(((PyTypeObject*)(x))->tp_name)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 135 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 136 | #define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 137 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 138 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 139 | /* Predefined exceptions */ |
Guido van Rossum | 5c600e1 | 1990-10-14 20:00:25 +0000 | [diff] [blame] | 140 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 141 | PyAPI_DATA(PyObject *) PyExc_BaseException; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 142 | PyAPI_DATA(PyObject *) PyExc_Exception; |
| 143 | PyAPI_DATA(PyObject *) PyExc_StopIteration; |
Phillip J. Eby | 0d6615f | 2005-08-02 00:46:46 +0000 | [diff] [blame] | 144 | PyAPI_DATA(PyObject *) PyExc_GeneratorExit; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 145 | PyAPI_DATA(PyObject *) PyExc_ArithmeticError; |
| 146 | PyAPI_DATA(PyObject *) PyExc_LookupError; |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 147 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 148 | PyAPI_DATA(PyObject *) PyExc_AssertionError; |
| 149 | PyAPI_DATA(PyObject *) PyExc_AttributeError; |
Antoine Pitrou | 6b4883d | 2011-10-12 02:54:14 +0200 | [diff] [blame] | 150 | PyAPI_DATA(PyObject *) PyExc_BufferError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 151 | PyAPI_DATA(PyObject *) PyExc_EOFError; |
| 152 | PyAPI_DATA(PyObject *) PyExc_FloatingPointError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 153 | PyAPI_DATA(PyObject *) PyExc_OSError; |
| 154 | PyAPI_DATA(PyObject *) PyExc_ImportError; |
Brett Cannon | b1611e2 | 2013-06-12 16:59:46 -0400 | [diff] [blame^] | 155 | PyAPI_DATA(PyObject *) PyExc_ModuleNotFoundError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 156 | PyAPI_DATA(PyObject *) PyExc_IndexError; |
| 157 | PyAPI_DATA(PyObject *) PyExc_KeyError; |
| 158 | PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt; |
| 159 | PyAPI_DATA(PyObject *) PyExc_MemoryError; |
| 160 | PyAPI_DATA(PyObject *) PyExc_NameError; |
| 161 | PyAPI_DATA(PyObject *) PyExc_OverflowError; |
| 162 | PyAPI_DATA(PyObject *) PyExc_RuntimeError; |
| 163 | PyAPI_DATA(PyObject *) PyExc_NotImplementedError; |
| 164 | PyAPI_DATA(PyObject *) PyExc_SyntaxError; |
| 165 | PyAPI_DATA(PyObject *) PyExc_IndentationError; |
| 166 | PyAPI_DATA(PyObject *) PyExc_TabError; |
| 167 | PyAPI_DATA(PyObject *) PyExc_ReferenceError; |
| 168 | PyAPI_DATA(PyObject *) PyExc_SystemError; |
| 169 | PyAPI_DATA(PyObject *) PyExc_SystemExit; |
| 170 | PyAPI_DATA(PyObject *) PyExc_TypeError; |
| 171 | PyAPI_DATA(PyObject *) PyExc_UnboundLocalError; |
| 172 | PyAPI_DATA(PyObject *) PyExc_UnicodeError; |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 173 | PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError; |
| 174 | PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError; |
| 175 | PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 176 | PyAPI_DATA(PyObject *) PyExc_ValueError; |
| 177 | PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError; |
Antoine Pitrou | 6b4883d | 2011-10-12 02:54:14 +0200 | [diff] [blame] | 178 | |
| 179 | PyAPI_DATA(PyObject *) PyExc_BlockingIOError; |
| 180 | PyAPI_DATA(PyObject *) PyExc_BrokenPipeError; |
| 181 | PyAPI_DATA(PyObject *) PyExc_ChildProcessError; |
| 182 | PyAPI_DATA(PyObject *) PyExc_ConnectionError; |
| 183 | PyAPI_DATA(PyObject *) PyExc_ConnectionAbortedError; |
| 184 | PyAPI_DATA(PyObject *) PyExc_ConnectionRefusedError; |
| 185 | PyAPI_DATA(PyObject *) PyExc_ConnectionResetError; |
| 186 | PyAPI_DATA(PyObject *) PyExc_FileExistsError; |
| 187 | PyAPI_DATA(PyObject *) PyExc_FileNotFoundError; |
| 188 | PyAPI_DATA(PyObject *) PyExc_InterruptedError; |
| 189 | PyAPI_DATA(PyObject *) PyExc_IsADirectoryError; |
| 190 | PyAPI_DATA(PyObject *) PyExc_NotADirectoryError; |
| 191 | PyAPI_DATA(PyObject *) PyExc_PermissionError; |
| 192 | PyAPI_DATA(PyObject *) PyExc_ProcessLookupError; |
| 193 | PyAPI_DATA(PyObject *) PyExc_TimeoutError; |
| 194 | |
| 195 | |
| 196 | /* Compatibility aliases */ |
| 197 | PyAPI_DATA(PyObject *) PyExc_EnvironmentError; |
| 198 | PyAPI_DATA(PyObject *) PyExc_IOError; |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 199 | #ifdef MS_WINDOWS |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 200 | PyAPI_DATA(PyObject *) PyExc_WindowsError; |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 201 | #endif |
Martin v. Löwis | 79acb9e | 2002-12-06 12:48:53 +0000 | [diff] [blame] | 202 | #ifdef __VMS |
Neal Norwitz | 21d896c | 2003-07-01 20:15:21 +0000 | [diff] [blame] | 203 | PyAPI_DATA(PyObject *) PyExc_VMSError; |
Martin v. Löwis | 79acb9e | 2002-12-06 12:48:53 +0000 | [diff] [blame] | 204 | #endif |
Guido van Rossum | 3e55cb6 | 1990-10-21 22:09:30 +0000 | [diff] [blame] | 205 | |
Thomas Wouters | 89d996e | 2007-09-08 17:39:28 +0000 | [diff] [blame] | 206 | PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst; |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 207 | |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 208 | /* Predefined warning categories */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 209 | PyAPI_DATA(PyObject *) PyExc_Warning; |
| 210 | PyAPI_DATA(PyObject *) PyExc_UserWarning; |
| 211 | PyAPI_DATA(PyObject *) PyExc_DeprecationWarning; |
| 212 | PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning; |
| 213 | PyAPI_DATA(PyObject *) PyExc_SyntaxWarning; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 214 | PyAPI_DATA(PyObject *) PyExc_RuntimeWarning; |
Barry Warsaw | 9f00739 | 2002-08-14 15:51:29 +0000 | [diff] [blame] | 215 | PyAPI_DATA(PyObject *) PyExc_FutureWarning; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 216 | PyAPI_DATA(PyObject *) PyExc_ImportWarning; |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 217 | PyAPI_DATA(PyObject *) PyExc_UnicodeWarning; |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 218 | PyAPI_DATA(PyObject *) PyExc_BytesWarning; |
Georg Brandl | 08be72d | 2010-10-24 15:11:22 +0000 | [diff] [blame] | 219 | PyAPI_DATA(PyObject *) PyExc_ResourceWarning; |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 220 | |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 221 | |
Guido van Rossum | 5c600e1 | 1990-10-14 20:00:25 +0000 | [diff] [blame] | 222 | /* Convenience functions */ |
| 223 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 224 | PyAPI_FUNC(int) PyErr_BadArgument(void); |
| 225 | PyAPI_FUNC(PyObject *) PyErr_NoMemory(void); |
| 226 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 227 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 228 | PyObject *, PyObject *); |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 229 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename( |
Victor Stinner | 257d38f | 2010-10-09 10:12:11 +0000 | [diff] [blame] | 230 | PyObject *exc, |
| 231 | const char *filename /* decoded from the filesystem encoding */ |
| 232 | ); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 233 | #if defined(MS_WINDOWS) && !defined(Py_LIMITED_API) |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 234 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 235 | PyObject *, const Py_UNICODE *); |
Hirokazu Yamamoto | 8223c24 | 2009-05-17 04:21:53 +0000 | [diff] [blame] | 236 | #endif /* MS_WINDOWS */ |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 237 | |
Victor Stinner | 1205f27 | 2010-09-11 00:54:47 +0000 | [diff] [blame] | 238 | PyAPI_FUNC(PyObject *) PyErr_Format( |
| 239 | PyObject *exception, |
| 240 | const char *format, /* ASCII-encoded string */ |
| 241 | ... |
| 242 | ); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 243 | |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 244 | #ifdef MS_WINDOWS |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 245 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 246 | int ierr, |
Victor Stinner | b9cb21e | 2010-12-28 00:59:03 +0000 | [diff] [blame] | 247 | const char *filename /* decoded from the filesystem encoding */ |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 248 | ); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 249 | #ifndef Py_LIMITED_API |
| 250 | /* XXX redeclare to use WSTRING */ |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 251 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 252 | int, const Py_UNICODE *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 253 | #endif |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 254 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 255 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 256 | PyObject *,int, PyObject *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 257 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 258 | PyObject *exc, |
| 259 | int ierr, |
Victor Stinner | b9cb21e | 2010-12-28 00:59:03 +0000 | [diff] [blame] | 260 | const char *filename /* decoded from the filesystem encoding */ |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 261 | ); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 262 | #ifndef Py_LIMITED_API |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 263 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 264 | PyObject *,int, const Py_UNICODE *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 265 | #endif |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 266 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 267 | #endif /* MS_WINDOWS */ |
Guido van Rossum | 3e55cb6 | 1990-10-21 22:09:30 +0000 | [diff] [blame] | 268 | |
Brett Cannon | 79ec55e | 2012-04-12 20:24:54 -0400 | [diff] [blame] | 269 | PyAPI_FUNC(PyObject *) PyErr_SetExcWithArgsKwargs(PyObject *, PyObject *, |
| 270 | PyObject *); |
Brian Curtin | 09b86d1 | 2012-04-17 16:57:09 -0500 | [diff] [blame] | 271 | PyAPI_FUNC(PyObject *) PyErr_SetImportError(PyObject *, PyObject *, |
| 272 | PyObject *); |
Brett Cannon | 79ec55e | 2012-04-12 20:24:54 -0400 | [diff] [blame] | 273 | |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 274 | /* Export the old function so that the existing API remains available: */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 275 | PyAPI_FUNC(void) PyErr_BadInternalCall(void); |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 276 | PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno); |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 277 | /* Mask the old API with a call to the new API for code compiled under |
| 278 | Python 2.0: */ |
| 279 | #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__) |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 280 | |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 281 | /* Function to create a new exception */ |
Georg Brandl | 1e28a27 | 2009-12-28 08:41:01 +0000 | [diff] [blame] | 282 | PyAPI_FUNC(PyObject *) PyErr_NewException( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 283 | const char *name, PyObject *base, PyObject *dict); |
Georg Brandl | 1e28a27 | 2009-12-28 08:41:01 +0000 | [diff] [blame] | 284 | PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 285 | const char *name, const char *doc, PyObject *base, PyObject *dict); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 286 | PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *); |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 287 | |
Barry Warsaw | f3f41a9 | 1997-01-03 00:15:03 +0000 | [diff] [blame] | 288 | /* In sigcheck.c or signalmodule.c */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 289 | PyAPI_FUNC(int) PyErr_CheckSignals(void); |
| 290 | PyAPI_FUNC(void) PyErr_SetInterrupt(void); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 291 | |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 292 | /* In signalmodule.c */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 293 | #ifndef Py_LIMITED_API |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 294 | int PySignal_SetWakeupFd(int fd); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 295 | #endif |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 296 | |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 297 | /* Support for adding program text to SyntaxErrors */ |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 298 | PyAPI_FUNC(void) PyErr_SyntaxLocation( |
| 299 | const char *filename, /* decoded from the filesystem encoding */ |
| 300 | int lineno); |
| 301 | PyAPI_FUNC(void) PyErr_SyntaxLocationEx( |
| 302 | const char *filename, /* decoded from the filesystem encoding */ |
| 303 | int lineno, |
| 304 | int col_offset); |
| 305 | PyAPI_FUNC(PyObject *) PyErr_ProgramText( |
| 306 | const char *filename, /* decoded from the filesystem encoding */ |
| 307 | int lineno); |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 308 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 309 | /* The following functions are used to create and modify unicode |
| 310 | exceptions from C */ |
Walter Dörwald | bf73db8 | 2002-11-21 20:08:33 +0000 | [diff] [blame] | 311 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 312 | /* create a UnicodeDecodeError object */ |
| 313 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 314 | const char *encoding, /* UTF-8 encoded string */ |
| 315 | const char *object, |
| 316 | Py_ssize_t length, |
| 317 | Py_ssize_t start, |
| 318 | Py_ssize_t end, |
| 319 | const char *reason /* UTF-8 encoded string */ |
| 320 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 321 | |
| 322 | /* create a UnicodeEncodeError object */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 323 | #ifndef Py_LIMITED_API |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 324 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 325 | const char *encoding, /* UTF-8 encoded string */ |
| 326 | const Py_UNICODE *object, |
| 327 | Py_ssize_t length, |
| 328 | Py_ssize_t start, |
| 329 | Py_ssize_t end, |
| 330 | const char *reason /* UTF-8 encoded string */ |
| 331 | ); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 332 | #endif |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 333 | |
| 334 | /* create a UnicodeTranslateError object */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 335 | #ifndef Py_LIMITED_API |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 336 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 337 | const Py_UNICODE *object, |
| 338 | Py_ssize_t length, |
| 339 | Py_ssize_t start, |
| 340 | Py_ssize_t end, |
| 341 | const char *reason /* UTF-8 encoded string */ |
| 342 | ); |
Martin v. Löwis | d63a3b8 | 2011-09-28 07:41:54 +0200 | [diff] [blame] | 343 | PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( |
| 344 | PyObject *object, |
| 345 | Py_ssize_t start, |
| 346 | Py_ssize_t end, |
| 347 | const char *reason /* UTF-8 encoded string */ |
| 348 | ); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 349 | #endif |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 350 | |
| 351 | /* get the encoding attribute */ |
| 352 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *); |
| 353 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 354 | |
| 355 | /* get the object attribute */ |
| 356 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *); |
| 357 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *); |
| 358 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *); |
| 359 | |
| 360 | /* get the value of the start attribute (the int * may not be NULL) |
| 361 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 362 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); |
| 363 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); |
| 364 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 365 | |
| 366 | /* assign a new value to the start attribute |
| 367 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 368 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t); |
| 369 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t); |
| 370 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 371 | |
| 372 | /* get the value of the end attribute (the int *may not be NULL) |
| 373 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 374 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 375 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 376 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 377 | |
| 378 | /* assign a new value to the end attribute |
| 379 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 380 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t); |
| 381 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t); |
| 382 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 383 | |
| 384 | /* get the value of the reason attribute */ |
| 385 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *); |
| 386 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *); |
| 387 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *); |
| 388 | |
| 389 | /* assign a new value to the reason attribute |
| 390 | return 0 on success, -1 on failure */ |
| 391 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 392 | PyObject *exc, |
| 393 | const char *reason /* UTF-8 encoded string */ |
| 394 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 395 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 396 | PyObject *exc, |
| 397 | const char *reason /* UTF-8 encoded string */ |
| 398 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 399 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 400 | PyObject *exc, |
| 401 | const char *reason /* UTF-8 encoded string */ |
| 402 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 403 | |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 404 | /* These APIs aren't really part of the error implementation, but |
| 405 | often needed to format error messages; the native C lib APIs are |
| 406 | not available on all platforms, which is why we provide emulations |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 407 | for those platforms in Python/mysnprintf.c, |
| 408 | WARNING: The return value of snprintf varies across platforms; do |
| 409 | not rely on any particular behavior; eventually the C99 defn may |
| 410 | be reliable. |
| 411 | */ |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 412 | #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF) |
| 413 | # define HAVE_SNPRINTF |
| 414 | # define snprintf _snprintf |
| 415 | # define vsnprintf _vsnprintf |
| 416 | #endif |
Marc-André Lemburg | 03d1b18 | 2001-07-31 18:05:33 +0000 | [diff] [blame] | 417 | |
Marc-André Lemburg | cecd9e0 | 2001-07-31 14:23:52 +0000 | [diff] [blame] | 418 | #include <stdarg.h> |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 419 | PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 420 | Py_GCC_ATTRIBUTE((format(printf, 3, 4))); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 421 | PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 422 | Py_GCC_ATTRIBUTE((format(printf, 3, 0))); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 423 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 424 | #ifdef __cplusplus |
| 425 | } |
| 426 | #endif |
| 427 | #endif /* !Py_ERRORS_H */ |