OLD | NEW |
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 #define NEW_STYLE_NUMBER(o) PyType_HasFeature((o)->ob_type, \ | 8 #define NEW_STYLE_NUMBER(o) PyType_HasFeature((o)->ob_type, \ |
9 Py_TPFLAGS_CHECKTYPES) | 9 Py_TPFLAGS_CHECKTYPES) |
10 | 10 |
(...skipping 2891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2902 | 2902 |
2903 return retval; | 2903 return retval; |
2904 } | 2904 } |
2905 | 2905 |
2906 int | 2906 int |
2907 PyObject_IsInstance(PyObject *inst, PyObject *cls) | 2907 PyObject_IsInstance(PyObject *inst, PyObject *cls) |
2908 { | 2908 { |
2909 static PyObject *name = NULL; | 2909 static PyObject *name = NULL; |
2910 PyObject *t, *v, *tb; | 2910 PyObject *t, *v, *tb; |
2911 PyObject *checker; | 2911 PyObject *checker; |
| 2912 |
| 2913 /* Quick test for an exact match */ |
| 2914 if (Py_TYPE(inst) == cls && !PyTuple_Check(cls)) |
| 2915 return 1; |
| 2916 |
2912 PyErr_Fetch(&t, &v, &tb); | 2917 PyErr_Fetch(&t, &v, &tb); |
2913 | |
2914 if (name == NULL) { | 2918 if (name == NULL) { |
2915 name = PyString_InternFromString("__instancecheck__"); | 2919 name = PyString_InternFromString("__instancecheck__"); |
2916 if (name == NULL) | 2920 if (name == NULL) |
2917 return -1; | 2921 return -1; |
2918 } | 2922 } |
2919 checker = PyObject_GetAttr(cls, name); | 2923 checker = PyObject_GetAttr(cls, name); |
2920 PyErr_Restore(t, v, tb); | 2924 PyErr_Restore(t, v, tb); |
2921 if (checker != NULL) { | 2925 if (checker != NULL) { |
2922 PyObject *res; | 2926 PyObject *res; |
2923 int ok = -1; | 2927 int ok = -1; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 { | 3061 { |
3058 PyObject *result; | 3062 PyObject *result; |
3059 assert(PyIter_Check(iter)); | 3063 assert(PyIter_Check(iter)); |
3060 result = (*iter->ob_type->tp_iternext)(iter); | 3064 result = (*iter->ob_type->tp_iternext)(iter); |
3061 if (result == NULL && | 3065 if (result == NULL && |
3062 PyErr_Occurred() && | 3066 PyErr_Occurred() && |
3063 PyErr_ExceptionMatches(PyExc_StopIteration)) | 3067 PyErr_ExceptionMatches(PyExc_StopIteration)) |
3064 PyErr_Clear(); | 3068 PyErr_Clear(); |
3065 return result; | 3069 return result; |
3066 } | 3070 } |
OLD | NEW |