Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 2 | /* Error handling */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 3 | |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | f22120a | 1990-12-20 23:05:40 +0000 | [diff] [blame] | 5 | |
Guido van Rossum | 53e8d44 | 1995-03-09 12:11:31 +0000 | [diff] [blame] | 6 | #ifndef __STDC__ |
Guido van Rossum | 7844e38 | 1997-04-11 20:44:04 +0000 | [diff] [blame] | 7 | #ifndef MS_WINDOWS |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 8 | extern char *strerror(int); |
Guido van Rossum | 53e8d44 | 1995-03-09 12:11:31 +0000 | [diff] [blame] | 9 | #endif |
Guido van Rossum | 7844e38 | 1997-04-11 20:44:04 +0000 | [diff] [blame] | 10 | #endif |
Guido van Rossum | f5401bd | 1990-11-02 17:50:28 +0000 | [diff] [blame] | 11 | |
Martin v. Löwis | 6238d2b | 2002-06-30 15:26:10 +0000 | [diff] [blame] | 12 | #ifdef MS_WINDOWS |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 13 | #include <windows.h> |
| 14 | #include <winbase.h> |
Guido van Rossum | 743007d | 1999-04-21 15:27:31 +0000 | [diff] [blame] | 15 | #endif |
| 16 | |
Jeremy Hylton | b69a27e | 2000-09-01 03:49:47 +0000 | [diff] [blame] | 17 | #include <ctype.h> |
| 18 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 24 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 25 | PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback) |
Guido van Rossum | 1ae940a | 1995-01-02 19:04:15 +0000 | [diff] [blame] | 26 | { |
Guido van Rossum | 885553e | 1998-12-21 18:33:30 +0000 | [diff] [blame] | 27 | PyThreadState *tstate = PyThreadState_GET(); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 28 | PyObject *oldtype, *oldvalue, *oldtraceback; |
Guido van Rossum | 1ae940a | 1995-01-02 19:04:15 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 30 | if (traceback != NULL && !PyTraceBack_Check(traceback)) { |
| 31 | /* XXX Should never happen -- fatal error instead? */ |
Guido van Rossum | 1a5e21e | 2006-02-28 21:57:43 +0000 | [diff] [blame] | 32 | /* Well, it could be None. */ |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 33 | Py_DECREF(traceback); |
| 34 | traceback = NULL; |
| 35 | } |
| 36 | |
| 37 | /* Save these in locals to safeguard against recursive |
| 38 | invocation through Py_XDECREF */ |
| 39 | oldtype = tstate->curexc_type; |
| 40 | oldvalue = tstate->curexc_value; |
| 41 | oldtraceback = tstate->curexc_traceback; |
| 42 | |
| 43 | tstate->curexc_type = type; |
| 44 | tstate->curexc_value = value; |
| 45 | tstate->curexc_traceback = traceback; |
| 46 | |
| 47 | Py_XDECREF(oldtype); |
| 48 | Py_XDECREF(oldvalue); |
| 49 | Py_XDECREF(oldtraceback); |
Guido van Rossum | 1ae940a | 1995-01-02 19:04:15 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 53 | PyErr_SetObject(PyObject *exception, PyObject *value) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 54 | { |
Guido van Rossum | b4fb6e4 | 2008-06-14 20:20:24 +0000 | [diff] [blame] | 55 | PyThreadState *tstate = PyThreadState_GET(); |
Amaury Forgeot d'Arc | db26f7c | 2008-08-29 07:13:32 +0000 | [diff] [blame] | 56 | PyObject *exc_value; |
Guido van Rossum | b4fb6e4 | 2008-06-14 20:20:24 +0000 | [diff] [blame] | 57 | PyObject *tb = NULL; |
| 58 | |
Thomas Wouters | 303de6a | 2006-04-20 22:42:37 +0000 | [diff] [blame] | 59 | if (exception != NULL && |
| 60 | !PyExceptionClass_Check(exception)) { |
Thomas Wouters | 303de6a | 2006-04-20 22:42:37 +0000 | [diff] [blame] | 61 | PyErr_Format(PyExc_SystemError, |
Walter Dörwald | 573c08c | 2007-05-25 15:46:59 +0000 | [diff] [blame] | 62 | "exception %R not a BaseException subclass", |
| 63 | exception); |
Thomas Wouters | 303de6a | 2006-04-20 22:42:37 +0000 | [diff] [blame] | 64 | return; |
| 65 | } |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 66 | Py_XINCREF(value); |
Amaury Forgeot d'Arc | db26f7c | 2008-08-29 07:13:32 +0000 | [diff] [blame] | 67 | exc_value = tstate->exc_value; |
| 68 | if (exc_value != NULL && exc_value != Py_None) { |
Guido van Rossum | b4fb6e4 | 2008-06-14 20:20:24 +0000 | [diff] [blame] | 69 | /* Implicit exception chaining */ |
Amaury Forgeot d'Arc | db26f7c | 2008-08-29 07:13:32 +0000 | [diff] [blame] | 70 | Py_INCREF(exc_value); |
Guido van Rossum | b4fb6e4 | 2008-06-14 20:20:24 +0000 | [diff] [blame] | 71 | if (value == NULL || !PyExceptionInstance_Check(value)) { |
| 72 | /* We must normalize the value right now */ |
| 73 | PyObject *args, *fixed_value; |
| 74 | if (value == NULL || value == Py_None) |
| 75 | args = PyTuple_New(0); |
| 76 | else if (PyTuple_Check(value)) { |
| 77 | Py_INCREF(value); |
| 78 | args = value; |
| 79 | } |
| 80 | else |
| 81 | args = PyTuple_Pack(1, value); |
| 82 | fixed_value = args ? |
| 83 | PyEval_CallObject(exception, args) : NULL; |
| 84 | Py_XDECREF(args); |
| 85 | Py_XDECREF(value); |
| 86 | if (fixed_value == NULL) |
| 87 | return; |
| 88 | value = fixed_value; |
| 89 | } |
Benjamin Peterson | e652821 | 2008-07-15 15:32:09 +0000 | [diff] [blame] | 90 | /* Avoid reference cycles through the context chain. |
| 91 | This is O(chain length) but context chains are |
| 92 | usually very short. Sensitive readers may try |
| 93 | to inline the call to PyException_GetContext. */ |
Amaury Forgeot d'Arc | db26f7c | 2008-08-29 07:13:32 +0000 | [diff] [blame] | 94 | if (exc_value != value) { |
| 95 | PyObject *o = exc_value, *context; |
Benjamin Peterson | e652821 | 2008-07-15 15:32:09 +0000 | [diff] [blame] | 96 | while ((context = PyException_GetContext(o))) { |
| 97 | Py_DECREF(context); |
| 98 | if (context == value) { |
| 99 | PyException_SetContext(o, NULL); |
| 100 | break; |
| 101 | } |
| 102 | o = context; |
| 103 | } |
Amaury Forgeot d'Arc | db26f7c | 2008-08-29 07:13:32 +0000 | [diff] [blame] | 104 | PyException_SetContext(value, exc_value); |
| 105 | } else { |
| 106 | Py_DECREF(exc_value); |
Benjamin Peterson | e652821 | 2008-07-15 15:32:09 +0000 | [diff] [blame] | 107 | } |
Guido van Rossum | b4fb6e4 | 2008-06-14 20:20:24 +0000 | [diff] [blame] | 108 | } |
| 109 | if (value != NULL && PyExceptionInstance_Check(value)) |
| 110 | tb = PyException_GetTraceback(value); |
| 111 | Py_XINCREF(exception); |
| 112 | PyErr_Restore(exception, value, tb); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 116 | PyErr_SetNone(PyObject *exception) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 117 | { |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 118 | PyErr_SetObject(exception, (PyObject *)NULL); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 122 | PyErr_SetString(PyObject *exception, const char *string) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 123 | { |
Walter Dörwald | 573c08c | 2007-05-25 15:46:59 +0000 | [diff] [blame] | 124 | PyObject *value = PyUnicode_FromString(string); |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 125 | PyErr_SetObject(exception, value); |
| 126 | Py_XDECREF(value); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Guido van Rossum | 3a24181 | 1994-08-29 12:14:12 +0000 | [diff] [blame] | 129 | |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 130 | PyObject * |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 131 | PyErr_Occurred(void) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 132 | { |
Tim Peters | 024da35 | 2001-05-30 06:09:50 +0000 | [diff] [blame] | 133 | PyThreadState *tstate = PyThreadState_GET(); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 134 | |
| 135 | return tstate->curexc_type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 138 | |
| 139 | int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 140 | PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc) |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 141 | { |
Barry Warsaw | fa5c315 | 2000-05-02 19:27:51 +0000 | [diff] [blame] | 142 | if (err == NULL || exc == NULL) { |
| 143 | /* maybe caused by "import exceptions" that failed early on */ |
| 144 | return 0; |
| 145 | } |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 146 | if (PyTuple_Check(exc)) { |
Martin v. Löwis | d96ee90 | 2006-02-16 14:37:16 +0000 | [diff] [blame] | 147 | Py_ssize_t i, n; |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 148 | n = PyTuple_Size(exc); |
| 149 | for (i = 0; i < n; i++) { |
| 150 | /* Test recursively */ |
| 151 | if (PyErr_GivenExceptionMatches( |
| 152 | err, PyTuple_GET_ITEM(exc, i))) |
| 153 | { |
| 154 | return 1; |
| 155 | } |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | /* err might be an instance, so check its class. */ |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 160 | if (PyExceptionInstance_Check(err)) |
| 161 | err = PyExceptionInstance_Class(err); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 162 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 163 | if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) { |
Benjamin Peterson | 69c88f7 | 2008-07-31 01:47:08 +0000 | [diff] [blame] | 164 | int res = 0; |
| 165 | PyObject *exception, *value, *tb; |
| 166 | PyErr_Fetch(&exception, &value, &tb); |
Antoine Pitrou | ec569b7 | 2008-08-26 22:40:48 +0000 | [diff] [blame] | 167 | /* PyObject_IsSubclass() can recurse and therefore is |
| 168 | not safe (see test_bad_getattr in test.pickletester). */ |
| 169 | res = PyType_IsSubtype((PyTypeObject *)err, (PyTypeObject *)exc); |
Benjamin Peterson | 69c88f7 | 2008-07-31 01:47:08 +0000 | [diff] [blame] | 170 | /* This function must not fail, so print the error here */ |
| 171 | if (res == -1) { |
| 172 | PyErr_WriteUnraisable(err); |
Benjamin Peterson | 69c88f7 | 2008-07-31 01:47:08 +0000 | [diff] [blame] | 173 | res = 0; |
| 174 | } |
| 175 | PyErr_Restore(exception, value, tb); |
| 176 | return res; |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 177 | } |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 178 | |
| 179 | return err == exc; |
| 180 | } |
Guido van Rossum | 743007d | 1999-04-21 15:27:31 +0000 | [diff] [blame] | 181 | |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 182 | |
| 183 | int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 184 | PyErr_ExceptionMatches(PyObject *exc) |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 185 | { |
| 186 | return PyErr_GivenExceptionMatches(PyErr_Occurred(), exc); |
| 187 | } |
| 188 | |
| 189 | |
| 190 | /* Used in many places to normalize a raised exception, including in |
| 191 | eval_code2(), do_raise(), and PyErr_Print() |
Benjamin Peterson | e652821 | 2008-07-15 15:32:09 +0000 | [diff] [blame] | 192 | |
| 193 | XXX: should PyErr_NormalizeException() also call |
| 194 | PyException_SetTraceback() with the resulting value and tb? |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 195 | */ |
| 196 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 197 | PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb) |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 198 | { |
| 199 | PyObject *type = *exc; |
| 200 | PyObject *value = *val; |
| 201 | PyObject *inclass = NULL; |
Jeremy Hylton | e2e2c9f | 2001-09-26 19:58:38 +0000 | [diff] [blame] | 202 | PyObject *initial_tb = NULL; |
Thomas Wouters | 89d996e | 2007-09-08 17:39:28 +0000 | [diff] [blame] | 203 | PyThreadState *tstate = NULL; |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 204 | |
Guido van Rossum | ed473a4 | 2000-08-07 19:18:27 +0000 | [diff] [blame] | 205 | if (type == NULL) { |
Guido van Rossum | 6b3fffa | 2003-04-10 20:29:48 +0000 | [diff] [blame] | 206 | /* There was no exception, so nothing to do. */ |
| 207 | return; |
Guido van Rossum | ed473a4 | 2000-08-07 19:18:27 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 210 | /* If PyErr_SetNone() was used, the value will have been actually |
| 211 | set to NULL. |
| 212 | */ |
| 213 | if (!value) { |
| 214 | value = Py_None; |
| 215 | Py_INCREF(value); |
| 216 | } |
| 217 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 218 | if (PyExceptionInstance_Check(value)) |
| 219 | inclass = PyExceptionInstance_Class(value); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 220 | |
| 221 | /* Normalize the exception so that if the type is a class, the |
| 222 | value will be an instance. |
| 223 | */ |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 224 | if (PyExceptionClass_Check(type)) { |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 225 | /* if the value was not an instance, or is not an instance |
| 226 | whose class is (or is derived from) type, then use the |
| 227 | value as an argument to instantiation of the type |
| 228 | class. |
| 229 | */ |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 230 | if (!inclass || !PyObject_IsSubclass(inclass, type)) { |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 231 | PyObject *args, *res; |
| 232 | |
| 233 | if (value == Py_None) |
Raymond Hettinger | 8ae4689 | 2003-10-12 19:09:37 +0000 | [diff] [blame] | 234 | args = PyTuple_New(0); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 235 | else if (PyTuple_Check(value)) { |
| 236 | Py_INCREF(value); |
| 237 | args = value; |
| 238 | } |
| 239 | else |
Raymond Hettinger | 8ae4689 | 2003-10-12 19:09:37 +0000 | [diff] [blame] | 240 | args = PyTuple_Pack(1, value); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 241 | |
| 242 | if (args == NULL) |
| 243 | goto finally; |
| 244 | res = PyEval_CallObject(type, args); |
| 245 | Py_DECREF(args); |
| 246 | if (res == NULL) |
| 247 | goto finally; |
| 248 | Py_DECREF(value); |
| 249 | value = res; |
| 250 | } |
Barry Warsaw | 3a74993 | 1997-09-30 15:00:18 +0000 | [diff] [blame] | 251 | /* if the class of the instance doesn't exactly match the |
| 252 | class of the type, believe the instance |
| 253 | */ |
| 254 | else if (inclass != type) { |
| 255 | Py_DECREF(type); |
| 256 | type = inclass; |
| 257 | Py_INCREF(type); |
| 258 | } |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 259 | } |
| 260 | *exc = type; |
| 261 | *val = value; |
| 262 | return; |
| 263 | finally: |
Guido van Rossum | 19b55f2 | 1997-12-09 14:11:39 +0000 | [diff] [blame] | 264 | Py_DECREF(type); |
| 265 | Py_DECREF(value); |
Jeremy Hylton | e2e2c9f | 2001-09-26 19:58:38 +0000 | [diff] [blame] | 266 | /* If the new exception doesn't set a traceback and the old |
| 267 | exception had a traceback, use the old traceback for the |
| 268 | new exception. It's better than nothing. |
| 269 | */ |
| 270 | initial_tb = *tb; |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 271 | PyErr_Fetch(exc, val, tb); |
Jeremy Hylton | e2e2c9f | 2001-09-26 19:58:38 +0000 | [diff] [blame] | 272 | if (initial_tb != NULL) { |
| 273 | if (*tb == NULL) |
| 274 | *tb = initial_tb; |
| 275 | else |
| 276 | Py_DECREF(initial_tb); |
| 277 | } |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 278 | /* normalize recursively */ |
Thomas Wouters | 89d996e | 2007-09-08 17:39:28 +0000 | [diff] [blame] | 279 | tstate = PyThreadState_GET(); |
| 280 | if (++tstate->recursion_depth > Py_GetRecursionLimit()) { |
| 281 | --tstate->recursion_depth; |
Georg Brandl | 406b3d8 | 2009-04-11 21:24:37 +0000 | [diff] [blame] | 282 | /* throw away the old exception... */ |
| 283 | Py_DECREF(*exc); |
| 284 | Py_DECREF(*val); |
| 285 | /* ... and use the recursion error instead */ |
| 286 | *exc = PyExc_RuntimeError; |
| 287 | *val = PyExc_RecursionErrorInst; |
| 288 | Py_INCREF(*exc); |
| 289 | Py_INCREF(*val); |
| 290 | /* just keeping the old traceback */ |
Thomas Wouters | 89d996e | 2007-09-08 17:39:28 +0000 | [diff] [blame] | 291 | return; |
| 292 | } |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 293 | PyErr_NormalizeException(exc, val, tb); |
Thomas Wouters | 89d996e | 2007-09-08 17:39:28 +0000 | [diff] [blame] | 294 | --tstate->recursion_depth; |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 298 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 299 | PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 300 | { |
Nicholas Bastin | e5662ae | 2004-03-24 22:22:12 +0000 | [diff] [blame] | 301 | PyThreadState *tstate = PyThreadState_GET(); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 302 | |
| 303 | *p_type = tstate->curexc_type; |
| 304 | *p_value = tstate->curexc_value; |
| 305 | *p_traceback = tstate->curexc_traceback; |
| 306 | |
| 307 | tstate->curexc_type = NULL; |
| 308 | tstate->curexc_value = NULL; |
| 309 | tstate->curexc_traceback = NULL; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 313 | PyErr_Clear(void) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 314 | { |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 315 | PyErr_Restore(NULL, NULL, NULL); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 316 | } |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 317 | |
| 318 | /* Convenience functions to set a type error exception and return 0 */ |
| 319 | |
| 320 | int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 321 | PyErr_BadArgument(void) |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 322 | { |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 323 | PyErr_SetString(PyExc_TypeError, |
Fred Drake | 661ea26 | 2000-10-24 19:57:45 +0000 | [diff] [blame] | 324 | "bad argument type for built-in operation"); |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 328 | PyObject * |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 329 | PyErr_NoMemory(void) |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 330 | { |
Vladimir Marangozov | 0888ff1 | 2000-08-18 18:01:06 +0000 | [diff] [blame] | 331 | if (PyErr_ExceptionMatches(PyExc_MemoryError)) |
| 332 | /* already current */ |
| 333 | return NULL; |
| 334 | |
Barry Warsaw | 2d8adff | 1997-08-29 21:54:35 +0000 | [diff] [blame] | 335 | /* raise the pre-allocated instance if it still exists */ |
| 336 | if (PyExc_MemoryErrorInst) |
Amaury Forgeot d'Arc | e19cadb | 2008-07-31 22:56:02 +0000 | [diff] [blame] | 337 | { |
| 338 | /* Clear the previous traceback, otherwise it will be appended |
| 339 | * to the current one. |
| 340 | * |
| 341 | * The following statement is not likely to raise any error; |
| 342 | * if it does, we simply discard it. |
| 343 | */ |
| 344 | PyException_SetTraceback(PyExc_MemoryErrorInst, Py_None); |
| 345 | |
Barry Warsaw | 2d8adff | 1997-08-29 21:54:35 +0000 | [diff] [blame] | 346 | PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst); |
Amaury Forgeot d'Arc | e19cadb | 2008-07-31 22:56:02 +0000 | [diff] [blame] | 347 | } |
Barry Warsaw | 2d8adff | 1997-08-29 21:54:35 +0000 | [diff] [blame] | 348 | else |
| 349 | /* this will probably fail since there's no memory and hee, |
| 350 | hee, we have to instantiate this class |
| 351 | */ |
| 352 | PyErr_SetNone(PyExc_MemoryError); |
| 353 | |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 354 | return NULL; |
| 355 | } |
| 356 | |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 357 | PyObject * |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 358 | PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 359 | { |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 360 | PyObject *message; |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 361 | PyObject *v; |
Guido van Rossum | 3a24181 | 1994-08-29 12:14:12 +0000 | [diff] [blame] | 362 | int i = errno; |
Martin v. Löwis | 3484a18 | 2002-03-09 12:07:51 +0000 | [diff] [blame] | 363 | #ifdef PLAN9 |
| 364 | char errbuf[ERRMAX]; |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 365 | #else |
| 366 | #ifndef MS_WINDOWS |
| 367 | char *s; |
| 368 | #else |
| 369 | WCHAR *s_buf = NULL; |
| 370 | #endif /* Unix/Windows */ |
| 371 | #endif /* PLAN 9*/ |
| 372 | |
Guido van Rossum | e9fbc09 | 1995-02-18 14:52:19 +0000 | [diff] [blame] | 373 | #ifdef EINTR |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 374 | if (i == EINTR && PyErr_CheckSignals()) |
Guido van Rossum | 5063bab | 1991-10-20 20:14:56 +0000 | [diff] [blame] | 375 | return NULL; |
Guido van Rossum | e9fbc09 | 1995-02-18 14:52:19 +0000 | [diff] [blame] | 376 | #endif |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 377 | |
Martin v. Löwis | 3484a18 | 2002-03-09 12:07:51 +0000 | [diff] [blame] | 378 | #ifdef PLAN9 |
| 379 | rerrstr(errbuf, sizeof errbuf); |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 380 | message = PyUnicode_DecodeUTF8(errbuf, strlen(errbuf), "ignore"); |
Martin v. Löwis | 3484a18 | 2002-03-09 12:07:51 +0000 | [diff] [blame] | 381 | #else |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 382 | #ifndef MS_WINDOWS |
Guido van Rossum | e0e5982 | 1998-10-14 20:38:13 +0000 | [diff] [blame] | 383 | if (i == 0) |
| 384 | s = "Error"; /* Sometimes errno didn't get set */ |
Barry Warsaw | 97d9515 | 1998-07-23 16:05:56 +0000 | [diff] [blame] | 385 | else |
Guido van Rossum | e0e5982 | 1998-10-14 20:38:13 +0000 | [diff] [blame] | 386 | s = strerror(i); |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 387 | message = PyUnicode_DecodeUTF8(s, strlen(s), "ignore"); |
Guido van Rossum | 743007d | 1999-04-21 15:27:31 +0000 | [diff] [blame] | 388 | #else |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 389 | if (i == 0) |
| 390 | message = PyUnicode_FromString("Error"); /* Sometimes errno didn't get set */ |
| 391 | else |
Guido van Rossum | 743007d | 1999-04-21 15:27:31 +0000 | [diff] [blame] | 392 | { |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 393 | /* Note that the Win32 errors do not lineup with the |
| 394 | errno error. So if the error is in the MSVC error |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 395 | table, we use it, otherwise we assume it really _is_ |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 396 | a Win32 error code |
| 397 | */ |
Guido van Rossum | 584b16a | 2000-02-21 16:50:31 +0000 | [diff] [blame] | 398 | if (i > 0 && i < _sys_nerr) { |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 399 | message = PyUnicode_FromString(_sys_errlist[i]); |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 400 | } |
| 401 | else { |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 402 | int len = FormatMessageW( |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 403 | FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 404 | FORMAT_MESSAGE_FROM_SYSTEM | |
| 405 | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 406 | NULL, /* no message source */ |
| 407 | i, |
| 408 | MAKELANGID(LANG_NEUTRAL, |
| 409 | SUBLANG_DEFAULT), |
| 410 | /* Default language */ |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 411 | (LPWSTR) &s_buf, |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 412 | 0, /* size not used */ |
| 413 | NULL); /* no args */ |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 414 | if (len==0) { |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 415 | /* Only ever seen this in out-of-mem |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 416 | situations */ |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 417 | s_buf = NULL; |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 418 | message = PyUnicode_FromFormat("Windows Error 0x%X", i); |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 419 | } else { |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 420 | /* remove trailing cr/lf and dots */ |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 421 | while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.')) |
| 422 | s_buf[--len] = L'\0'; |
| 423 | message = PyUnicode_FromUnicode(s_buf, len); |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 424 | } |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 425 | } |
Guido van Rossum | 743007d | 1999-04-21 15:27:31 +0000 | [diff] [blame] | 426 | } |
Martin v. Löwis | 3484a18 | 2002-03-09 12:07:51 +0000 | [diff] [blame] | 427 | #endif /* Unix/Windows */ |
| 428 | #endif /* PLAN 9*/ |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 429 | |
| 430 | if (message == NULL) |
| 431 | { |
| 432 | #ifdef MS_WINDOWS |
| 433 | LocalFree(s_buf); |
| 434 | #endif |
| 435 | return NULL; |
| 436 | } |
| 437 | |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 438 | if (filenameObject != NULL) |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 439 | v = Py_BuildValue("(iOO)", i, message, filenameObject); |
Guido van Rossum | e0e5982 | 1998-10-14 20:38:13 +0000 | [diff] [blame] | 440 | else |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 441 | v = Py_BuildValue("(iO)", i, message); |
| 442 | Py_DECREF(message); |
| 443 | |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 444 | if (v != NULL) { |
Guido van Rossum | 373c869 | 1997-04-29 18:22:47 +0000 | [diff] [blame] | 445 | PyErr_SetObject(exc, v); |
| 446 | Py_DECREF(v); |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 447 | } |
Martin v. Löwis | 6238d2b | 2002-06-30 15:26:10 +0000 | [diff] [blame] | 448 | #ifdef MS_WINDOWS |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 449 | LocalFree(s_buf); |
Guido van Rossum | 743007d | 1999-04-21 15:27:31 +0000 | [diff] [blame] | 450 | #endif |
Guido van Rossum | 7d310eb | 1990-10-14 20:00:05 +0000 | [diff] [blame] | 451 | return NULL; |
| 452 | } |
Guido van Rossum | 743007d | 1999-04-21 15:27:31 +0000 | [diff] [blame] | 453 | |
Barry Warsaw | 97d9515 | 1998-07-23 16:05:56 +0000 | [diff] [blame] | 454 | |
| 455 | PyObject * |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 456 | PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename) |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 457 | { |
Neal Norwitz | cd79596 | 2007-08-24 19:54:13 +0000 | [diff] [blame] | 458 | PyObject *name = filename ? PyUnicode_FromString(filename) : NULL; |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 459 | PyObject *result = PyErr_SetFromErrnoWithFilenameObject(exc, name); |
Mark Hammond | da7efaa | 2002-10-04 00:09:38 +0000 | [diff] [blame] | 460 | Py_XDECREF(name); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 461 | return result; |
| 462 | } |
| 463 | |
Hirokazu Yamamoto | 8223c24 | 2009-05-17 04:21:53 +0000 | [diff] [blame] | 464 | #ifdef MS_WINDOWS |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 465 | PyObject * |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 466 | PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, const Py_UNICODE *filename) |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 467 | { |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 468 | PyObject *name = filename ? |
| 469 | PyUnicode_FromUnicode(filename, wcslen(filename)) : |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 470 | NULL; |
| 471 | PyObject *result = PyErr_SetFromErrnoWithFilenameObject(exc, name); |
| 472 | Py_XDECREF(name); |
| 473 | return result; |
| 474 | } |
Hirokazu Yamamoto | 8223c24 | 2009-05-17 04:21:53 +0000 | [diff] [blame] | 475 | #endif /* MS_WINDOWS */ |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 476 | |
| 477 | PyObject * |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 478 | PyErr_SetFromErrno(PyObject *exc) |
Barry Warsaw | 97d9515 | 1998-07-23 16:05:56 +0000 | [diff] [blame] | 479 | { |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 480 | return PyErr_SetFromErrnoWithFilenameObject(exc, NULL); |
Barry Warsaw | 97d9515 | 1998-07-23 16:05:56 +0000 | [diff] [blame] | 481 | } |
Guido van Rossum | 683a072 | 1990-10-21 22:09:12 +0000 | [diff] [blame] | 482 | |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 483 | #ifdef MS_WINDOWS |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 484 | /* Windows specific error code handling */ |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 485 | PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( |
Thomas Heller | 085358a | 2002-07-29 14:27:41 +0000 | [diff] [blame] | 486 | PyObject *exc, |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 487 | int ierr, |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 488 | PyObject *filenameObject) |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 489 | { |
| 490 | int len; |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 491 | WCHAR *s_buf = NULL; /* Free via LocalFree */ |
| 492 | PyObject *message; |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 493 | PyObject *v; |
| 494 | DWORD err = (DWORD)ierr; |
| 495 | if (err==0) err = GetLastError(); |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 496 | len = FormatMessageW( |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 497 | /* Error API error */ |
| 498 | FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 499 | FORMAT_MESSAGE_FROM_SYSTEM | |
| 500 | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 501 | NULL, /* no message source */ |
| 502 | err, |
| 503 | MAKELANGID(LANG_NEUTRAL, |
| 504 | SUBLANG_DEFAULT), /* Default language */ |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 505 | (LPWSTR) &s_buf, |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 506 | 0, /* size not used */ |
| 507 | NULL); /* no args */ |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 508 | if (len==0) { |
| 509 | /* Only seen this in out of mem situations */ |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 510 | message = PyUnicode_FromFormat("Windows Error 0x%X", err); |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 511 | s_buf = NULL; |
| 512 | } else { |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 513 | /* remove trailing cr/lf and dots */ |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 514 | while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.')) |
| 515 | s_buf[--len] = L'\0'; |
| 516 | message = PyUnicode_FromUnicode(s_buf, len); |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 517 | } |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 518 | |
| 519 | if (message == NULL) |
| 520 | { |
| 521 | LocalFree(s_buf); |
| 522 | return NULL; |
| 523 | } |
| 524 | |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 525 | if (filenameObject != NULL) |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 526 | v = Py_BuildValue("(iOO)", err, message, filenameObject); |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 527 | else |
Martin v. Löwis | 5d12abe | 2007-09-03 07:40:24 +0000 | [diff] [blame] | 528 | v = Py_BuildValue("(iO)", err, message); |
| 529 | Py_DECREF(message); |
| 530 | |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 531 | if (v != NULL) { |
Thomas Heller | 085358a | 2002-07-29 14:27:41 +0000 | [diff] [blame] | 532 | PyErr_SetObject(exc, v); |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 533 | Py_DECREF(v); |
| 534 | } |
Mark Hammond | 3d61a06 | 2002-10-04 00:13:02 +0000 | [diff] [blame] | 535 | LocalFree(s_buf); |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 536 | return NULL; |
| 537 | } |
| 538 | |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 539 | PyObject *PyErr_SetExcFromWindowsErrWithFilename( |
| 540 | PyObject *exc, |
| 541 | int ierr, |
| 542 | const char *filename) |
| 543 | { |
Neal Norwitz | cd79596 | 2007-08-24 19:54:13 +0000 | [diff] [blame] | 544 | PyObject *name = filename ? PyUnicode_FromString(filename) : NULL; |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 545 | PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, |
| 546 | ierr, |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 547 | name); |
| 548 | Py_XDECREF(name); |
| 549 | return ret; |
| 550 | } |
| 551 | |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 552 | PyObject *PyErr_SetExcFromWindowsErrWithUnicodeFilename( |
| 553 | PyObject *exc, |
| 554 | int ierr, |
| 555 | const Py_UNICODE *filename) |
| 556 | { |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 557 | PyObject *name = filename ? |
| 558 | PyUnicode_FromUnicode(filename, wcslen(filename)) : |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 559 | NULL; |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 560 | PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, |
| 561 | ierr, |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 562 | name); |
| 563 | Py_XDECREF(name); |
| 564 | return ret; |
| 565 | } |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 566 | |
Thomas Heller | 085358a | 2002-07-29 14:27:41 +0000 | [diff] [blame] | 567 | PyObject *PyErr_SetExcFromWindowsErr(PyObject *exc, int ierr) |
| 568 | { |
| 569 | return PyErr_SetExcFromWindowsErrWithFilename(exc, ierr, NULL); |
| 570 | } |
| 571 | |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 572 | PyObject *PyErr_SetFromWindowsErr(int ierr) |
| 573 | { |
Thomas Heller | 085358a | 2002-07-29 14:27:41 +0000 | [diff] [blame] | 574 | return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError, |
| 575 | ierr, NULL); |
| 576 | } |
| 577 | PyObject *PyErr_SetFromWindowsErrWithFilename( |
| 578 | int ierr, |
| 579 | const char *filename) |
| 580 | { |
Neal Norwitz | cd79596 | 2007-08-24 19:54:13 +0000 | [diff] [blame] | 581 | PyObject *name = filename ? PyUnicode_FromString(filename) : NULL; |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 582 | PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( |
| 583 | PyExc_WindowsError, |
| 584 | ierr, name); |
Mark Hammond | da7efaa | 2002-10-04 00:09:38 +0000 | [diff] [blame] | 585 | Py_XDECREF(name); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 586 | return result; |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 587 | } |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 588 | |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 589 | PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( |
| 590 | int ierr, |
| 591 | const Py_UNICODE *filename) |
| 592 | { |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 593 | PyObject *name = filename ? |
| 594 | PyUnicode_FromUnicode(filename, wcslen(filename)) : |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 595 | NULL; |
| 596 | PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( |
| 597 | PyExc_WindowsError, |
| 598 | ierr, name); |
Mark Hammond | da7efaa | 2002-10-04 00:09:38 +0000 | [diff] [blame] | 599 | Py_XDECREF(name); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 600 | return result; |
| 601 | } |
Guido van Rossum | 795e189 | 2000-02-17 15:19:15 +0000 | [diff] [blame] | 602 | #endif /* MS_WINDOWS */ |
| 603 | |
Guido van Rossum | 683a072 | 1990-10-21 22:09:12 +0000 | [diff] [blame] | 604 | void |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 605 | _PyErr_BadInternalCall(const char *filename, int lineno) |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 606 | { |
| 607 | PyErr_Format(PyExc_SystemError, |
| 608 | "%s:%d: bad argument to internal function", |
| 609 | filename, lineno); |
| 610 | } |
| 611 | |
| 612 | /* Remove the preprocessor macro for PyErr_BadInternalCall() so that we can |
| 613 | export the entry point for existing object code: */ |
| 614 | #undef PyErr_BadInternalCall |
| 615 | void |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 616 | PyErr_BadInternalCall(void) |
Guido van Rossum | 683a072 | 1990-10-21 22:09:12 +0000 | [diff] [blame] | 617 | { |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 618 | PyErr_Format(PyExc_SystemError, |
| 619 | "bad argument to internal function"); |
Guido van Rossum | 683a072 | 1990-10-21 22:09:12 +0000 | [diff] [blame] | 620 | } |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 621 | #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__) |
| 622 | |
Guido van Rossum | 1548bac | 1997-02-14 17:09:47 +0000 | [diff] [blame] | 623 | |
| 624 | |
Guido van Rossum | 1548bac | 1997-02-14 17:09:47 +0000 | [diff] [blame] | 625 | PyObject * |
| 626 | PyErr_Format(PyObject *exception, const char *format, ...) |
Guido van Rossum | 1548bac | 1997-02-14 17:09:47 +0000 | [diff] [blame] | 627 | { |
| 628 | va_list vargs; |
Jeremy Hylton | b69a27e | 2000-09-01 03:49:47 +0000 | [diff] [blame] | 629 | PyObject* string; |
Guido van Rossum | 1548bac | 1997-02-14 17:09:47 +0000 | [diff] [blame] | 630 | |
Jeremy Hylton | b69a27e | 2000-09-01 03:49:47 +0000 | [diff] [blame] | 631 | #ifdef HAVE_STDARG_PROTOTYPES |
Guido van Rossum | 1548bac | 1997-02-14 17:09:47 +0000 | [diff] [blame] | 632 | va_start(vargs, format); |
Jeremy Hylton | b69a27e | 2000-09-01 03:49:47 +0000 | [diff] [blame] | 633 | #else |
| 634 | va_start(vargs); |
| 635 | #endif |
Guido van Rossum | 1548bac | 1997-02-14 17:09:47 +0000 | [diff] [blame] | 636 | |
Walter Dörwald | 573c08c | 2007-05-25 15:46:59 +0000 | [diff] [blame] | 637 | string = PyUnicode_FromFormatV(format, vargs); |
Jeremy Hylton | b69a27e | 2000-09-01 03:49:47 +0000 | [diff] [blame] | 638 | PyErr_SetObject(exception, string); |
| 639 | Py_XDECREF(string); |
Tim Peters | c15c4f1 | 2001-10-02 21:32:07 +0000 | [diff] [blame] | 640 | va_end(vargs); |
Guido van Rossum | 1548bac | 1997-02-14 17:09:47 +0000 | [diff] [blame] | 641 | return NULL; |
| 642 | } |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 643 | |
| 644 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 645 | |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 646 | PyObject * |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 647 | PyErr_NewException(const char *name, PyObject *base, PyObject *dict) |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 648 | { |
Neal Norwitz | b382b84 | 2007-08-24 20:00:37 +0000 | [diff] [blame] | 649 | const char *dot; |
Guido van Rossum | 2ac650f | 1997-10-03 19:50:55 +0000 | [diff] [blame] | 650 | PyObject *modulename = NULL; |
| 651 | PyObject *classname = NULL; |
| 652 | PyObject *mydict = NULL; |
| 653 | PyObject *bases = NULL; |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 654 | PyObject *result = NULL; |
Guido van Rossum | 2ac650f | 1997-10-03 19:50:55 +0000 | [diff] [blame] | 655 | dot = strrchr(name, '.'); |
| 656 | if (dot == NULL) { |
| 657 | PyErr_SetString(PyExc_SystemError, |
| 658 | "PyErr_NewException: name must be module.class"); |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 659 | return NULL; |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 660 | } |
| 661 | if (base == NULL) |
| 662 | base = PyExc_Exception; |
Guido van Rossum | 2ac650f | 1997-10-03 19:50:55 +0000 | [diff] [blame] | 663 | if (dict == NULL) { |
| 664 | dict = mydict = PyDict_New(); |
| 665 | if (dict == NULL) |
| 666 | goto failure; |
| 667 | } |
| 668 | if (PyDict_GetItemString(dict, "__module__") == NULL) { |
Neal Norwitz | cd79596 | 2007-08-24 19:54:13 +0000 | [diff] [blame] | 669 | modulename = PyUnicode_FromStringAndSize(name, |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 670 | (Py_ssize_t)(dot-name)); |
Guido van Rossum | 2ac650f | 1997-10-03 19:50:55 +0000 | [diff] [blame] | 671 | if (modulename == NULL) |
| 672 | goto failure; |
| 673 | if (PyDict_SetItemString(dict, "__module__", modulename) != 0) |
| 674 | goto failure; |
| 675 | } |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 676 | if (PyTuple_Check(base)) { |
| 677 | bases = base; |
| 678 | /* INCREF as we create a new ref in the else branch */ |
| 679 | Py_INCREF(bases); |
| 680 | } else { |
| 681 | bases = PyTuple_Pack(1, base); |
| 682 | if (bases == NULL) |
| 683 | goto failure; |
| 684 | } |
| 685 | /* Create a real new-style class. */ |
Guido van Rossum | e845c0f | 2007-11-02 23:07:07 +0000 | [diff] [blame] | 686 | result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 687 | dot+1, bases, dict); |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 688 | failure: |
Guido van Rossum | 2ac650f | 1997-10-03 19:50:55 +0000 | [diff] [blame] | 689 | Py_XDECREF(bases); |
| 690 | Py_XDECREF(mydict); |
| 691 | Py_XDECREF(classname); |
| 692 | Py_XDECREF(modulename); |
Guido van Rossum | 7617e05 | 1997-09-16 18:43:50 +0000 | [diff] [blame] | 693 | return result; |
| 694 | } |
Jeremy Hylton | b709df3 | 2000-09-01 02:47:25 +0000 | [diff] [blame] | 695 | |
| 696 | /* Call when an exception has occurred but there is no way for Python |
| 697 | to handle it. Examples: exception in __del__ or during GC. */ |
| 698 | void |
| 699 | PyErr_WriteUnraisable(PyObject *obj) |
| 700 | { |
| 701 | PyObject *f, *t, *v, *tb; |
| 702 | PyErr_Fetch(&t, &v, &tb); |
| 703 | f = PySys_GetObject("stderr"); |
Christian Heimes | 2be0373 | 2007-11-15 02:26:46 +0000 | [diff] [blame] | 704 | if (f != NULL && f != Py_None) { |
Jeremy Hylton | b709df3 | 2000-09-01 02:47:25 +0000 | [diff] [blame] | 705 | PyFile_WriteString("Exception ", f); |
| 706 | if (t) { |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 707 | PyObject* moduleName; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 708 | char* className; |
| 709 | assert(PyExceptionClass_Check(t)); |
| 710 | className = PyExceptionClass_Name(t); |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 711 | if (className != NULL) { |
| 712 | char *dot = strrchr(className, '.'); |
| 713 | if (dot != NULL) |
| 714 | className = dot+1; |
| 715 | } |
| 716 | |
| 717 | moduleName = PyObject_GetAttrString(t, "__module__"); |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 718 | if (moduleName == NULL) |
| 719 | PyFile_WriteString("<unknown>", f); |
| 720 | else { |
Marc-André Lemburg | 4cc0f24 | 2008-08-07 18:54:33 +0000 | [diff] [blame] | 721 | char* modstr = _PyUnicode_AsString(moduleName); |
Neal Norwitz | 2633c69 | 2007-02-26 22:22:47 +0000 | [diff] [blame] | 722 | if (modstr && |
Georg Brandl | 1a3284e | 2007-12-02 09:40:06 +0000 | [diff] [blame] | 723 | strcmp(modstr, "builtins") != 0) |
Brett Cannon | bf36409 | 2006-03-01 04:25:17 +0000 | [diff] [blame] | 724 | { |
| 725 | PyFile_WriteString(modstr, f); |
| 726 | PyFile_WriteString(".", f); |
| 727 | } |
| 728 | } |
| 729 | if (className == NULL) |
| 730 | PyFile_WriteString("<unknown>", f); |
| 731 | else |
| 732 | PyFile_WriteString(className, f); |
Jeremy Hylton | b709df3 | 2000-09-01 02:47:25 +0000 | [diff] [blame] | 733 | if (v && v != Py_None) { |
| 734 | PyFile_WriteString(": ", f); |
| 735 | PyFile_WriteObject(v, f, 0); |
| 736 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 737 | Py_XDECREF(moduleName); |
Jeremy Hylton | b709df3 | 2000-09-01 02:47:25 +0000 | [diff] [blame] | 738 | } |
| 739 | PyFile_WriteString(" in ", f); |
| 740 | PyFile_WriteObject(obj, f, 0); |
| 741 | PyFile_WriteString(" ignored\n", f); |
| 742 | PyErr_Clear(); /* Just in case */ |
| 743 | } |
| 744 | Py_XDECREF(t); |
| 745 | Py_XDECREF(v); |
| 746 | Py_XDECREF(tb); |
| 747 | } |
Guido van Rossum | cfd42b5 | 2000-12-15 21:58:52 +0000 | [diff] [blame] | 748 | |
Armin Rigo | 092381a | 2003-10-25 14:29:27 +0000 | [diff] [blame] | 749 | extern PyObject *PyModule_GetWarningsModule(void); |
Guido van Rossum | cfd42b5 | 2000-12-15 21:58:52 +0000 | [diff] [blame] | 750 | |
Guido van Rossum | 2fd4565 | 2001-02-28 21:46:24 +0000 | [diff] [blame] | 751 | |
Martin v. Löwis | cfeb3b6 | 2002-03-03 21:30:27 +0000 | [diff] [blame] | 752 | /* Set file and line information for the current exception. |
| 753 | If the exception is not a SyntaxError, also sets additional attributes |
| 754 | to make printing of exceptions believe it is a syntax error. */ |
Guido van Rossum | 2fd4565 | 2001-02-28 21:46:24 +0000 | [diff] [blame] | 755 | |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 756 | void |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 757 | PyErr_SyntaxLocation(const char *filename, int lineno) |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 758 | { |
| 759 | PyObject *exc, *v, *tb, *tmp; |
| 760 | |
| 761 | /* add attributes for the line number and filename for the error */ |
| 762 | PyErr_Fetch(&exc, &v, &tb); |
| 763 | PyErr_NormalizeException(&exc, &v, &tb); |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 764 | /* XXX check that it is, indeed, a syntax error. It might not |
| 765 | * be, though. */ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 766 | tmp = PyLong_FromLong(lineno); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 767 | if (tmp == NULL) |
| 768 | PyErr_Clear(); |
| 769 | else { |
| 770 | if (PyObject_SetAttrString(v, "lineno", tmp)) |
| 771 | PyErr_Clear(); |
| 772 | Py_DECREF(tmp); |
| 773 | } |
| 774 | if (filename != NULL) { |
Neal Norwitz | cd79596 | 2007-08-24 19:54:13 +0000 | [diff] [blame] | 775 | tmp = PyUnicode_FromString(filename); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 776 | if (tmp == NULL) |
| 777 | PyErr_Clear(); |
| 778 | else { |
| 779 | if (PyObject_SetAttrString(v, "filename", tmp)) |
| 780 | PyErr_Clear(); |
| 781 | Py_DECREF(tmp); |
| 782 | } |
| 783 | |
| 784 | tmp = PyErr_ProgramText(filename, lineno); |
| 785 | if (tmp) { |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 786 | if (PyObject_SetAttrString(v, "text", tmp)) |
| 787 | PyErr_Clear(); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 788 | Py_DECREF(tmp); |
| 789 | } |
| 790 | } |
Martin v. Löwis | cfeb3b6 | 2002-03-03 21:30:27 +0000 | [diff] [blame] | 791 | if (PyObject_SetAttrString(v, "offset", Py_None)) { |
| 792 | PyErr_Clear(); |
| 793 | } |
| 794 | if (exc != PyExc_SyntaxError) { |
| 795 | if (!PyObject_HasAttrString(v, "msg")) { |
| 796 | tmp = PyObject_Str(v); |
| 797 | if (tmp) { |
| 798 | if (PyObject_SetAttrString(v, "msg", tmp)) |
| 799 | PyErr_Clear(); |
| 800 | Py_DECREF(tmp); |
| 801 | } else { |
| 802 | PyErr_Clear(); |
| 803 | } |
| 804 | } |
| 805 | if (!PyObject_HasAttrString(v, "print_file_and_line")) { |
| 806 | if (PyObject_SetAttrString(v, "print_file_and_line", |
| 807 | Py_None)) |
| 808 | PyErr_Clear(); |
| 809 | } |
| 810 | } |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 811 | PyErr_Restore(exc, v, tb); |
| 812 | } |
| 813 | |
Guido van Rossum | ebe8f8a | 2007-10-10 18:53:36 +0000 | [diff] [blame] | 814 | /* Attempt to load the line of text that the exception refers to. If it |
| 815 | fails, it will return NULL but will not set an exception. |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 816 | |
| 817 | XXX The functionality of this function is quite similar to the |
Guido van Rossum | ebe8f8a | 2007-10-10 18:53:36 +0000 | [diff] [blame] | 818 | functionality in tb_displayline() in traceback.c. */ |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 819 | |
| 820 | PyObject * |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 821 | PyErr_ProgramText(const char *filename, int lineno) |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 822 | { |
| 823 | FILE *fp; |
| 824 | int i; |
| 825 | char linebuf[1000]; |
| 826 | |
Tim Peters | a7444f4 | 2006-02-27 23:29:46 +0000 | [diff] [blame] | 827 | if (filename == NULL || *filename == '\0' || lineno <= 0) |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 828 | return NULL; |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 829 | fp = fopen(filename, "r" PY_STDIOTEXTMODE); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 830 | if (fp == NULL) |
| 831 | return NULL; |
| 832 | for (i = 0; i < lineno; i++) { |
| 833 | char *pLastChar = &linebuf[sizeof(linebuf) - 2]; |
| 834 | do { |
| 835 | *pLastChar = '\0'; |
Guido van Rossum | ebe8f8a | 2007-10-10 18:53:36 +0000 | [diff] [blame] | 836 | if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, |
| 837 | fp, NULL) == NULL) |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 838 | break; |
| 839 | /* fgets read *something*; if it didn't get as |
| 840 | far as pLastChar, it must have found a newline |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 841 | or hit the end of the file; if pLastChar is \n, |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 842 | it obviously found a newline; else we haven't |
| 843 | yet seen a newline, so must continue */ |
| 844 | } while (*pLastChar != '\0' && *pLastChar != '\n'); |
| 845 | } |
| 846 | fclose(fp); |
| 847 | if (i == lineno) { |
| 848 | char *p = linebuf; |
Guido van Rossum | ebe8f8a | 2007-10-10 18:53:36 +0000 | [diff] [blame] | 849 | PyObject *res; |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 850 | while (*p == ' ' || *p == '\t' || *p == '\014') |
| 851 | p++; |
Guido van Rossum | ebe8f8a | 2007-10-10 18:53:36 +0000 | [diff] [blame] | 852 | res = PyUnicode_FromString(p); |
| 853 | if (res == NULL) |
| 854 | PyErr_Clear(); |
| 855 | return res; |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 856 | } |
| 857 | return NULL; |
| 858 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 859 | |
| 860 | #ifdef __cplusplus |
| 861 | } |
| 862 | #endif |