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;\ |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 11 | PyObject *args; PyObject *traceback;\ |
| 12 | PyObject *context; PyObject *cause; |
| 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 | |
Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +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 | |
Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +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) \ |
| 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( |
| 178 | PyObject *, PyObject *); |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 179 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, const char *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 180 | #ifdef Py_WIN_WIDE_FILENAMES |
| 181 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 182 | PyObject *, const Py_UNICODE *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 183 | #endif /* Py_WIN_WIDE_FILENAMES */ |
| 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( |
| 189 | int, const char *); |
| 190 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( |
| 191 | int, const char *); |
| 192 | #ifdef Py_WIN_WIDE_FILENAMES |
| 193 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename( |
| 194 | int, const Py_UNICODE *); |
| 195 | #endif /* Py_WIN_WIDE_FILENAMES */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 196 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 197 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( |
| 198 | PyObject *,int, PyObject *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 199 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename( |
Thomas Heller | 085358a | 2002-07-29 14:27:41 +0000 | [diff] [blame] | 200 | PyObject *,int, const char *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 201 | #ifdef Py_WIN_WIDE_FILENAMES |
| 202 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename( |
| 203 | PyObject *,int, const Py_UNICODE *); |
| 204 | #endif /* Py_WIN_WIDE_FILENAMES */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 205 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 206 | #endif /* MS_WINDOWS */ |
Guido van Rossum | 3e55cb6 | 1990-10-21 22:09:30 +0000 | [diff] [blame] | 207 | |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 208 | /* Export the old function so that the existing API remains available: */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 209 | PyAPI_FUNC(void) PyErr_BadInternalCall(void); |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 210 | PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno); |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 211 | /* Mask the old API with a call to the new API for code compiled under |
| 212 | Python 2.0: */ |
| 213 | #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__) |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 214 | |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 215 | /* Function to create a new exception */ |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 216 | PyAPI_FUNC(PyObject *) PyErr_NewException(const char *name, PyObject *base, |
Fred Drake | d5c84ed | 2000-07-08 17:25:55 +0000 | [diff] [blame] | 217 | PyObject *dict); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 218 | PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *); |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 219 | |
Barry Warsaw | f3f41a9 | 1997-01-03 00:15:03 +0000 | [diff] [blame] | 220 | /* In sigcheck.c or signalmodule.c */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 221 | PyAPI_FUNC(int) PyErr_CheckSignals(void); |
| 222 | PyAPI_FUNC(void) PyErr_SetInterrupt(void); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 223 | |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 224 | /* In signalmodule.c */ |
| 225 | int PySignal_SetWakeupFd(int fd); |
| 226 | |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 227 | /* Support for adding program text to SyntaxErrors */ |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 228 | PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int); |
| 229 | PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int); |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 230 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 231 | /* The following functions are used to create and modify unicode |
| 232 | exceptions from C */ |
Walter Dörwald | bf73db8 | 2002-11-21 20:08:33 +0000 | [diff] [blame] | 233 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 234 | /* create a UnicodeDecodeError object */ |
| 235 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 236 | 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] | 237 | |
| 238 | /* create a UnicodeEncodeError object */ |
| 239 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 240 | 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] | 241 | |
| 242 | /* create a UnicodeTranslateError object */ |
| 243 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create( |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 244 | 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] | 245 | |
| 246 | /* get the encoding attribute */ |
| 247 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *); |
| 248 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 249 | |
| 250 | /* get the object attribute */ |
| 251 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *); |
| 252 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *); |
| 253 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *); |
| 254 | |
| 255 | /* get the value of the start attribute (the int * may not be NULL) |
| 256 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 257 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); |
| 258 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); |
| 259 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 260 | |
| 261 | /* assign a new value to the start attribute |
| 262 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 263 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t); |
| 264 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t); |
| 265 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 266 | |
| 267 | /* get the value of the end attribute (the int *may not be NULL) |
| 268 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 269 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 270 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *); |
| 271 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 272 | |
| 273 | /* assign a new value to the end attribute |
| 274 | return 0 on success, -1 on failure */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 275 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t); |
| 276 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t); |
| 277 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 278 | |
| 279 | /* get the value of the reason attribute */ |
| 280 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *); |
| 281 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *); |
| 282 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *); |
| 283 | |
| 284 | /* assign a new value to the reason attribute |
| 285 | return 0 on success, -1 on failure */ |
| 286 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason( |
| 287 | PyObject *, const char *); |
| 288 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason( |
| 289 | PyObject *, const char *); |
| 290 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( |
| 291 | PyObject *, const char *); |
| 292 | |
| 293 | |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 294 | /* These APIs aren't really part of the error implementation, but |
| 295 | often needed to format error messages; the native C lib APIs are |
| 296 | not available on all platforms, which is why we provide emulations |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 297 | for those platforms in Python/mysnprintf.c, |
| 298 | WARNING: The return value of snprintf varies across platforms; do |
| 299 | not rely on any particular behavior; eventually the C99 defn may |
| 300 | be reliable. |
| 301 | */ |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 302 | #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF) |
| 303 | # define HAVE_SNPRINTF |
| 304 | # define snprintf _snprintf |
| 305 | # define vsnprintf _vsnprintf |
| 306 | #endif |
Marc-André Lemburg | 03d1b18 | 2001-07-31 18:05:33 +0000 | [diff] [blame] | 307 | |
Marc-André Lemburg | cecd9e0 | 2001-07-31 14:23:52 +0000 | [diff] [blame] | 308 | #include <stdarg.h> |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 309 | PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...) |
Neil Schemenauer | 96aa0ac | 2002-09-15 14:09:54 +0000 | [diff] [blame] | 310 | Py_GCC_ATTRIBUTE((format(printf, 3, 4))); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 311 | PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) |
Neil Schemenauer | 96aa0ac | 2002-09-15 14:09:54 +0000 | [diff] [blame] | 312 | Py_GCC_ATTRIBUTE((format(printf, 3, 0))); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 313 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 314 | #ifdef __cplusplus |
| 315 | } |
| 316 | #endif |
| 317 | #endif /* !Py_ERRORS_H */ |