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 *); |
Raymond Hettinger | 69492da | 2013-09-02 15:59:26 -0700 | [diff] [blame] | 78 | PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); |
Victor Stinner | 257d38f | 2010-10-09 10:12:11 +0000 | [diff] [blame] | 79 | PyAPI_FUNC(void) PyErr_SetString( |
| 80 | PyObject *exception, |
| 81 | const char *string /* decoded from utf-8 */ |
| 82 | ); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 83 | PyAPI_FUNC(PyObject *) PyErr_Occurred(void); |
| 84 | PyAPI_FUNC(void) PyErr_Clear(void); |
| 85 | PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **); |
| 86 | PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); |
Martin v. Löwis | aa2efcb | 2012-04-19 14:33:43 +0200 | [diff] [blame] | 87 | PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **); |
| 88 | PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *); |
Brett Cannon | b94767f | 2011-02-22 20:15:44 +0000 | [diff] [blame] | 89 | |
| 90 | #if defined(__clang__) || \ |
Benjamin Peterson | ca75b00 | 2012-06-03 18:15:15 -0700 | [diff] [blame] | 91 | (defined(__GNUC_MAJOR__) && \ |
Brett Cannon | b94767f | 2011-02-22 20:15:44 +0000 | [diff] [blame] | 92 | ((__GNUC_MAJOR__ >= 3) || \ |
| 93 | (__GNUC_MAJOR__ == 2) && (__GNUC_MINOR__ >= 5))) |
| 94 | #define _Py_NO_RETURN __attribute__((__noreturn__)) |
| 95 | #else |
| 96 | #define _Py_NO_RETURN |
| 97 | #endif |
| 98 | |
| 99 | PyAPI_FUNC(void) Py_FatalError(const char *message) _Py_NO_RETURN; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 100 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 101 | #if defined(Py_DEBUG) || defined(Py_LIMITED_API) |
Raymond Hettinger | 5ba0cbe | 2005-08-06 18:31:24 +0000 | [diff] [blame] | 102 | #define _PyErr_OCCURRED() PyErr_Occurred() |
| 103 | #else |
Antoine Pitrou | 59c900d | 2013-10-07 20:38:51 +0200 | [diff] [blame] | 104 | #define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type) |
Raymond Hettinger | 5ba0cbe | 2005-08-06 18:31:24 +0000 | [diff] [blame] | 105 | #endif |
| 106 | |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 107 | /* Error testing and normalization */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 108 | PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); |
| 109 | PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); |
| 110 | PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 111 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 112 | /* Traceback manipulation (PEP 3134) */ |
| 113 | PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *); |
| 114 | PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *); |
| 115 | |
| 116 | /* Cause manipulation (PEP 3134) */ |
| 117 | PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *); |
| 118 | PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *); |
| 119 | |
| 120 | /* Context manipulation (PEP 3134) */ |
| 121 | PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *); |
| 122 | PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *); |
| 123 | |
| 124 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 125 | /* */ |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 126 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 127 | #define PyExceptionClass_Check(x) \ |
| 128 | (PyType_Check((x)) && \ |
| 129 | PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 130 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 131 | #define PyExceptionInstance_Check(x) \ |
| 132 | PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 133 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 134 | #define PyExceptionClass_Name(x) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 135 | ((char *)(((PyTypeObject*)(x))->tp_name)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 136 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 137 | #define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type)) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 138 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 139 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 140 | /* Predefined exceptions */ |
Guido van Rossum | 5c600e1 | 1990-10-14 20:00:25 +0000 | [diff] [blame] | 141 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 142 | PyAPI_DATA(PyObject *) PyExc_BaseException; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 143 | PyAPI_DATA(PyObject *) PyExc_Exception; |
| 144 | PyAPI_DATA(PyObject *) PyExc_StopIteration; |
Phillip J. Eby | 0d6615f | 2005-08-02 00:46:46 +0000 | [diff] [blame] | 145 | PyAPI_DATA(PyObject *) PyExc_GeneratorExit; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 146 | PyAPI_DATA(PyObject *) PyExc_ArithmeticError; |
| 147 | PyAPI_DATA(PyObject *) PyExc_LookupError; |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 148 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 149 | PyAPI_DATA(PyObject *) PyExc_AssertionError; |
| 150 | PyAPI_DATA(PyObject *) PyExc_AttributeError; |
Antoine Pitrou | 6b4883d | 2011-10-12 02:54:14 +0200 | [diff] [blame] | 151 | PyAPI_DATA(PyObject *) PyExc_BufferError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 152 | PyAPI_DATA(PyObject *) PyExc_EOFError; |
| 153 | PyAPI_DATA(PyObject *) PyExc_FloatingPointError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 154 | PyAPI_DATA(PyObject *) PyExc_OSError; |
| 155 | PyAPI_DATA(PyObject *) PyExc_ImportError; |
| 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 | |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 288 | /* In exceptions.c */ |
| 289 | #ifndef Py_LIMITED_API |
| 290 | /* Helper that attempts to replace the current exception with one of the |
| 291 | * same type but with a prefix added to the exception text. The resulting |
| 292 | * exception description looks like: |
| 293 | * |
| 294 | * prefix (exc_type: original_exc_str) |
| 295 | * |
| 296 | * Only some exceptions can be safely replaced. If the function determines |
| 297 | * it isn't safe to perform the replacement, it will leave the original |
| 298 | * unmodified exception in place. |
| 299 | * |
| 300 | * Returns a borrowed reference to the new exception (if any), NULL if the |
| 301 | * existing exception was left in place. |
| 302 | */ |
| 303 | PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause( |
| 304 | const char *prefix_format, /* ASCII-encoded string */ |
| 305 | ... |
| 306 | ); |
| 307 | #endif |
| 308 | |
| 309 | |
Barry Warsaw | f3f41a9 | 1997-01-03 00:15:03 +0000 | [diff] [blame] | 310 | /* In sigcheck.c or signalmodule.c */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 311 | PyAPI_FUNC(int) PyErr_CheckSignals(void); |
| 312 | PyAPI_FUNC(void) PyErr_SetInterrupt(void); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 313 | |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 314 | /* In signalmodule.c */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 315 | #ifndef Py_LIMITED_API |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 316 | int PySignal_SetWakeupFd(int fd); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 317 | #endif |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 318 | |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 319 | /* Support for adding program text to SyntaxErrors */ |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 320 | PyAPI_FUNC(void) PyErr_SyntaxLocation( |
| 321 | const char *filename, /* decoded from the filesystem encoding */ |
| 322 | int lineno); |
| 323 | PyAPI_FUNC(void) PyErr_SyntaxLocationEx( |
| 324 | const char *filename, /* decoded from the filesystem encoding */ |
| 325 | int lineno, |
| 326 | int col_offset); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 327 | PyAPI_FUNC(void) PyErr_SyntaxLocationObject( |
| 328 | PyObject *filename, |
| 329 | int lineno, |
| 330 | int col_offset); |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 331 | PyAPI_FUNC(PyObject *) PyErr_ProgramText( |
| 332 | const char *filename, /* decoded from the filesystem encoding */ |
| 333 | int lineno); |
Victor Stinner | 14e461d | 2013-08-26 22:28:21 +0200 | [diff] [blame] | 334 | PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( |
| 335 | PyObject *filename, |
| 336 | int lineno); |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 337 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 338 | /* The following functions are used to create and modify unicode |
| 339 | exceptions from C */ |
Walter Dörwald | bf73db8 | 2002-11-21 20:08:33 +0000 | [diff] [blame] | 340 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 341 | /* create a UnicodeDecodeError object */ |
| 342 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 343 | const char *encoding, /* UTF-8 encoded string */ |
| 344 | const char *object, |
| 345 | Py_ssize_t length, |
| 346 | Py_ssize_t start, |
| 347 | Py_ssize_t end, |
| 348 | const char *reason /* UTF-8 encoded string */ |
| 349 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 350 | |
| 351 | /* create a UnicodeEncodeError object */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 352 | #ifndef Py_LIMITED_API |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 353 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 354 | const char *encoding, /* UTF-8 encoded string */ |
| 355 | const Py_UNICODE *object, |
| 356 | Py_ssize_t length, |
| 357 | Py_ssize_t start, |
| 358 | Py_ssize_t end, |
| 359 | const char *reason /* UTF-8 encoded string */ |
| 360 | ); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 361 | #endif |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 362 | |
| 363 | /* create a UnicodeTranslateError object */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 364 | #ifndef Py_LIMITED_API |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 365 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 366 | const Py_UNICODE *object, |
| 367 | Py_ssize_t length, |
| 368 | Py_ssize_t start, |
| 369 | Py_ssize_t end, |
| 370 | const char *reason /* UTF-8 encoded string */ |
| 371 | ); |
Martin v. Löwis | d63a3b8 | 2011-09-28 07:41:54 +0200 | [diff] [blame] | 372 | PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( |
| 373 | PyObject *object, |
| 374 | Py_ssize_t start, |
| 375 | Py_ssize_t end, |
| 376 | const char *reason /* UTF-8 encoded string */ |
| 377 | ); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 378 | #endif |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 379 | |
| 380 | /* get the encoding attribute */ |
| 381 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *); |
| 382 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 383 | |
| 384 | /* get the object attribute */ |
| 385 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *); |
| 386 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *); |
| 387 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *); |
| 388 | |
| 389 | /* get the value of the start attribute (the int * may not be NULL) |
| 390 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 391 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); |
| 392 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); |
| 393 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 394 | |
| 395 | /* assign a new value to the start attribute |
| 396 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 397 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t); |
| 398 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t); |
| 399 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 400 | |
| 401 | /* get the value of the end attribute (the int *may not be NULL) |
| 402 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 403 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 404 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 405 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 406 | |
| 407 | /* assign a new value to the end attribute |
| 408 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 409 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t); |
| 410 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t); |
| 411 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 412 | |
| 413 | /* get the value of the reason attribute */ |
| 414 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *); |
| 415 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *); |
| 416 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *); |
| 417 | |
| 418 | /* assign a new value to the reason attribute |
| 419 | return 0 on success, -1 on failure */ |
| 420 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 421 | PyObject *exc, |
| 422 | const char *reason /* UTF-8 encoded string */ |
| 423 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 424 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 425 | PyObject *exc, |
| 426 | const char *reason /* UTF-8 encoded string */ |
| 427 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 428 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( |
Victor Stinner | 555a24f | 2010-12-27 01:49:26 +0000 | [diff] [blame] | 429 | PyObject *exc, |
| 430 | const char *reason /* UTF-8 encoded string */ |
| 431 | ); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 432 | |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 433 | /* These APIs aren't really part of the error implementation, but |
| 434 | often needed to format error messages; the native C lib APIs are |
| 435 | not available on all platforms, which is why we provide emulations |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 436 | for those platforms in Python/mysnprintf.c, |
| 437 | WARNING: The return value of snprintf varies across platforms; do |
| 438 | not rely on any particular behavior; eventually the C99 defn may |
| 439 | be reliable. |
| 440 | */ |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 441 | #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF) |
| 442 | # define HAVE_SNPRINTF |
| 443 | # define snprintf _snprintf |
| 444 | # define vsnprintf _vsnprintf |
| 445 | #endif |
Marc-André Lemburg | 03d1b18 | 2001-07-31 18:05:33 +0000 | [diff] [blame] | 446 | |
Marc-André Lemburg | cecd9e0 | 2001-07-31 14:23:52 +0000 | [diff] [blame] | 447 | #include <stdarg.h> |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 448 | 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] | 449 | Py_GCC_ATTRIBUTE((format(printf, 3, 4))); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 450 | 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] | 451 | Py_GCC_ATTRIBUTE((format(printf, 3, 0))); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 452 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 453 | #ifdef __cplusplus |
| 454 | } |
| 455 | #endif |
| 456 | #endif /* !Py_ERRORS_H */ |