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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
57f327c1
Commit
57f327c1
authored
May 16, 2009
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add compiler directive for user-defined function calling conventions
parent
054826b1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
93 additions
and
5 deletions
+93
-5
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+3
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+7
-0
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+5
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+1
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+9
-0
tests/compile/callingconvention.pyx
tests/compile/callingconvention.pyx
+19
-4
tests/errors/e_callspec.pyx
tests/errors/e_callspec.pyx
+48
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
57f327c1
...
...
@@ -530,6 +530,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
" #ifndef __cdecl"
)
code
.
putln
(
" #define __cdecl"
)
code
.
putln
(
" #endif"
)
code
.
putln
(
" #ifndef __fastcall"
)
code
.
putln
(
" #define __fastcall"
)
code
.
putln
(
" #endif"
)
code
.
putln
(
"#else"
)
code
.
putln
(
" #define _USE_MATH_DEFINES"
)
code
.
putln
(
"#endif"
)
...
...
Cython/Compiler/Nodes.py
View file @
57f327c1
...
...
@@ -603,6 +603,13 @@ class CFuncDeclaratorNode(CDeclaratorNode):
nogil
=
self
.
nogil
,
with_gil
=
self
.
with_gil
,
is_overridable
=
self
.
overridable
)
if
self
.
optional_arg_count
:
func_type
.
op_arg_struct
=
PyrexTypes
.
c_ptr_type
(
self
.
op_args_struct
.
type
)
callspec
=
env
.
directives
[
'callspec'
]
if
callspec
:
current
=
func_type
.
calling_convention
if
current
and
current
!=
callspec
:
error
(
self
.
pos
,
"cannot have both '%s' and '%s' "
"calling conventions"
%
(
current
,
callspec
))
func_type
.
calling_convention
=
callspec
return
self
.
base
.
analyse
(
func_type
,
env
)
...
...
Cython/Compiler/Options.py
View file @
57f327c1
...
...
@@ -66,6 +66,7 @@ option_defaults = {
'always_allow_keywords'
:
False
,
'wraparound'
:
True
,
'c99_complex'
:
False
,
# Don't use macro wrappers for complex arith, not sure what to name this...
'callspec'
:
""
,
}
# Override types possibilities above, if needed
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
57f327c1
...
...
@@ -435,6 +435,11 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
raise
PostParseError
(
dec
.
function
.
pos
,
'The %s option takes one compile-time boolean argument'
%
optname
)
return
(
optname
,
args
[
0
].
value
)
elif
optiontype
is
str
:
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
StringNode
):
raise
PostParseError
(
dec
.
function
.
pos
,
'The %s option takes one compile-time string argument'
%
optname
)
return
(
optname
,
args
[
0
].
value
)
elif
optiontype
is
dict
:
if
len
(
args
)
!=
0
:
raise
PostParseError
(
dec
.
function
.
pos
,
...
...
Cython/Compiler/Parsing.py
View file @
57f327c1
...
...
@@ -1675,7 +1675,7 @@ def p_calling_convention(s):
else
:
return
""
calling_convention_words
=
(
"__stdcall"
,
"__cdecl"
)
calling_convention_words
=
(
"__stdcall"
,
"__cdecl"
,
"__fastcall"
)
def
p_c_complex_base_type
(
s
):
# s.sy == '('
...
...
Cython/Compiler/PyrexTypes.py
View file @
57f327c1
...
...
@@ -1125,6 +1125,15 @@ class CFuncType(CType):
return
1
def
same_calling_convention_as
(
self
,
other
):
## XXX Under discussion ...
## callspec_words = ("__stdcall", "__cdecl", "__fastcall")
## cs1 = self.calling_convention
## cs2 = other.calling_convention
## if (cs1 in callspec_words or
## cs2 in callspec_words):
## return cs1 == cs2
## else:
## return True
sc1
=
self
.
calling_convention
==
'__stdcall'
sc2
=
other
.
calling_convention
==
'__stdcall'
return
sc1
==
sc2
...
...
tests/compile/callingconvention.pyx
View file @
57f327c1
cdef
extern
int
f
()
cdef
extern
int
f
1
()
cdef
extern
int
__
stdcall
g
()
cdef
extern
int
__
cdecl
f2
()
cdef
extern
int
__
cdecl
h
()
cdef
extern
int
__
stdcall
f3
()
cdef
extern
int
(
__stdcall
*
p
)()
cdef
extern
int
__fastcall
f4
()
cdef
extern
int
(
*
p1
)()
cdef
extern
int
(
__cdecl
*
p2
)()
cdef
extern
int
(
__stdcall
*
p3
)()
cdef
extern
int
(
__fastcall
*
p4
)()
p1
=
f1
p2
=
f2
p3
=
f3
p4
=
f4
tests/errors/e_callspec.pyx
0 → 100644
View file @
57f327c1
cimport
cython
@
cython
.
callspec
(
""
)
cdef
void
h1
():
pass
@
cython
.
callspec
(
"__cdecl"
)
cdef
void
__cdecl
h2
():
pass
@
cython
.
callspec
(
"__stdcall"
)
cdef
void
__stdcall
h3
():
pass
@
cython
.
callspec
(
"__fastcall"
)
cdef
void
__fastcall
h4
():
pass
@
cython
.
callspec
(
"__cdecl"
)
cdef
void
__stdcall
h5
():
pass
# fail
@
cython
.
callspec
(
"__cdecl"
)
cdef
void
__fastcall
h6
():
pass
# fail
cdef
void
(
*
p1
)()
cdef
void
(
__cdecl
*
p2
)()
cdef
void
(
__stdcall
*
p3
)()
cdef
void
(
__fastcall
*
p4
)()
p1
=
h1
p2
=
h2
p3
=
h3
p4
=
h4
#p1 = h2 # fail
#p1 = h3 # fail
#p1 = h4 # fail
#p2 = h1 # fail
#p2 = h3 # fail
#p2 = h4 # fail
_ERRORS
=
u"""
16:22: cannot have both '__stdcall' and '__cdecl' calling conventions
19:23: cannot have both '__fastcall' and '__cdecl' calling conventions
"""
#31:14: Cannot assign type 'void (__cdecl )(void)' to 'void (*)(void)'
#32:14: Cannot assign type 'void (__stdcall )(void)' to 'void (*)(void)'
#33:14: Cannot assign type 'void (__fastcall )(void)' to 'void (*)(void)'
#35:14: Cannot assign type 'void (void)' to 'void (__cdecl *)(void)'
#36:14: Cannot assign type 'void (__stdcall )(void)' to 'void (__cdecl *)(void)'
#37:14: Cannot assign type 'void (__fastcall )(void)' to 'void (__cdecl *)(void)'
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