Skip to content
Merged
Show file tree
Hide file tree
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
Ditch obsolete tp_compare implementation.
We can use tp_richcompare for all supported Python versions.
  • Loading branch information
filmor committed Nov 25, 2016
commit fa94ada648e6992963db16b19c8d8b95c3e13b71
23 changes: 1 addition & 22 deletions src/runtime/classbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public virtual IntPtr type_subscript(IntPtr idx)
//====================================================================
// Standard comparison implementation for instances of reflected types.
//====================================================================
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)

public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
CLRObject co1;
CLRObject co2;
Expand Down Expand Up @@ -169,27 +169,6 @@ public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
return Runtime.PyNotImplemented;
}
}
#else
public static int tp_compare(IntPtr ob, IntPtr other)
{
if (ob == other)
{
return 0;
}

CLRObject co1 = GetManagedObject(ob) as CLRObject;
CLRObject co2 = GetManagedObject(other) as CLRObject;
Object o1 = co1.inst;
Object o2 = co2.inst;

if (Object.Equals(o1, o2))
{
return 0;
}
return -1;
}
#endif


//====================================================================
// Standard iteration support for instances of reflected types. This
Expand Down
33 changes: 17 additions & 16 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ internal static void Initialize()
}

#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
IntPtr op = Runtime.PyImport_ImportModule("builtins");
IntPtr dict = Runtime.PyObject_GetAttrString(op, "__dict__");
PyNotImplemented = Runtime.PyObject_GetAttrString(op, "NotImplemented");
IntPtr op = Runtime.PyImport_ImportModule("builtins");
IntPtr dict = Runtime.PyObject_GetAttrString(op, "__dict__");
#else
IntPtr dict = Runtime.PyImport_GetModuleDict();
IntPtr op = Runtime.PyDict_GetItemString(dict, "__builtin__");
#endif
PyNotImplemented = Runtime.PyObject_GetAttrString(op, "NotImplemented");
PyBaseObjectType = Runtime.PyObject_GetAttrString(op, "object");

PyModuleType = Runtime.PyObject_Type(op);
Expand All @@ -263,7 +263,7 @@ internal static void Initialize()
Runtime.XDecref(op);

#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
Runtime.XDecref(dict);
Runtime.XDecref(dict);
#endif

op = Runtime.PyString_FromString("string");
Expand All @@ -275,9 +275,9 @@ internal static void Initialize()
Runtime.XDecref(op);

#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
op = Runtime.PyBytes_FromString("bytes");
PyBytesType = Runtime.PyObject_Type(op);
Runtime.XDecref(op);
op = Runtime.PyBytes_FromString("bytes");
PyBytesType = Runtime.PyObject_Type(op);
Runtime.XDecref(op);
#endif

op = Runtime.PyTuple_New(0);
Expand Down Expand Up @@ -397,17 +397,18 @@ internal static int AtExit()
internal static IntPtr PyTypeType;

#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
internal static IntPtr PyBytesType;
internal static IntPtr PyNotImplemented;
internal const int Py_LT = 0;
internal const int Py_LE = 1;
internal const int Py_EQ = 2;
internal const int Py_NE = 3;
internal const int Py_GT = 4;
internal const int Py_GE = 5;
internal static IntPtr _PyObject_NextNotImplemented;
internal static IntPtr PyBytesType;
internal static IntPtr _PyObject_NextNotImplemented;
#endif

internal static IntPtr PyNotImplemented;
internal const int Py_LT = 0;
internal const int Py_LE = 1;
internal const int Py_EQ = 2;
internal const int Py_NE = 3;
internal const int Py_GT = 4;
internal const int Py_GE = 5;

internal static IntPtr PyTrue;
internal static IntPtr PyFalse;
internal static IntPtr PyNone;
Expand Down