comparison Python/errors.c @ 12559:3b8d9e63e4e1 legacy-trunk

PyErr_GivenExceptionMatches(): Check for err==NULL and exc==NULL and return 0 (exceptions don't match). This means that if an ImportError is raised because exceptions.py can't be imported, the interpreter will exit "cleanly" with an error message instead of just core dumping. PyErr_SetFromErrnoWithFilename(), PyErr_SetFromWindowsErrWithFilename(): Don't test on Py_UseClassExceptionsFlag.
author Barry Warsaw <barry@python.org>
date Tue, 02 May 2000 19:27:51 +0000
parents 723efcdcce1b
children 916fb024ce94
comparison
equal deleted inserted replaced
12558:4df8462a259d 12559:3b8d9e63e4e1
123 123
124 int 124 int
125 PyErr_GivenExceptionMatches(err, exc) 125 PyErr_GivenExceptionMatches(err, exc)
126 PyObject *err, *exc; 126 PyObject *err, *exc;
127 { 127 {
128 if (err == NULL || exc == NULL) {
129 /* maybe caused by "import exceptions" that failed early on */
130 return 0;
131 }
128 if (PyTuple_Check(exc)) { 132 if (PyTuple_Check(exc)) {
129 int i, n; 133 int i, n;
130 n = PyTuple_Size(exc); 134 n = PyTuple_Size(exc);
131 for (i = 0; i < n; i++) { 135 for (i = 0; i < n; i++) {
132 /* Test recursively */ 136 /* Test recursively */
329 while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.')) 333 while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))
330 s[--len] = '\0'; 334 s[--len] = '\0';
331 } 335 }
332 } 336 }
333 #endif 337 #endif
334 if (filename != NULL && Py_UseClassExceptionsFlag) 338 if (filename != NULL)
335 v = Py_BuildValue("(iss)", i, s, filename); 339 v = Py_BuildValue("(iss)", i, s, filename);
336 else 340 else
337 v = Py_BuildValue("(is)", i, s); 341 v = Py_BuildValue("(is)", i, s);
338 if (v != NULL) { 342 if (v != NULL) {
339 PyErr_SetObject(exc, v); 343 PyErr_SetObject(exc, v);
377 0, /* size not used */ 381 0, /* size not used */
378 NULL); /* no args */ 382 NULL); /* no args */
379 /* remove trailing cr/lf and dots */ 383 /* remove trailing cr/lf and dots */
380 while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.')) 384 while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))
381 s[--len] = '\0'; 385 s[--len] = '\0';
382 if (filename != NULL && Py_UseClassExceptionsFlag) 386 if (filename != NULL)
383 v = Py_BuildValue("(iss)", err, s, filename); 387 v = Py_BuildValue("(iss)", err, s, filename);
384 else 388 else
385 v = Py_BuildValue("(is)", err, s); 389 v = Py_BuildValue("(is)", err, s);
386 if (v != NULL) { 390 if (v != NULL) {
387 PyErr_SetObject(PyExc_WindowsError, v); 391 PyErr_SetObject(PyExc_WindowsError, v);