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
96a48b19
Commit
96a48b19
authored
Jul 28, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dispatch cypclass static methods correctly
parent
301afca4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
7 deletions
+44
-7
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+35
-3
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+0
-4
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+9
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
96a48b19
...
...
@@ -1042,7 +1042,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
continue
elif
attr
.
type
.
is_cyp_class
:
cname
=
"%s = NULL"
%
cname
if
type
.
is_cyp_class
and
attr
.
type
.
is_cfunction
and
attr
.
type
.
is_static_method
and
attr
.
static_cname
is
not
None
:
code
.
putln
(
"%s;"
%
attr
.
type
.
declaration_code
(
attr
.
static_cname
))
self
.
generate_cyp_class_static_method_resolution
(
attr
,
code
)
else
:
code
.
putln
(
"%s;"
%
attr
.
type
.
declaration_code
(
cname
))
is_implementing
=
'init_module'
in
code
.
globalstate
.
parts
for
reified
in
scope
.
reifying_entries
:
...
...
@@ -1169,8 +1174,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
and
e
.
from_type
and
e
.
mro_index
>
0
and
e
.
from_type
.
is_cyp_class
# avoid dealing with methods inherited from non-cypclass bases for now
and
not
e
.
type
.
is_static_method
# avoid dealing with static methods for now
and
e
.
name
not
in
(
"<init>"
,
"<del>"
)
and
(
not
e
.
type
.
is_static_method
or
e
.
static_cname
is
not
None
)
# mro-resolve the virtual methods used to dispatch static methods
and
not
e
.
type
.
has_varargs
# avoid dealing with varargs for now (is this ever required anyway ?)
]
if
inherited_methods
:
...
...
@@ -1199,6 +1205,32 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
inherited_methods
:
code
.
putln
(
""
)
def
generate_cyp_class_static_method_resolution
(
self
,
static_method
,
code
):
"""
Generate a virtual method in cypclass that just forward calls to associated static method.
The virtual version will serve to correctly dispatch static methods.
"""
func_type
=
static_method
.
type
modifiers
=
code
.
build_function_modifiers
(
static_method
.
func_modifiers
)
arg_names
=
[
"%s_%d"
%
(
arg
.
cname
,
i
)
for
i
,
arg
in
enumerate
(
func_type
.
args
)]
arg_decls
=
[
arg
.
type
.
declaration_code
(
arg_name
)
for
arg
,
arg_name
in
zip
(
func_type
.
args
,
arg_names
)]
if
func_type
.
optional_arg_count
:
opt_name
=
Naming
.
optional_args_cname
arg_decls
.
append
(
func_type
.
op_arg_struct
.
declaration_code
(
opt_name
))
arg_names
.
append
(
opt_name
)
header
=
func_type
.
function_header_code
(
static_method
.
cname
,
", "
.
join
(
arg_decls
))
if
not
static_method
.
name
.
startswith
(
"operator "
):
header
=
func_type
.
return_type
.
declaration_code
(
header
)
return_code
=
""
if
func_type
.
return_type
.
is_void
else
"return "
body
=
"%s%s(%s);"
%
(
return_code
,
static_method
.
static_cname
,
", "
.
join
(
arg_names
))
code
.
putln
(
"virtual %s%s {%s}"
%
(
modifiers
,
header
,
body
))
def
generate_enum_definition
(
self
,
entry
,
code
):
code
.
mark_pos
(
entry
.
pos
)
type
=
entry
.
type
...
...
Cython/Compiler/Naming.py
View file @
96a48b19
...
...
@@ -169,10 +169,6 @@ api_name = pyrex_prefix + "capi__"
# cname for the type that defines the essential memory layout of a cypclass wrapper.
cypclass_wrapper_layout_type
=
"CyPyObject"
# cname for the underlying cypclass attribute in the memory layout of a cypclass wrapper.
cypclass_wrapper_underlying_attr
=
"nogil_cyobject"
# the h and api guards get changed to:
# __PYX_HAVE__FILENAME (for ascii filenames)
# __PYX_HAVE_U_PUNYCODEFILENAME (for non-ascii filenames)
...
...
Cython/Compiler/Symtab.py
View file @
96a48b19
...
...
@@ -176,6 +176,8 @@ class Entry(object):
# defining_classes [CypClassType or CppClassType or CStructOrUnionType]
# All the base classes that define an entry that this entry
# overrides, if this entry represents a cypclass method
#
# static_cname string The cname of a static method in a cypclass
# TODO: utility_code and utility_code_definition serves the same purpose...
...
...
@@ -254,6 +256,7 @@ class Entry(object):
is_default
=
False
mro_index
=
0
from_type
=
None
static_cname
=
None
def
__init__
(
self
,
name
,
cname
,
type
,
pos
=
None
,
init
=
None
):
self
.
name
=
name
...
...
@@ -2827,6 +2830,8 @@ class CppClassScope(Scope):
cname
=
None
,
visibility
=
'extern'
,
api
=
0
,
in_pxd
=
0
,
is_cdef
=
0
,
defining
=
0
):
# Add an entry for an attribute.
if
name
.
startswith
(
Naming
.
func_prefix
):
error
(
pos
,
"Names starting with %s are reserved inside cppclass and cypclass"
%
Naming
.
func_prefix
)
if
not
cname
:
cname
=
name
entry
=
self
.
lookup_here
(
name
)
...
...
@@ -2846,6 +2851,9 @@ class CppClassScope(Scope):
entry
.
is_cfunction
=
type
.
is_cfunction
if
type
.
is_cfunction
and
self
.
type
:
if
not
self
.
type
.
get_fused_types
():
if
(
self
.
parent_type
.
is_cyp_class
and
type
.
is_static_method
and
name
not
in
(
"<alloc>"
,
"__new__"
)):
cname
=
"%s__static__%s"
%
(
Naming
.
func_prefix
,
cname
)
entry
.
static_cname
=
cname
entry
.
func_cname
=
"%s::%s"
%
(
self
.
type
.
empty_declaration_code
(),
cname
)
if
name
!=
"this"
and
(
defining
or
name
!=
"<init>"
or
self
.
parent_type
.
is_cyp_class
):
self
.
var_entries
.
append
(
entry
)
...
...
@@ -3126,6 +3134,7 @@ class CppClassScope(Scope):
entry
.
is_cfunction
=
base_entry
.
is_cfunction
if
entry
.
is_cfunction
:
entry
.
func_cname
=
base_entry
.
func_cname
entry
.
static_cname
=
base_entry
.
static_cname
for
base_entry
in
base_scope
.
type_entries
:
if
base_entry
.
name
not
in
base_templates
:
...
...
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