[Patches] [ python-Patches-995939 ] Avoid calling tp_compare with
different types
SourceForge.net
noreply at sourceforge.net
Thu Jul 22 16:14:25 CEST 2004
Patches item #995939, was opened at 2004-07-22 14:14
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=995939&group_id=5470
Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Dima Dorfman (ddorfman)
Assigned to: Nobody/Anonymous (nobody)
Summary: Avoid calling tp_compare with different types
Initial Comment:
C implementations of the tp_compare slot usually expect both of their
arguments to have the type for which that slot is defined (this isn't
documented anywhere that I can find, but many core types assume this,
and extension authors are likely to do the same). A problem occurs if a
user-defined nb_coerce slot (__coerce__) returns objects with different
types. Avoid the problem by refusing to call a non-Python tp_compare
unless the arguments have the same type. Indiscriminately calling
tp_compare with different types is wrong as long as there are
implementations that don't check the type of the second argument, but
Python implementations should be allowed to receive a different type.
Other options for fixing the problem:
- Make PyNumber_CoerceEx require that the results have the same
type. This would prevent a user-defined __coerce__ from
communicating an arbitrary object to a user-defined __cmp__.
Furthermore, there are uses for coerce besides comparison, and those
uses might not require identical types.
- Change tp_compare implementations to check the type of the
second argument. This might be the most desirable long-term solution,
but as I understand it, tp_richcompare is preferred over tp_compare for
new code, and old (current) code is likely assuming that the types are
the same.
Addresses bug #980352
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=995939&group_id=5470
More information about the Patches
mailing list