Skip to content

Commit

Permalink
bpo-39573: Update clinic to use Py_IS_TYPE() function (GH-18507)
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 authored Feb 14, 2020
1 parent d212c3c commit 9aeb0ef
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update clinic tool to use :c:func:`Py_IS_TYPE`. Patch by Dong-hee Na.
4 changes: 2 additions & 2 deletions Modules/_io/clinic/bufferedio.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *writer;
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;

if ((Py_TYPE(self) == &PyBufferedRWPair_Type) &&
if (Py_IS_TYPE(self, &PyBufferedRWPair_Type) &&
!_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
goto exit;
}
Expand Down Expand Up @@ -672,4 +672,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=7246104f6c7d3167 input=a9049054013a1b77]*/
/*[clinic end generated code: output=7d9ad40c95bdd808 input=a9049054013a1b77]*/
8 changes: 4 additions & 4 deletions Modules/clinic/_bz2module.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Objects/clinic/listobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3585,17 +3585,14 @@ def set_template_dict(self, template_dict):
cls = self.function.cls

if ((kind in (METHOD_NEW, METHOD_INIT)) and cls and cls.typedef):
type_object = self.function.cls.type_object
if kind == METHOD_NEW:
passed_in_type = self.name
type_check = '({} == {})'.format(self.name, type_object)
else:
passed_in_type = 'Py_TYPE({})'.format(self.name)

line = '({passed_in_type} == {type_object}) &&\n '
d = {
'type_object': self.function.cls.type_object,
'passed_in_type': passed_in_type
}
template_dict['self_type_check'] = line.format_map(d)
type_check = 'Py_IS_TYPE({}, {})'.format(self.name, type_object)

line = '{} &&\n '.format(type_check)
template_dict['self_type_check'] = line



Expand Down

0 comments on commit 9aeb0ef

Please sign in to comment.