import Options
from Cython.Utils import open_new_file
from PyrexTypes import py_object_type, typecast
+from TypeSlots import get_special_method_signature
class CCodeWriter:
# f file output file
doc_code = entry.doc_cname
else:
doc_code = 0
+ # Add METH_COEXIST to special methods
+ meth_flags = "METH_VARARGS|METH_KEYWORDS"
+ if get_special_method_signature(entry.name):
+ meth_flags = "METH_VARARGS|METH_KEYWORDS|METH_COEXIST"
self.putln(
- '{"%s", (PyCFunction)%s, METH_VARARGS|METH_KEYWORDS, %s}%s' % (
+ '{"%s", (PyCFunction)%s, %s, %s}%s' % (
entry.name,
- entry.func_cname,
+ entry.func_cname,
+ meth_flags,
doc_code,
term))
def declare_pyfunction(self, name, pos):
# Add an entry for a method.
+ if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'):
+ error(pos, "Special method %s must be implemented via __richcmp__"
+% name)
entry = self.declare(name, name, py_object_type, pos)
special_sig = get_special_method_signature(name)
if special_sig:
+ # Special methods get put in the method table with a particular
+ # signature declared in advance.
entry.signature = special_sig
- # Special methods don't get put in the method table
else:
entry.signature = pymethod_signature
- self.pyfunc_entries.append(entry)
+
+ self.pyfunc_entries.append(entry)
return entry
def declare_cfunction(self, name, type, pos,