Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(169698)

Side by Side Diff: Objects/abstract.c

Issue 1574217: isinstance swallows exceptions
Patch Set: Created 9 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_isinstance.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Abstract Object Interface (many thanks to Jim Fulton) */ 1 /* Abstract Object Interface (many thanks to Jim Fulton) */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include <ctype.h> 4 #include <ctype.h>
5 #include "structmember.h" /* we need the offsetof() macro from there */ 5 #include "structmember.h" /* we need the offsetof() macro from there */
6 #include "longintrepr.h" 6 #include "longintrepr.h"
7 7
8 8
9 9
10 /* Shorthands to return certain errors */ 10 /* Shorthands to return certain errors */
(...skipping 2490 matching lines...) Expand 10 before | Expand all | Expand 10 after
2501 __class__ = PyUnicode_InternFromString("__class__"); 2501 __class__ = PyUnicode_InternFromString("__class__");
2502 if (__class__ == NULL) 2502 if (__class__ == NULL)
2503 return -1; 2503 return -1;
2504 } 2504 }
2505 2505
2506 if (PyType_Check(cls)) { 2506 if (PyType_Check(cls)) {
2507 retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls); 2507 retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
2508 if (retval == 0) { 2508 if (retval == 0) {
2509 PyObject *c = PyObject_GetAttr(inst, __class__); 2509 PyObject *c = PyObject_GetAttr(inst, __class__);
2510 if (c == NULL) { 2510 if (c == NULL) {
2511 PyErr_Clear(); 2511 if(PyErr_ExceptionMatches(PyExc_AttributeError)) {
2512 PyErr_Clear();
2513 }
2514 else {
2515 retval = -1;
2516 }
2512 } 2517 }
2513 else { 2518 else {
2514 if (c != (PyObject *)(inst->ob_type) && 2519 if (c != (PyObject *)(inst->ob_type) &&
2515 PyType_Check(c)) 2520 PyType_Check(c))
2516 retval = PyType_IsSubtype( 2521 retval = PyType_IsSubtype(
2517 (PyTypeObject *)c, 2522 (PyTypeObject *)c,
2518 (PyTypeObject *)cls); 2523 (PyTypeObject *)cls);
2519 Py_DECREF(c); 2524 Py_DECREF(c);
2520 } 2525 }
2521 } 2526 }
2522 } 2527 }
2523 else { 2528 else {
2524 if (!check_class(cls, 2529 if (!check_class(cls,
2525 "isinstance() arg 2 must be a type or tuple of types")) 2530 "isinstance() arg 2 must be a type or tuple of types"))
2526 return -1; 2531 return -1;
2527 icls = PyObject_GetAttr(inst, __class__); 2532 icls = PyObject_GetAttr(inst, __class__);
2528 if (icls == NULL) { 2533 if (icls == NULL) {
2529 PyErr_Clear(); 2534 if(PyErr_ExceptionMatches(PyExc_AttributeError)) {
2530 retval = 0; 2535 PyErr_Clear();
2536 }
2537 else {
2538 retval = -1;
2539 }
2531 } 2540 }
2532 else { 2541 else {
2533 retval = abstract_issubclass(icls, cls); 2542 retval = abstract_issubclass(icls, cls);
2534 Py_DECREF(icls); 2543 Py_DECREF(icls);
2535 } 2544 }
2536 } 2545 }
2537 2546
2538 return retval; 2547 return retval;
2539 } 2548 }
2540 2549
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2766 /* Free's a NULL terminated char** array of C strings. */ 2775 /* Free's a NULL terminated char** array of C strings. */
2767 void 2776 void
2768 _Py_FreeCharPArray(char *const array[]) 2777 _Py_FreeCharPArray(char *const array[])
2769 { 2778 {
2770 Py_ssize_t i; 2779 Py_ssize_t i;
2771 for (i = 0; array[i] != NULL; ++i) { 2780 for (i = 0; array[i] != NULL; ++i) {
2772 free(array[i]); 2781 free(array[i]);
2773 } 2782 }
2774 free((void*)array); 2783 free((void*)array);
2775 } 2784 }
OLDNEW
« no previous file with comments | « Lib/test/test_isinstance.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+