diff options
Diffstat (limited to 'Include')
-rw-r--r-- | Include/dictobject.h | 3 | ||||
-rw-r--r-- | Include/listobject.h | 3 | ||||
-rw-r--r-- | Include/longobject.h | 3 | ||||
-rw-r--r-- | Include/object.h | 15 | ||||
-rw-r--r-- | Include/pyerrors.h | 11 | ||||
-rw-r--r-- | Include/stringobject.h | 3 | ||||
-rw-r--r-- | Include/tupleobject.h | 3 | ||||
-rw-r--r-- | Include/unicodeobject.h | 3 |
8 files changed, 31 insertions, 13 deletions
diff --git a/Include/dictobject.h b/Include/dictobject.h index 44b0838..ec2e0c8 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -90,7 +90,8 @@ struct _dictobject { PyAPI_DATA(PyTypeObject) PyDict_Type; -#define PyDict_Check(op) PyObject_TypeCheck(op, &PyDict_Type) +#define PyDict_Check(op) \ + PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_DICT_SUBCLASS) #define PyDict_CheckExact(op) ((op)->ob_type == &PyDict_Type) PyAPI_FUNC(PyObject *) PyDict_New(void); diff --git a/Include/listobject.h b/Include/listobject.h index d9012ce..db3124e 100644 --- a/Include/listobject.h +++ b/Include/listobject.h @@ -40,7 +40,8 @@ typedef struct { PyAPI_DATA(PyTypeObject) PyList_Type; -#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type) +#define PyList_Check(op) \ + PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LIST_SUBCLASS) #define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type) PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size); diff --git a/Include/longobject.h b/Include/longobject.h index 7f2cda6..b7a29b5 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -11,7 +11,8 @@ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */ PyAPI_DATA(PyTypeObject) PyLong_Type; -#define PyLong_Check(op) PyObject_TypeCheck(op, &PyLong_Type) +#define PyLong_Check(op) \ + PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LONG_SUBCLASS) #define PyLong_CheckExact(op) ((op)->ob_type == &PyLong_Type) PyAPI_FUNC(PyObject *) PyLong_FromLong(long); diff --git a/Include/object.h b/Include/object.h index 0c5fa42..40e52e3 100644 --- a/Include/object.h +++ b/Include/object.h @@ -357,7 +357,8 @@ PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */ PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ -#define PyType_Check(op) PyObject_TypeCheck(op, &PyType_Type) +#define PyType_Check(op) \ + PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TYPE_SUBCLASS) #define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type) PyAPI_FUNC(int) PyType_Ready(PyTypeObject *); @@ -469,11 +470,23 @@ given type object has a specified feature. #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0 #endif +/* These flags are used to determine if a type is a subclass. */ +#define Py_TPFLAGS_INT_SUBCLASS (1L<<23) +#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24) +#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25) +#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26) +#define Py_TPFLAGS_STRING_SUBCLASS (1L<<27) +#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28) +#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29) +#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30) +#define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31) + #define Py_TPFLAGS_DEFAULT ( \ Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \ 0) #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0) +#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f) /* diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 67f1909..562af10 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -94,13 +94,12 @@ PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); /* */ -#define PyExceptionClass_Check(x) \ - (PyType_Check((x)) && PyType_IsSubtype( \ - (PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException)) +#define PyExceptionClass_Check(x) \ + (PyType_Check((x)) && \ + PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)) - -#define PyExceptionInstance_Check(x) \ - (PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException)) +#define PyExceptionInstance_Check(x) \ + PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) #define PyExceptionClass_Name(x) \ ((char *)(((PyTypeObject*)(x))->tp_name)) diff --git a/Include/stringobject.h b/Include/stringobject.h index ef8f545..8156193 100644 --- a/Include/stringobject.h +++ b/Include/stringobject.h @@ -55,7 +55,8 @@ typedef struct { PyAPI_DATA(PyTypeObject) PyBaseString_Type; PyAPI_DATA(PyTypeObject) PyString_Type; -#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type) +#define PyString_Check(op) \ + PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_STRING_SUBCLASS) #define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type) PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t); diff --git a/Include/tupleobject.h b/Include/tupleobject.h index 8c37cab..738cea1 100644 --- a/Include/tupleobject.h +++ b/Include/tupleobject.h @@ -33,7 +33,8 @@ typedef struct { PyAPI_DATA(PyTypeObject) PyTuple_Type; -#define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type) +#define PyTuple_Check(op) \ + PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TUPLE_SUBCLASS) #define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type) PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 33aa185..0bad8c3 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -392,7 +392,8 @@ typedef struct { PyAPI_DATA(PyTypeObject) PyUnicode_Type; -#define PyUnicode_Check(op) PyObject_TypeCheck(op, &PyUnicode_Type) +#define PyUnicode_Check(op) \ + PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_UNICODE_SUBCLASS) #define PyUnicode_CheckExact(op) ((op)->ob_type == &PyUnicode_Type) /* Fast access macros */ |