Commit c326b2da authored by Haoyu Bai's avatar Haoyu Bai

@cython.ccall decorator

parent 0a81c329
......@@ -96,6 +96,7 @@ directive_types = {
'internal' : bool, # cdef class visibility in the module dict
'infer_types' : bool, # values can be True/None/False
'cfunc' : None, # decorators do not take directive value
'ccall' : None,
'cclass' : None,
}
......
......@@ -1401,6 +1401,9 @@ class AdjustDefByDirectives(CythonTransform, SkipDeclarations):
return node
def visit_DefNode(self, node):
if 'ccall' in self.directives:
node = node.as_cfunction(overridable=True)
return self.visit(node)
if 'cfunc' in self.directives:
if self.in_py_class:
error(node.pos, "cfunc directive is not allowed here")
......
......@@ -23,7 +23,7 @@ class _EmptyDecoratorAndManager(object):
def __exit__(self, exc_type, exc_value, traceback):
pass
cclass = cfunc = _EmptyDecoratorAndManager()
cclass = ccall = cfunc = _EmptyDecoratorAndManager()
def inline(f, *args, **kwds):
if isinstance(f, basestring):
......
import cython
from cython import cfunc, cclass
from cython import cfunc, cclass, ccall
@cython.test_assert_path_exists('//CFuncDefNode')
@cython.cfunc
......@@ -75,3 +75,38 @@ def test_method():
else:
print(True)
return
@cython.ccall
def ccall_sqr(x):
return x*x
@cclass
class Overidable(object):
@ccall
def meth(self):
return 0
def test_ccall():
"""
>>> test_ccall()
25
>>> ccall_sqr(5)
25
"""
return ccall_sqr(5)
def test_ccall_method(x):
"""
>>> test_ccall_method(Overidable())
0
>>> Overidable().meth()
0
>>> class Foo(Overidable):
... def meth(self):
... return 1
>>> test_ccall_method(Foo())
1
>>> Foo().meth()
1
"""
return x.meth()
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