Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 13658:f79434ee41fa legacy-trunk
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Sat, 22 Jul 2000 18:47:25 +0000 |
| parents | a032101ed926 |
| children | 15ad4088a700 |
comparison
equal
deleted
inserted
replaced
| 13657:6a5314a6c2c2 | 13658:f79434ee41fa |
|---|---|
| 28 #include "windows.h" | 28 #include "windows.h" |
| 29 #include "winbase.h" | 29 #include "winbase.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 void | 32 void |
| 33 PyErr_Restore(type, value, traceback) | 33 PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback) |
| 34 PyObject *type; | |
| 35 PyObject *value; | |
| 36 PyObject *traceback; | |
| 37 { | 34 { |
| 38 PyThreadState *tstate = PyThreadState_GET(); | 35 PyThreadState *tstate = PyThreadState_GET(); |
| 39 PyObject *oldtype, *oldvalue, *oldtraceback; | 36 PyObject *oldtype, *oldvalue, *oldtraceback; |
| 40 | 37 |
| 41 if (traceback != NULL && !PyTraceBack_Check(traceback)) { | 38 if (traceback != NULL && !PyTraceBack_Check(traceback)) { |
| 58 Py_XDECREF(oldvalue); | 55 Py_XDECREF(oldvalue); |
| 59 Py_XDECREF(oldtraceback); | 56 Py_XDECREF(oldtraceback); |
| 60 } | 57 } |
| 61 | 58 |
| 62 void | 59 void |
| 63 PyErr_SetObject(exception, value) | 60 PyErr_SetObject(PyObject *exception, PyObject *value) |
| 64 PyObject *exception; | |
| 65 PyObject *value; | |
| 66 { | 61 { |
| 67 Py_XINCREF(exception); | 62 Py_XINCREF(exception); |
| 68 Py_XINCREF(value); | 63 Py_XINCREF(value); |
| 69 PyErr_Restore(exception, value, (PyObject *)NULL); | 64 PyErr_Restore(exception, value, (PyObject *)NULL); |
| 70 } | 65 } |
| 71 | 66 |
| 72 void | 67 void |
| 73 PyErr_SetNone(exception) | 68 PyErr_SetNone(PyObject *exception) |
| 74 PyObject *exception; | |
| 75 { | 69 { |
| 76 PyErr_SetObject(exception, (PyObject *)NULL); | 70 PyErr_SetObject(exception, (PyObject *)NULL); |
| 77 } | 71 } |
| 78 | 72 |
| 79 void | 73 void |
| 80 PyErr_SetString(exception, string) | 74 PyErr_SetString(PyObject *exception, const char *string) |
| 81 PyObject *exception; | |
| 82 const char *string; | |
| 83 { | 75 { |
| 84 PyObject *value = PyString_FromString(string); | 76 PyObject *value = PyString_FromString(string); |
| 85 PyErr_SetObject(exception, value); | 77 PyErr_SetObject(exception, value); |
| 86 Py_XDECREF(value); | 78 Py_XDECREF(value); |
| 87 } | 79 } |
| 88 | 80 |
| 89 | 81 |
| 90 PyObject * | 82 PyObject * |
| 91 PyErr_Occurred() | 83 PyErr_Occurred(void) |
| 92 { | 84 { |
| 93 PyThreadState *tstate = PyThreadState_Get(); | 85 PyThreadState *tstate = PyThreadState_Get(); |
| 94 | 86 |
| 95 return tstate->curexc_type; | 87 return tstate->curexc_type; |
| 96 } | 88 } |
| 97 | 89 |
| 98 | 90 |
| 99 int | 91 int |
| 100 PyErr_GivenExceptionMatches(err, exc) | 92 PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc) |
| 101 PyObject *err, *exc; | |
| 102 { | 93 { |
| 103 if (err == NULL || exc == NULL) { | 94 if (err == NULL || exc == NULL) { |
| 104 /* maybe caused by "import exceptions" that failed early on */ | 95 /* maybe caused by "import exceptions" that failed early on */ |
| 105 return 0; | 96 return 0; |
| 106 } | 97 } |
| 127 return err == exc; | 118 return err == exc; |
| 128 } | 119 } |
| 129 | 120 |
| 130 | 121 |
| 131 int | 122 int |
| 132 PyErr_ExceptionMatches(exc) | 123 PyErr_ExceptionMatches(PyObject *exc) |
| 133 PyObject *exc; | |
| 134 { | 124 { |
| 135 return PyErr_GivenExceptionMatches(PyErr_Occurred(), exc); | 125 return PyErr_GivenExceptionMatches(PyErr_Occurred(), exc); |
| 136 } | 126 } |
| 137 | 127 |
| 138 | 128 |
| 139 /* Used in many places to normalize a raised exception, including in | 129 /* Used in many places to normalize a raised exception, including in |
| 140 eval_code2(), do_raise(), and PyErr_Print() | 130 eval_code2(), do_raise(), and PyErr_Print() |
| 141 */ | 131 */ |
| 142 void | 132 void |
| 143 PyErr_NormalizeException(exc, val, tb) | 133 PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb) |
| 144 PyObject **exc; | |
| 145 PyObject **val; | |
| 146 PyObject **tb; | |
| 147 { | 134 { |
| 148 PyObject *type = *exc; | 135 PyObject *type = *exc; |
| 149 PyObject *value = *val; | 136 PyObject *value = *val; |
| 150 PyObject *inclass = NULL; | 137 PyObject *inclass = NULL; |
| 151 | 138 |
| 211 PyErr_NormalizeException(exc, val, tb); | 198 PyErr_NormalizeException(exc, val, tb); |
| 212 } | 199 } |
| 213 | 200 |
| 214 | 201 |
| 215 void | 202 void |
| 216 PyErr_Fetch(p_type, p_value, p_traceback) | 203 PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) |
| 217 PyObject **p_type; | |
| 218 PyObject **p_value; | |
| 219 PyObject **p_traceback; | |
| 220 { | 204 { |
| 221 PyThreadState *tstate = PyThreadState_Get(); | 205 PyThreadState *tstate = PyThreadState_Get(); |
| 222 | 206 |
| 223 *p_type = tstate->curexc_type; | 207 *p_type = tstate->curexc_type; |
| 224 *p_value = tstate->curexc_value; | 208 *p_value = tstate->curexc_value; |
| 228 tstate->curexc_value = NULL; | 212 tstate->curexc_value = NULL; |
| 229 tstate->curexc_traceback = NULL; | 213 tstate->curexc_traceback = NULL; |
| 230 } | 214 } |
| 231 | 215 |
| 232 void | 216 void |
| 233 PyErr_Clear() | 217 PyErr_Clear(void) |
| 234 { | 218 { |
| 235 PyErr_Restore(NULL, NULL, NULL); | 219 PyErr_Restore(NULL, NULL, NULL); |
| 236 } | 220 } |
| 237 | 221 |
| 238 /* Convenience functions to set a type error exception and return 0 */ | 222 /* Convenience functions to set a type error exception and return 0 */ |
| 239 | 223 |
| 240 int | 224 int |
| 241 PyErr_BadArgument() | 225 PyErr_BadArgument(void) |
| 242 { | 226 { |
| 243 PyErr_SetString(PyExc_TypeError, | 227 PyErr_SetString(PyExc_TypeError, |
| 244 "illegal argument type for built-in operation"); | 228 "illegal argument type for built-in operation"); |
| 245 return 0; | 229 return 0; |
| 246 } | 230 } |
| 247 | 231 |
| 248 PyObject * | 232 PyObject * |
| 249 PyErr_NoMemory() | 233 PyErr_NoMemory(void) |
| 250 { | 234 { |
| 251 /* raise the pre-allocated instance if it still exists */ | 235 /* raise the pre-allocated instance if it still exists */ |
| 252 if (PyExc_MemoryErrorInst) | 236 if (PyExc_MemoryErrorInst) |
| 253 PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst); | 237 PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst); |
| 254 else | 238 else |
| 259 | 243 |
| 260 return NULL; | 244 return NULL; |
| 261 } | 245 } |
| 262 | 246 |
| 263 PyObject * | 247 PyObject * |
| 264 PyErr_SetFromErrnoWithFilename(exc, filename) | 248 PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename) |
| 265 PyObject *exc; | |
| 266 char *filename; | |
| 267 { | 249 { |
| 268 PyObject *v; | 250 PyObject *v; |
| 269 char *s; | 251 char *s; |
| 270 int i = errno; | 252 int i = errno; |
| 271 #ifdef MS_WIN32 | 253 #ifdef MS_WIN32 |
| 324 return NULL; | 306 return NULL; |
| 325 } | 307 } |
| 326 | 308 |
| 327 | 309 |
| 328 PyObject * | 310 PyObject * |
| 329 PyErr_SetFromErrno(exc) | 311 PyErr_SetFromErrno(PyObject *exc) |
| 330 PyObject *exc; | |
| 331 { | 312 { |
| 332 return PyErr_SetFromErrnoWithFilename(exc, NULL); | 313 return PyErr_SetFromErrnoWithFilename(exc, NULL); |
| 333 } | 314 } |
| 334 | 315 |
| 335 #ifdef MS_WINDOWS | 316 #ifdef MS_WINDOWS |
| 336 /* Windows specific error code handling */ | 317 /* Windows specific error code handling */ |
| 337 PyObject *PyErr_SetFromWindowsErrWithFilename( | 318 PyObject *PyErr_SetFromWindowsErrWithFilename( |
| 338 int ierr, | 319 int ierr, |
| 339 const char *filename) | 320 const char *filename) |
| 340 { | 321 { |
| 341 int len; | 322 int len; |
| 342 char *s; | 323 char *s; |
| 343 PyObject *v; | 324 PyObject *v; |
| 376 | 357 |
| 377 } | 358 } |
| 378 #endif /* MS_WINDOWS */ | 359 #endif /* MS_WINDOWS */ |
| 379 | 360 |
| 380 void | 361 void |
| 381 PyErr_BadInternalCall() | 362 PyErr_BadInternalCall(void) |
| 382 { | 363 { |
| 383 PyErr_SetString(PyExc_SystemError, | 364 PyErr_SetString(PyExc_SystemError, |
| 384 "bad argument to internal function"); | 365 "bad argument to internal function"); |
| 385 } | 366 } |
| 386 | 367 |
| 387 | 368 |
| 388 #ifdef HAVE_STDARG_PROTOTYPES | |
| 389 PyObject * | 369 PyObject * |
| 390 PyErr_Format(PyObject *exception, const char *format, ...) | 370 PyErr_Format(PyObject *exception, const char *format, ...) |
| 391 #else | |
| 392 PyObject * | |
| 393 PyErr_Format(exception, format, va_alist) | |
| 394 PyObject *exception; | |
| 395 const char *format; | |
| 396 va_dcl | |
| 397 #endif | |
| 398 { | 371 { |
| 399 va_list vargs; | 372 va_list vargs; |
| 400 char buffer[500]; /* Caller is responsible for limiting the format */ | 373 char buffer[500]; /* Caller is responsible for limiting the format */ |
| 401 | 374 |
| 402 #ifdef HAVE_STDARG_PROTOTYPES | |
| 403 va_start(vargs, format); | 375 va_start(vargs, format); |
| 404 #else | |
| 405 va_start(vargs); | |
| 406 #endif | |
| 407 | 376 |
| 408 vsprintf(buffer, format, vargs); | 377 vsprintf(buffer, format, vargs); |
| 409 PyErr_SetString(exception, buffer); | 378 PyErr_SetString(exception, buffer); |
| 410 return NULL; | 379 return NULL; |
| 411 } | 380 } |
| 412 | 381 |
| 413 | 382 |
| 414 PyObject * | 383 PyObject * |
| 415 PyErr_NewException(name, base, dict) | 384 PyErr_NewException(char *name, PyObject *base, PyObject *dict) |
| 416 char *name; /* modulename.classname */ | |
| 417 PyObject *base; | |
| 418 PyObject *dict; | |
| 419 { | 385 { |
| 420 char *dot; | 386 char *dot; |
| 421 PyObject *modulename = NULL; | 387 PyObject *modulename = NULL; |
| 422 PyObject *classname = NULL; | 388 PyObject *classname = NULL; |
| 423 PyObject *mydict = NULL; | 389 PyObject *mydict = NULL; |
