Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid storing error flags, also decref.
  • Loading branch information
JulienPalard committed May 8, 2019
commit dde48ab4cce847cf93bd4a66cb49a79bd89882cc
16 changes: 11 additions & 5 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void
clear_slotdefs(void);

static PyObject *
lookup_method(PyObject *self, _Py_Identifier *attrid, int *unbound);
lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound);

/*
* finds the beginning of the docstring's introspection signature.
Expand Down Expand Up @@ -305,13 +305,19 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
if (custom) {
_Py_IDENTIFIER(mro);
int unbound;
PyObject *mro_meth = lookup_method((PyObject *)type, &PyId_mro,
&unbound);
PyObject *type_mro_meth = lookup_method((PyObject *)&PyType_Type, &PyId_mro,
&unbound);
PyObject *mro_meth = lookup_maybe_method(
(PyObject *)type, &PyId_mro, &unbound);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mro_meth needs to be checked for NULL before lookup_maybe_method is called again.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK :-] is using a goto legit here? It'll avoid a bunch of if (clear == 0) (see current impl).

PyObject *type_mro_meth = lookup_maybe_method(
(PyObject *)&PyType_Type, &PyId_mro, &unbound);
if (mro_meth == NULL || type_mro_meth == NULL ||
mro_meth != type_mro_meth)
{
clear = 1;
}
if (mro_meth != NULL)
Py_DECREF(mro_meth);
if (type_mro_meth != NULL)
Py_DECREF(type_mro_meth);
}
if (!clear) {
n = PyTuple_GET_SIZE(bases);
Expand Down