|
@@ -2536,7 +2536,7 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (NeedsARichCompareFunction(obj->_itype)) {
|
|
|
|
|
|
|
+ if (NeedsARichCompareFunction(obj->_itype) || slots.count("tp_compare")) {
|
|
|
out << "//////////////////\n";
|
|
out << "//////////////////\n";
|
|
|
out << "// A rich comparison function\n";
|
|
out << "// A rich comparison function\n";
|
|
|
out << "// " << ClassName << "\n";
|
|
out << "// " << ClassName << "\n";
|
|
@@ -2547,7 +2547,6 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
out << " return nullptr;\n";
|
|
out << " return nullptr;\n";
|
|
|
out << " }\n\n";
|
|
out << " }\n\n";
|
|
|
|
|
|
|
|
- out << " switch (op) {\n";
|
|
|
|
|
for (fi = obj->_methods.begin(); fi != obj->_methods.end(); ++fi) {
|
|
for (fi = obj->_methods.begin(); fi != obj->_methods.end(); ++fi) {
|
|
|
std::set<FunctionRemap*> remaps;
|
|
std::set<FunctionRemap*> remaps;
|
|
|
Function *func = (*fi);
|
|
Function *func = (*fi);
|
|
@@ -2564,21 +2563,28 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
const string &fname = func->_ifunc.get_name();
|
|
const string &fname = func->_ifunc.get_name();
|
|
|
|
|
+ const char *op_type;
|
|
|
if (fname == "operator <") {
|
|
if (fname == "operator <") {
|
|
|
- out << " case Py_LT:\n";
|
|
|
|
|
|
|
+ op_type = "Py_LT";
|
|
|
} else if (fname == "operator <=") {
|
|
} else if (fname == "operator <=") {
|
|
|
- out << " case Py_LE:\n";
|
|
|
|
|
|
|
+ op_type = "Py_LE";
|
|
|
} else if (fname == "operator ==") {
|
|
} else if (fname == "operator ==") {
|
|
|
- out << " case Py_EQ:\n";
|
|
|
|
|
|
|
+ op_type = "Py_EQ";
|
|
|
} else if (fname == "operator !=") {
|
|
} else if (fname == "operator !=") {
|
|
|
- out << " case Py_NE:\n";
|
|
|
|
|
|
|
+ op_type = "Py_NE";
|
|
|
} else if (fname == "operator >") {
|
|
} else if (fname == "operator >") {
|
|
|
- out << " case Py_GT:\n";
|
|
|
|
|
|
|
+ op_type = "Py_GT";
|
|
|
} else if (fname == "operator >=") {
|
|
} else if (fname == "operator >=") {
|
|
|
- out << " case Py_GE:\n";
|
|
|
|
|
|
|
+ op_type = "Py_GE";
|
|
|
} else {
|
|
} else {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!has_local_richcompare) {
|
|
|
|
|
+ out << " switch (op) {\n";
|
|
|
|
|
+ has_local_richcompare = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ out << " case " << op_type << ":\n";
|
|
|
|
|
+
|
|
|
out << " {\n";
|
|
out << " {\n";
|
|
|
|
|
|
|
|
string expected_params;
|
|
string expected_params;
|
|
@@ -2587,14 +2593,15 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
|
|
|
|
|
out << " break;\n";
|
|
out << " break;\n";
|
|
|
out << " }\n";
|
|
out << " }\n";
|
|
|
- has_local_richcompare = true;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- out << " }\n\n";
|
|
|
|
|
-
|
|
|
|
|
- out << " if (_PyErr_OCCURRED()) {\n";
|
|
|
|
|
- out << " PyErr_Clear();\n";
|
|
|
|
|
- out << " }\n\n";
|
|
|
|
|
|
|
+ if (has_local_richcompare) {
|
|
|
|
|
+ // End of switch block
|
|
|
|
|
+ out << " }\n\n";
|
|
|
|
|
+ out << " if (_PyErr_OCCURRED()) {\n";
|
|
|
|
|
+ out << " PyErr_Clear();\n";
|
|
|
|
|
+ out << " }\n\n";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (slots.count("tp_compare")) {
|
|
if (slots.count("tp_compare")) {
|
|
|
// A lot of Panda code depends on comparisons being done via the
|
|
// A lot of Panda code depends on comparisons being done via the
|
|
@@ -2624,6 +2631,7 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
out << " case Py_GE:\n";
|
|
out << " case Py_GE:\n";
|
|
|
out << " return PyBool_FromLong(cmpval >= 0);\n";
|
|
out << " return PyBool_FromLong(cmpval >= 0);\n";
|
|
|
out << " }\n";
|
|
out << " }\n";
|
|
|
|
|
+ has_local_richcompare = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
out << " Py_INCREF(Py_NotImplemented);\n";
|
|
out << " Py_INCREF(Py_NotImplemented);\n";
|
|
@@ -2850,7 +2858,7 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
out << "#else\n";
|
|
out << "#else\n";
|
|
|
if (has_hash_compare) {
|
|
if (has_hash_compare) {
|
|
|
write_function_slot(out, 4, slots, "tp_compare",
|
|
write_function_slot(out, 4, slots, "tp_compare",
|
|
|
- "&DTOOL_PyObject_ComparePointers");
|
|
|
|
|
|
|
+ "&DtoolInstance_ComparePointers");
|
|
|
} else {
|
|
} else {
|
|
|
out << " nullptr, // tp_compare\n";
|
|
out << " nullptr, // tp_compare\n";
|
|
|
}
|
|
}
|
|
@@ -2880,7 +2888,7 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
|
|
|
|
|
// hashfunc tp_hash;
|
|
// hashfunc tp_hash;
|
|
|
if (has_hash_compare) {
|
|
if (has_hash_compare) {
|
|
|
- write_function_slot(out, 4, slots, "tp_hash", "&DTOOL_PyObject_HashPointer");
|
|
|
|
|
|
|
+ write_function_slot(out, 4, slots, "tp_hash", "&DtoolInstance_HashPointer");
|
|
|
} else {
|
|
} else {
|
|
|
out << " nullptr, // tp_hash\n";
|
|
out << " nullptr, // tp_hash\n";
|
|
|
}
|
|
}
|
|
@@ -2951,7 +2959,7 @@ write_module_class(ostream &out, Object *obj) {
|
|
|
} else if (has_hash_compare) {
|
|
} else if (has_hash_compare) {
|
|
|
// All hashable types need to be comparable.
|
|
// All hashable types need to be comparable.
|
|
|
out << "#if PY_MAJOR_VERSION >= 3\n";
|
|
out << "#if PY_MAJOR_VERSION >= 3\n";
|
|
|
- out << " &DTOOL_PyObject_RichCompare,\n";
|
|
|
|
|
|
|
+ out << " &DtoolInstance_RichComparePointers,\n";
|
|
|
out << "#else\n";
|
|
out << "#else\n";
|
|
|
out << " nullptr, // tp_richcompare\n";
|
|
out << " nullptr, // tp_richcompare\n";
|
|
|
out << "#endif\n";
|
|
out << "#endif\n";
|