Kaydet (Commit) 7759a0cd authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Factor-out common code with a new macro

üst 52716c94
...@@ -73,6 +73,8 @@ PyAPI_DATA(PyTypeObject) PyFrozenSet_Type; ...@@ -73,6 +73,8 @@ PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
(Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \ (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \
PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \ PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \
PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_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 *) PySet_New(PyObject *);
PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *); PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);
......
...@@ -2158,7 +2158,7 @@ PySet_Size(PyObject *anyset) ...@@ -2158,7 +2158,7 @@ PySet_Size(PyObject *anyset)
int int
PySet_Clear(PyObject *set) PySet_Clear(PyObject *set)
{ {
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { if (!PySet_Check(set)) {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return -1; return -1;
} }
...@@ -2178,7 +2178,7 @@ PySet_Contains(PyObject *anyset, PyObject *key) ...@@ -2178,7 +2178,7 @@ PySet_Contains(PyObject *anyset, PyObject *key)
int int
PySet_Discard(PyObject *set, PyObject *key) PySet_Discard(PyObject *set, PyObject *key)
{ {
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { if (!PySet_Check(set)) {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return -1; return -1;
} }
...@@ -2229,7 +2229,7 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash) ...@@ -2229,7 +2229,7 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash)
PyObject * PyObject *
PySet_Pop(PyObject *set) PySet_Pop(PyObject *set)
{ {
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { if (!PySet_Check(set)) {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return NULL; return NULL;
} }
...@@ -2239,7 +2239,7 @@ PySet_Pop(PyObject *set) ...@@ -2239,7 +2239,7 @@ PySet_Pop(PyObject *set)
int int
_PySet_Update(PyObject *set, PyObject *iterable) _PySet_Update(PyObject *set, PyObject *iterable)
{ {
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { if (!PySet_Check(set)) {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment