Generate a tp_richcompare slot function for each type. For the time being it simply raises TypeError, just to avoid the trap of comparing objects when the default evil Python 2.x behaviour is to compare by wrapper pointer value. In the future, wrapping C++ comparison operators will be possible.
This commit is contained in:
1 parent
49c62c8c03
commit
e1f813d97e
1 file changed
+24
@@ -1335,6 +1335,10 @@ typedef struct {
|
||||
self._generate_destructor(code_sink, have_constructor)
|
||||
if self.has_output_stream_operator:
|
||||
self._generate_str(code_sink)
|
||||
|
||||
if self.slots.get("tp_richcompare", "NULL") == "NULL":
|
||||
self.slots["tp_richcompare"] = self._generate_tp_richcompare(code_sink)
|
||||
|
||||
self._generate_type_structure(code_sink, docstring)
|
||||
|
||||
def _generate_type_structure(self, code_sink, docstring):
|
||||
@@ -1585,6 +1589,26 @@ static void
|
||||
self.slots.setdefault("tp_dealloc", tp_dealloc_function_name )
|
||||
|
||||
|
||||
def _generate_tp_richcompare(self, code_sink):
|
||||
tp_richcompare_function_name = "_wrap_%s__tp_richcompare" % (self.pystruct,)
|
||||
|
||||
code_sink.writeln("static PyObject*\n%s (%s *self, PyObject *o2, int opid)"
|
||||
% (tp_richcompare_function_name, self.pystruct))
|
||||
code_sink.writeln("{")
|
||||
code_sink.indent()
|
||||
|
||||
## TODO
|
||||
code_sink.writeln('PyErr_SetString(PyExc_TypeError, "Comparison not defined or not yet implemented.");')
|
||||
code_sink.writeln('return NULL;')
|
||||
|
||||
#code_sink.writeln("Py_INCREF(Py_NotImplemented);")
|
||||
#code_sink.writeln("return Py_NotImplemented;")
|
||||
|
||||
code_sink.unindent()
|
||||
code_sink.writeln("}\n")
|
||||
|
||||
return tp_richcompare_function_name
|
||||
|
||||
###
|
||||
### ------------ C++ class parameter type handlers ------------
|
||||
###
|
||||
|
||||
Reference in new issue
Block a user