Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
c326b2da
Commit
c326b2da
authored
Apr 02, 2011
by
Haoyu Bai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@cython.ccall decorator
parent
0a81c329
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
2 deletions
+41
-2
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+3
-0
Cython/Shadow.py
Cython/Shadow.py
+1
-1
tests/run/purecdef.py
tests/run/purecdef.py
+36
-1
No files found.
Cython/Compiler/Options.py
View file @
c326b2da
...
...
@@ -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
,
}
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
c326b2da
...
...
@@ -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"
)
...
...
Cython/Shadow.py
View file @
c326b2da
...
...
@@ -23,7 +23,7 @@ class _EmptyDecoratorAndManager(object):
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
pass
cclass
=
cfunc
=
_EmptyDecoratorAndManager
()
cclass
=
c
call
=
c
func
=
_EmptyDecoratorAndManager
()
def
inline
(
f
,
*
args
,
**
kwds
):
if
isinstance
(
f
,
basestring
):
...
...
tests/run/purecdef.py
View file @
c326b2da
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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment