Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fc7df0e6
Commit
fc7df0e6
authored
Mar 07, 2018
by
INADA Naoki
Committed by
GitHub
Mar 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-32999: Fix ABC.__subclasscheck__ crash (GH-6002)
parent
bc3f2289
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
12 deletions
+45
-12
Lib/test/test_abc.py
Lib/test/test_abc.py
+18
-0
Misc/NEWS.d/next/Library/2018-03-06-20-30-20.bpo-32999.lgFXWl.rst
...S.d/next/Library/2018-03-06-20-30-20.bpo-32999.lgFXWl.rst
+2
-0
Modules/_abc.c
Modules/_abc.c
+25
-12
No files found.
Lib/test/test_abc.py
View file @
fc7df0e6
...
@@ -392,6 +392,24 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
...
@@ -392,6 +392,24 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
self
.
assertIsInstance
(
42
,
A
)
self
.
assertIsInstance
(
42
,
A
)
self
.
assertIsInstance
(
42
,
(
A
,))
self
.
assertIsInstance
(
42
,
(
A
,))
def
test_issubclass_bad_arguments
(
self
):
class
A
(
metaclass
=
abc_ABCMeta
):
pass
with
self
.
assertRaises
(
TypeError
):
issubclass
({},
A
)
# unhashable
with
self
.
assertRaises
(
TypeError
):
issubclass
(
42
,
A
)
# No __mro__
# Python version supports any iterable as __mro__.
# But it's implementation detail and don't emulate it in C version.
class
C
:
__mro__
=
42
# __mro__ is not tuple
with
self
.
assertRaises
(
TypeError
):
issubclass
(
C
(),
A
)
def
test_all_new_methods_are_called
(
self
):
def
test_all_new_methods_are_called
(
self
):
class
A
(
metaclass
=
abc_ABCMeta
):
class
A
(
metaclass
=
abc_ABCMeta
):
pass
pass
...
...
Misc/NEWS.d/next/Library/2018-03-06-20-30-20.bpo-32999.lgFXWl.rst
0 → 100644
View file @
fc7df0e6
Fix C implemetation of ``ABC.__subclasscheck__(cls, subclass)`` crashed when
``subclass`` is not a type object.
Modules/_abc.c
View file @
fc7df0e6
...
@@ -16,6 +16,7 @@ _Py_IDENTIFIER(__abstractmethods__);
...
@@ -16,6 +16,7 @@ _Py_IDENTIFIER(__abstractmethods__);
_Py_IDENTIFIER
(
__class__
);
_Py_IDENTIFIER
(
__class__
);
_Py_IDENTIFIER
(
__dict__
);
_Py_IDENTIFIER
(
__dict__
);
_Py_IDENTIFIER
(
__bases__
);
_Py_IDENTIFIER
(
__bases__
);
_Py_IDENTIFIER
(
__mro__
);
_Py_IDENTIFIER
(
_abc_impl
);
_Py_IDENTIFIER
(
_abc_impl
);
_Py_IDENTIFIER
(
__subclasscheck__
);
_Py_IDENTIFIER
(
__subclasscheck__
);
_Py_IDENTIFIER
(
__subclasshook__
);
_Py_IDENTIFIER
(
__subclasshook__
);
...
@@ -568,7 +569,7 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
...
@@ -568,7 +569,7 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
PyObject
*
subclass
)
PyObject
*
subclass
)
/*[clinic end generated code: output=b56c9e4a530e3894 input=1d947243409d10b8]*/
/*[clinic end generated code: output=b56c9e4a530e3894 input=1d947243409d10b8]*/
{
{
PyObject
*
ok
,
*
mro
,
*
subclasses
=
NULL
,
*
result
=
NULL
;
PyObject
*
ok
,
*
mro
=
NULL
,
*
subclasses
=
NULL
,
*
result
=
NULL
;
Py_ssize_t
pos
;
Py_ssize_t
pos
;
int
incache
;
int
incache
;
_abc_data
*
impl
=
_get_impl
(
self
);
_abc_data
*
impl
=
_get_impl
(
self
);
...
@@ -637,20 +638,31 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
...
@@ -637,20 +638,31 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
}
}
Py_DECREF
(
ok
);
Py_DECREF
(
ok
);
/* 4. Check if it's a direct subclass. */
/* 4. Check if it's a direct subclass.
mro
=
((
PyTypeObject
*
)
subclass
)
->
tp_mro
;
*
assert
(
PyTuple_Check
(
mro
));
* if cls in getattr(subclass, '__mro__', ()):
for
(
pos
=
0
;
pos
<
PyTuple_GET_SIZE
(
mro
);
pos
++
)
{
* cls._abc_cache.add(subclass)
PyObject
*
mro_item
=
PyTuple_GET_ITEM
(
mro
,
pos
);
* return True
if
(
mro_item
==
NULL
)
{
*/
if
(
_PyObject_LookupAttrId
(
subclass
,
&
PyId___mro__
,
&
mro
)
<
0
)
{
goto
end
;
}
if
(
mro
!=
NULL
)
{
if
(
!
PyTuple_Check
(
mro
))
{
// Python version supports non-tuple iterable. Keep it as
// implementation detail.
PyErr_SetString
(
PyExc_TypeError
,
"__mro__ is not a tuple"
);
goto
end
;
goto
end
;
}
}
if
((
PyObject
*
)
self
==
mro_item
)
{
for
(
pos
=
0
;
pos
<
PyTuple_GET_SIZE
(
mro
);
pos
++
)
{
if
(
_add_to_weak_set
(
&
impl
->
_abc_cache
,
subclass
)
<
0
)
{
PyObject
*
mro_item
=
PyTuple_GET_ITEM
(
mro
,
pos
);
if
((
PyObject
*
)
self
==
mro_item
)
{
if
(
_add_to_weak_set
(
&
impl
->
_abc_cache
,
subclass
)
<
0
)
{
goto
end
;
}
result
=
Py_True
;
goto
end
;
goto
end
;
}
}
result
=
Py_True
;
goto
end
;
}
}
}
}
...
@@ -690,7 +702,8 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
...
@@ -690,7 +702,8 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
result
=
Py_False
;
result
=
Py_False
;
end:
end:
Py_XDECREF
(
impl
);
Py_DECREF
(
impl
);
Py_XDECREF
(
mro
);
Py_XDECREF
(
subclasses
);
Py_XDECREF
(
subclasses
);
Py_XINCREF
(
result
);
Py_XINCREF
(
result
);
return
result
;
return
result
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment