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