diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-28 21:47:42 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-28 21:47:42 (GMT) |
commit | 7759a0cd76105e6685008da7a1e2deb6e0d37c38 (patch) | |
tree | 505e72617a73d473b7ea83dff2df7aa65b042a87 | |
parent | 52716c94be3fa7b7df0160bc1cf5b04ec99f9c72 (diff) | |
download | cpython-7759a0cd76105e6685008da7a1e2deb6e0d37c38.zip cpython-7759a0cd76105e6685008da7a1e2deb6e0d37c38.tar.gz cpython-7759a0cd76105e6685008da7a1e2deb6e0d37c38.tar.bz2 |
Factor-out common code with a new macro
-rw-r--r-- | Include/setobject.h | 2 | ||||
-rw-r--r-- | Objects/setobject.c | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/Include/setobject.h b/Include/setobject.h index 2739d62..fc32367 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -73,6 +73,8 @@ PyAPI_DATA(PyTypeObject) PyFrozenSet_Type; (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \ PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \ PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type)) +#define PySet_Check(ob) \ + (Py_TYPE(ob) == &PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &PySet_Type)) PyAPI_FUNC(PyObject *) PySet_New(PyObject *); PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *); diff --git a/Objects/setobject.c b/Objects/setobject.c index ee11b9f..4b4213a 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -2158,7 +2158,7 @@ PySet_Size(PyObject *anyset) int PySet_Clear(PyObject *set) { - if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { + if (!PySet_Check(set)) { PyErr_BadInternalCall(); return -1; } @@ -2178,7 +2178,7 @@ PySet_Contains(PyObject *anyset, PyObject *key) int PySet_Discard(PyObject *set, PyObject *key) { - if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { + if (!PySet_Check(set)) { PyErr_BadInternalCall(); return -1; } @@ -2229,7 +2229,7 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash) PyObject * PySet_Pop(PyObject *set) { - if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { + if (!PySet_Check(set)) { PyErr_BadInternalCall(); return NULL; } @@ -2239,7 +2239,7 @@ PySet_Pop(PyObject *set) int _PySet_Update(PyObject *set, PyObject *iterable) { - if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { + if (!PySet_Check(set)) { PyErr_BadInternalCall(); return -1; } |