Skip to content

Commit e4b91d7

Browse files
committed
Ditch obsolete tp_compare implementation.
We can use tp_richcompare for all supported Python versions.
1 parent 40f7086 commit e4b91d7

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

src/runtime/classbase.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public virtual IntPtr type_subscript(IntPtr idx)
6767
//====================================================================
6868
// Standard comparison implementation for instances of reflected types.
6969
//====================================================================
70-
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
70+
7171
public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
7272
CLRObject co1;
7373
CLRObject co2;
@@ -169,27 +169,6 @@ public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
169169
return Runtime.PyNotImplemented;
170170
}
171171
}
172-
#else
173-
public static int tp_compare(IntPtr ob, IntPtr other)
174-
{
175-
if (ob == other)
176-
{
177-
return 0;
178-
}
179-
180-
CLRObject co1 = GetManagedObject(ob) as CLRObject;
181-
CLRObject co2 = GetManagedObject(other) as CLRObject;
182-
Object o1 = co1.inst;
183-
Object o2 = co2.inst;
184-
185-
if (Object.Equals(o1, o2))
186-
{
187-
return 0;
188-
}
189-
return -1;
190-
}
191-
#endif
192-
193172

194173
//====================================================================
195174
// Standard iteration support for instances of reflected types. This

src/runtime/runtime.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ internal static void Initialize()
232232
}
233233

234234
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
235-
IntPtr op = Runtime.PyImport_ImportModule("builtins");
236-
IntPtr dict = Runtime.PyObject_GetAttrString(op, "__dict__");
237-
PyNotImplemented = Runtime.PyObject_GetAttrString(op, "NotImplemented");
235+
IntPtr op = Runtime.PyImport_ImportModule("builtins");
236+
IntPtr dict = Runtime.PyObject_GetAttrString(op, "__dict__");
238237
#else
239238
IntPtr dict = Runtime.PyImport_GetModuleDict();
240239
IntPtr op = Runtime.PyDict_GetItemString(dict, "__builtin__");
241240
#endif
241+
PyNotImplemented = Runtime.PyObject_GetAttrString(op, "NotImplemented");
242242
PyBaseObjectType = Runtime.PyObject_GetAttrString(op, "object");
243243

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

265265
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
266-
Runtime.XDecref(dict);
266+
Runtime.XDecref(dict);
267267
#endif
268268

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

277277
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
278-
op = Runtime.PyBytes_FromString("bytes");
279-
PyBytesType = Runtime.PyObject_Type(op);
280-
Runtime.XDecref(op);
278+
op = Runtime.PyBytes_FromString("bytes");
279+
PyBytesType = Runtime.PyObject_Type(op);
280+
Runtime.XDecref(op);
281281
#endif
282282

283283
op = Runtime.PyTuple_New(0);
@@ -397,17 +397,18 @@ internal static int AtExit()
397397
internal static IntPtr PyTypeType;
398398

399399
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
400-
internal static IntPtr PyBytesType;
401-
internal static IntPtr PyNotImplemented;
402-
internal const int Py_LT = 0;
403-
internal const int Py_LE = 1;
404-
internal const int Py_EQ = 2;
405-
internal const int Py_NE = 3;
406-
internal const int Py_GT = 4;
407-
internal const int Py_GE = 5;
408-
internal static IntPtr _PyObject_NextNotImplemented;
400+
internal static IntPtr PyBytesType;
401+
internal static IntPtr _PyObject_NextNotImplemented;
409402
#endif
410403

404+
internal static IntPtr PyNotImplemented;
405+
internal const int Py_LT = 0;
406+
internal const int Py_LE = 1;
407+
internal const int Py_EQ = 2;
408+
internal const int Py_NE = 3;
409+
internal const int Py_GT = 4;
410+
internal const int Py_GE = 5;
411+
411412
internal static IntPtr PyTrue;
412413
internal static IntPtr PyFalse;
413414
internal static IntPtr PyNone;

0 commit comments

Comments
 (0)