-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-31333: Re-implement ABCMeta in C #5273
Changes from 1 commit
5c34508
cb7ffcf
b83ee80
181e83f
c084a7f
a192d5d
35a2472
4812450
b9038e2
bbee578
a3464fd
947bf7d
7ffc59e
41287a7
569cc44
34665a8
576acac
30098b4
51ede5d
5263e1a
1f7aee9
11fea70
7ff3fbb
9b4eb2f
ab20a33
39f2692
493d0ec
2fe2c54
9476af6
ab68cdb
3eb0a60
ed36b76
25fc5b9
b2f75b9
cdb5cdf
a1a3a52
a66b08c
86af9ae
b22232a
e51c5ca
bac7a43
4571649
0d7513b
c429f49
357b56d
cd80fcb
34e13c3
c5633b6
3cbbc12
23bcb07
0aab479
86e0660
c55e482
5f9526a
8174b61
bb8d623
ef59e54
22699fe
95cbf34
4d596cc
fa3cba3
6f18293
9100891
36c5643
dd2abda
99d950c
3762d49
404d1ce
0dc5fae
287b26a
ef34364
d4d78a1
f58822e
3b74bdc
db1c852
6e62be7
5384726
a48eecc
16a8db1
5ad3ea8
86a9b8d
36c2013
09c5370
207d8e9
a15377b
d31da13
eaff1cb
48de70e
3bd0666
702347a
e0c978b
b370dfe
a1ae0a7
4746211
001b416
fc528df
289c414
ac0c639
079e3be
9c49e5a
4146588
c133605
f82e04d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,8 +269,7 @@ abcmeta_instancecheck(abc *self, PyObject *args) | |
return NULL; | ||
} | ||
if (incache > 0) { | ||
Py_INCREF(Py_True); | ||
return Py_True; | ||
Py_RETURN_TRUE; | ||
} | ||
subtype = (PyObject *)Py_TYPE(instance); | ||
if (subtype == subclass) { | ||
|
@@ -279,8 +278,7 @@ abcmeta_instancecheck(abc *self, PyObject *args) | |
return NULL; | ||
} | ||
if (self->abc_negative_cache_version == abc_invalidation_counter && incache) { | ||
Py_INCREF(Py_False); | ||
return Py_False; | ||
Py_RETURN_FALSE; | ||
} | ||
/* Fall back to the subclass check. */ | ||
return PyObject_CallMethod((PyObject *)self, "__subclasscheck__", "O", subclass); | ||
|
@@ -292,6 +290,7 @@ abcmeta_instancecheck(abc *self, PyObject *args) | |
if (result == Py_True) { | ||
return Py_True; | ||
} | ||
Py_DECREF(result); | ||
return PyObject_CallMethod((PyObject *)self, "__subclasscheck__", "O", subtype); | ||
} | ||
|
||
|
@@ -316,8 +315,7 @@ abcmeta_subclasscheck(abc *self, PyObject *args) | |
return NULL; | ||
} | ||
if (incache > 0) { | ||
Py_INCREF(Py_True); | ||
return Py_True; | ||
Py_RETURN_TRUE; | ||
} | ||
/* 2. Check negative cache; may have to invalidate. */ | ||
incache = _in_weak_set(self->abc_negative_cache, subclass); | ||
|
@@ -332,8 +330,7 @@ abcmeta_subclasscheck(abc *self, PyObject *args) | |
} | ||
self->abc_negative_cache_version = abc_invalidation_counter; | ||
} else if (incache) { | ||
Py_INCREF(Py_False); | ||
return Py_False; | ||
Py_RETURN_FALSE; | ||
} | ||
/* 3. Check the subclass hook. */ | ||
ok = PyObject_CallMethod((PyObject *)self, "__subclasshook__", "O", subclass); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _PyObject_CallMethodIdObjArgs |
||
|
@@ -359,11 +356,10 @@ abcmeta_subclasscheck(abc *self, PyObject *args) | |
mro = ((PyTypeObject *)subclass)->tp_mro; | ||
for (pos = 0; pos < PyTuple_Size(mro); pos++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
if ((PyObject *)self == PyTuple_GetItem(mro, pos)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really? How is it possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, even though it's not possible right now because you are operating strictly within tuple boundaries, the code can be refactored/copy-pasted later, or be accidentally broken otherwise. The function is documented to return NULL in an exceptional situation, so it's a bad style to not check its return value. |
||
Py_INCREF(Py_True); | ||
if (!_add_weak_set(self->abc_cache, subclass)) { | ||
return NULL; | ||
} | ||
return Py_True; | ||
Py_RETURN_TRUE; | ||
} | ||
} | ||
/* 5. Check if it's a subclass of a registered class (recursive). */ | ||
|
@@ -380,8 +376,7 @@ abcmeta_subclasscheck(abc *self, PyObject *args) | |
if (!_add_weak_set(self->abc_cache, subclass)) { | ||
return NULL; | ||
} | ||
Py_INCREF(Py_True); | ||
return Py_True; | ||
Py_RETURN_TRUE; | ||
} | ||
if (result < 0) { | ||
Py_DECREF(key); | ||
|
@@ -400,8 +395,7 @@ abcmeta_subclasscheck(abc *self, PyObject *args) | |
return NULL; | ||
} | ||
Py_DECREF(subclasses); | ||
Py_INCREF(Py_True); | ||
return Py_True; | ||
Py_RETURN_TRUE; | ||
} | ||
if (result < 0) { | ||
Py_DECREF(subclasses); | ||
|
@@ -413,8 +407,7 @@ abcmeta_subclasscheck(abc *self, PyObject *args) | |
if (!_add_weak_set(self->abc_negative_cache, subclass)) { | ||
return NULL; | ||
} | ||
Py_INCREF(Py_False); | ||
return Py_False; | ||
Py_RETURN_FALSE; | ||
} | ||
|
||
int | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will produce warnings that not all possible return values are handled on some compilers. I suggest to add a
default: Py_UNREACHABLE()
case.