Commit a51cac49 authored by Robert Bradshaw's avatar Robert Bradshaw

Correct flags on special methods so one can call their python functions directly.

parent a9fa4bda
...@@ -289,15 +289,12 @@ class CCodeWriter: ...@@ -289,15 +289,12 @@ class CCodeWriter:
doc_code = entry.doc_cname doc_code = entry.doc_cname
else: else:
doc_code = 0 doc_code = 0
# Add METH_COEXIST to special methods if entry.meth_flags:
meth_flags = "METH_VARARGS|METH_KEYWORDS"
if get_special_method_signature(entry.name):
meth_flags = "METH_VARARGS|METH_KEYWORDS|METH_COEXIST"
self.putln( self.putln(
'{"%s", (PyCFunction)%s, %s, %s}%s' % ( '{"%s", (PyCFunction)%s, %s, %s}%s' % (
entry.name, entry.name,
entry.func_cname, entry.func_cname,
meth_flags, entry.meth_flags,
doc_code, doc_code,
term)) term))
......
...@@ -7,6 +7,7 @@ from Errors import error, InternalError, warning ...@@ -7,6 +7,7 @@ from Errors import error, InternalError, warning
import Options import Options
import Naming import Naming
from PyrexTypes import * from PyrexTypes import *
import TypeSlots
from TypeSlots import \ from TypeSlots import \
pyfunction_signature, pymethod_signature, \ pyfunction_signature, pymethod_signature, \
get_special_method_signature, get_property_accessor_signature get_special_method_signature, get_property_accessor_signature
...@@ -302,6 +303,7 @@ class Scope: ...@@ -302,6 +303,7 @@ class Scope:
# Add an entry for a Python function. # Add an entry for a Python function.
entry = self.declare_var(name, py_object_type, pos) entry = self.declare_var(name, py_object_type, pos)
entry.signature = pyfunction_signature entry.signature = pyfunction_signature
entry.meth_flags = "METH_VARARGS|METH_KEYWORDS"
self.pyfunc_entries.append(entry) self.pyfunc_entries.append(entry)
return entry return entry
...@@ -1088,7 +1090,14 @@ class CClassScope(ClassScope): ...@@ -1088,7 +1090,14 @@ class CClassScope(ClassScope):
# Special methods get put in the method table with a particular # Special methods get put in the method table with a particular
# signature declared in advance. # signature declared in advance.
entry.signature = special_sig entry.signature = special_sig
if special_sig == TypeSlots.unaryfunc:
entry.meth_flags = "METH_NOARGS|METH_COEXIST"
elif special_sig == TypeSlots.binaryfunc or special_sig == TypeSlots.ibinaryfunc:
entry.meth_flags = "METH_O|METH_COEXIST"
else: else:
entry.meth_flags = None # should it generate a wrapper function?
else:
entry.meth_flags = "METH_VARARGS|METH_KEYWORDS"
entry.signature = pymethod_signature entry.signature = pymethod_signature
self.pyfunc_entries.append(entry) self.pyfunc_entries.append(entry)
...@@ -1172,6 +1181,7 @@ class PropertyScope(Scope): ...@@ -1172,6 +1181,7 @@ class PropertyScope(Scope):
if signature: if signature:
entry = self.declare(name, name, py_object_type, pos) entry = self.declare(name, name, py_object_type, pos)
entry.signature = signature entry.signature = signature
entry.meth_flags = None
return entry return entry
else: else:
error(pos, "Only __get__, __set__ and __del__ methods allowed " error(pos, "Only __get__, __set__ and __del__ methods allowed "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment