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
Gwenaël Samain
cython
Commits
41f215e5
Commit
41f215e5
authored
Aug 19, 2007
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
meth_o and meth_noargs for module-level functions
previous patch was just for classes
parent
8c68f604
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
15 deletions
+34
-15
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+6
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+7
-3
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+0
-9
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+21
-0
No files found.
Cython/Compiler/Code.py
View file @
41f215e5
...
...
@@ -6,7 +6,7 @@ import Naming
import
Options
from
Cython.Utils
import
open_new_file
from
PyrexTypes
import
py_object_type
,
typecast
from
TypeSlots
import
get_special_method_signature
from
TypeSlots
import
get_special_method_signature
,
method_coexist
class
CCodeWriter
:
# f file output file
...
...
@@ -289,12 +289,15 @@ class CCodeWriter:
doc_code
=
entry
.
doc_cname
else
:
doc_code
=
0
if
entry
.
meth_flags
:
method_flags
=
entry
.
signature
.
method_flags
()
if
method_flags
:
if
get_special_method_signature
(
entry
.
name
):
method_flags
+=
[
method_coexist
]
self
.
putln
(
'{"%s", (PyCFunction)%s, %s, %s}%s'
%
(
entry
.
name
,
entry
.
func_cname
,
"|"
.
join
(
entry
.
meth
_flags
),
"|"
.
join
(
method
_flags
),
doc_code
,
term
))
...
...
Cython/Compiler/Nodes.py
View file @
41f215e5
...
...
@@ -820,13 +820,17 @@ class DefNode(FuncDefNode):
def
analyse_signature
(
self
,
env
):
any_type_tests_needed
=
0
if
self
.
entry
.
signature
is
TypeSlots
.
pymethod_signature
:
# Use the simpler calling signature for zero- and one-argument functions.
if
self
.
entry
.
signature
is
TypeSlots
.
pyfunction_signature
:
if
len
(
self
.
args
)
==
0
:
self
.
entry
.
signature
=
TypeSlots
.
pyfunction_noargs
elif
len
(
self
.
args
)
==
1
and
self
.
args
[
0
].
type
.
is_pyobject
and
self
.
args
[
0
].
default
is
None
:
self
.
entry
.
signature
=
TypeSlots
.
pyfunction_onearg
elif
self
.
entry
.
signature
is
TypeSlots
.
pymethod_signature
:
if
len
(
self
.
args
)
==
1
:
self
.
entry
.
signature
=
TypeSlots
.
unaryfunc
self
.
entry
.
meth_flags
=
[
TypeSlots
.
method_noargs
]
elif
len
(
self
.
args
)
==
2
and
self
.
args
[
1
].
type
.
is_pyobject
and
self
.
args
[
1
].
default
is
None
:
self
.
entry
.
signature
=
TypeSlots
.
ibinaryfunc
self
.
entry
.
meth_flags
=
[
TypeSlots
.
method_onearg
]
sig
=
self
.
entry
.
signature
nfixed
=
sig
.
num_fixed_args
()
for
i
in
range
(
nfixed
):
...
...
Cython/Compiler/Symtab.py
View file @
41f215e5
...
...
@@ -303,7 +303,6 @@ class Scope:
# Add an entry for a Python function.
entry
=
self
.
declare_var
(
name
,
py_object_type
,
pos
)
entry
.
signature
=
pyfunction_signature
entry
.
meth_flags
=
[
TypeSlots
.
method_varargs
,
TypeSlots
.
method_keywords
]
self
.
pyfunc_entries
.
append
(
entry
)
return
entry
...
...
@@ -1090,14 +1089,7 @@ class CClassScope(ClassScope):
# Special methods get put in the method table with a particular
# signature declared in advance.
entry
.
signature
=
special_sig
if
special_sig
==
TypeSlots
.
unaryfunc
:
entry
.
meth_flags
=
[
TypeSlots
.
method_noargs
,
TypeSlots
.
method_coexist
]
elif
special_sig
==
TypeSlots
.
binaryfunc
or
special_sig
==
TypeSlots
.
ibinaryfunc
:
entry
.
meth_flags
=
[
TypeSlots
.
method_onearg
,
TypeSlots
.
method_coexist
]
else
:
entry
.
meth_flags
=
None
# should it generate a wrapper function?
else
:
entry
.
meth_flags
=
[
TypeSlots
.
method_varargs
,
TypeSlots
.
method_keywords
]
entry
.
signature
=
pymethod_signature
self
.
pyfunc_entries
.
append
(
entry
)
...
...
@@ -1181,7 +1173,6 @@ class PropertyScope(Scope):
if
signature
:
entry
=
self
.
declare
(
name
,
name
,
py_object_type
,
pos
)
entry
.
signature
=
signature
entry
.
meth_flags
=
None
return
entry
else
:
error
(
pos
,
"Only __get__, __set__ and __del__ methods allowed "
...
...
Cython/Compiler/TypeSlots.py
View file @
41f215e5
...
...
@@ -82,6 +82,18 @@ class Signature:
def
return_type
(
self
):
return
self
.
format_map
[
self
.
ret_format
]
def
method_flags
(
self
):
if
self
.
ret_format
==
"O"
:
full_args
=
"O"
+
self
.
fixed_arg_format
if
self
.
has_dummy_arg
else
self
.
fixed_arg_format
if
full_args
in
[
"O"
,
"T"
]:
if
self
.
has_generic_args
:
return
[
method_varargs
,
method_keywords
]
else
:
return
[
method_noargs
]
elif
full_args
in
[
"OO"
,
"TO"
]
and
not
self
.
has_generic_args
:
return
[
method_onearg
]
return
None
class
SlotDescriptor
:
...
...
@@ -342,6 +354,15 @@ def get_property_accessor_signature(name):
pyfunction_signature
=
Signature
(
"-*"
,
"O"
)
pymethod_signature
=
Signature
(
"T*"
,
"O"
)
#------------------------------------------------------------------------------------------
#
# Signatures for simple Python functions.
#
#------------------------------------------------------------------------------------------
pyfunction_noargs
=
Signature
(
"-"
,
"O"
)
pyfunction_onearg
=
Signature
(
"-O"
,
"O"
)
#------------------------------------------------------------------------------------------
#
# Signatures for the various kinds of function that
...
...
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