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