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
Avoid calling tp_compare with different types #40621
Comments
C implementations of the tp_compare slot usually expect both of their Other options for fixing the problem:
Addresses bug bpo-980352 |
Logged In: YES Is your patch complete? There seem to be a lot of places in object.c that call tp_compare slots. Shouldn't we try to make sure that none of these places can ever be called with two different types? It also looks like we have to do something special about a value of &_PyObject_SlotCompare in tp_compare, because this function from typeobject.c checks itself the type of its arguments and does specific things with them. This should be thought about. Moreover there is the issue of the user subclassing built-in types, e.g. PyInt_Type.tp_compare is capable of comparing different user subclasses of "int" for each other. |
Logged In: YES The patch is intended to be complete, but it's certainly possible that I I'm actually more concerned about restricting too much than having Comparing subclasses of builtins to builtins still works, too. On line 599 /* If both have the same (non-NULL) tp_compare, use it. */
if (f != NULL && f == w->ob_type->tp_compare) {
c = (*f)(v, w);
return adjust_tp_compare(c);
} which takes care of that case. |
Logged In: YES Sorry, I did not read well enough what object.c was doing. Before rich comparison, there was no obvious sane way to
There is no other reasonable safe way that I can of to fix A note about the patch: in the first comment you say that v The new single test introduced after PyNumber_CoerceEx() |
Logged In: YES I added a minor change after the coercion, to accept two Applied as planned in the 2.5 CVS as:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: