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
Xavier Thompson
cython
Commits
080269ba
Commit
080269ba
authored
Jun 03, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support wrapping cypclass with multiple bases
parent
d784e746
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
17 deletions
+28
-17
Cython/Compiler/CypclassWrapper.py
Cython/Compiler/CypclassWrapper.py
+7
-10
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+9
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+10
-4
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+2
-0
No files found.
Cython/Compiler/CypclassWrapper.py
View file @
080269ba
...
...
@@ -154,10 +154,7 @@ class CypclassWrapperInjection(VisitorTransform):
if
not
node_has_suite
:
return
None
if
len
(
node
.
base_classes
)
>
1
:
return
None
# TODO: take nesting into account for the name
cclass_name
=
EncodedString
(
"%s_cyp_wrapper"
%
node
.
name
)
...
...
@@ -217,13 +214,12 @@ class CypclassWrapperInjection(VisitorTransform):
return
wrapper
def
synthesize_underlying_cyobject_attribute
(
self
,
node
):
nested_names
=
[
node
.
name
for
node
in
self
.
nesting_stack
]
underlying_base_typ
e
=
Nodes
.
CSimpleBaseTypeNode
(
void_type_nod
e
=
Nodes
.
CSimpleBaseTypeNode
(
node
.
pos
,
name
=
node
.
name
,
module_path
=
nested_names
,
is_basic_c_type
=
0
,
name
=
"void"
,
module_path
=
[]
,
is_basic_c_type
=
1
,
signed
=
1
,
complex
=
0
,
longness
=
0
,
...
...
@@ -232,11 +228,12 @@ class CypclassWrapperInjection(VisitorTransform):
)
underlying_name_declarator
=
Nodes
.
CNameDeclaratorNode
(
node
.
pos
,
name
=
underlying_name
,
cname
=
None
)
underlying_name_declarator
=
Nodes
.
CPtrDeclaratorNode
(
node
.
pos
,
base
=
underlying_name_declarator
)
underlying_cyobject
=
Nodes
.
CVarDefNode
(
pos
=
node
.
pos
,
visibility
=
'private'
,
base_type
=
underlying_base_typ
e
,
base_type
=
void_type_nod
e
,
declarators
=
[
underlying_name_declarator
],
in_pxd
=
node
.
in_pxd
,
doc
=
None
,
...
...
Cython/Compiler/ModuleNode.py
View file @
080269ba
...
...
@@ -1553,10 +1553,16 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"static void %s(PyObject *o) {"
%
slot_func_cname
)
# for cyp wrappers, just decrement the atomic counter of the underlying type
is_cyp_wrapper
=
scope
.
parent_type
.
is_cyp_wrapper
if
is_cyp_wrapper
:
parent_type
=
scope
.
parent_type
if
parent_type
.
is_cyp_wrapper
:
underlying_type_decl
=
parent_type
.
wrapped_decl
underlying_attribute_name
=
CypclassWrapper
.
underlying_name
self
.
generate_self_cast
(
scope
,
code
)
code
.
putln
(
"Cy_DECREF(p->%s);"
%
CypclassWrapper
.
underlying_name
)
code
.
putln
(
"%s * p_nogil_cyobject = (%s *) (p->%s);"
%
(
underlying_type_decl
,
underlying_type_decl
,
underlying_attribute_name
)
)
code
.
putln
(
"Cy_DECREF(p_nogil_cyobject);"
)
code
.
putln
(
"}"
)
return
...
...
Cython/Compiler/Nodes.py
View file @
080269ba
...
...
@@ -5359,6 +5359,8 @@ class CypclassWrapperDefNode(CClassDefNode):
self
.
entry
.
type
.
is_cyp_wrapper
=
1
# > associate the wrapper type to the wrapped type
self
.
wrapped_cypclass
.
entry
.
type
.
wrapper_type
=
self
.
entry
.
type
# > remember the cname of the wrapped type
self
.
entry
.
type
.
wrapped_decl
=
self
.
wrapped_cypclass
.
entry
.
type
.
empty_declaration_code
()
# > insert and analyse each method wrapper
self
.
insert_cypclass_method_wrappers
(
env
)
...
...
@@ -5439,16 +5441,20 @@ class CypclassWrapperDefNode(CClassDefNode):
# > reference to the self argument of the wrapper method
self_obj
=
ExprNodes
.
NameNode
(
self_pos
,
name
=
self_name
)
# > access the
method of the
underlying cyobject from the self argument of the wrapper method
# > access the underlying cyobject from the self argument of the wrapper method
underlying_obj
=
ExprNodes
.
AttributeNode
(
cfunc_method
.
pos
,
obj
=
self_obj
,
attribute
=
underlying_name
)
empty_declarator
=
CNameDeclaratorNode
(
cfunc_method
.
pos
,
name
=
""
,
cname
=
None
)
cast_
underlying_obj
=
ExprNodes
.
TypecastNode
(
cast_
operation
=
ExprNodes
.
TypecastNode
(
cfunc_method
.
pos
,
type
=
self
.
wrapped_cypclass
.
entry
.
type
,
operand
=
underlying_obj
,
typecheck
=
False
)
cast_underlying_obj
=
ExprNodes
.
NameNode
(
self_pos
,
name
=
EncodedString
(
"cast_cyobject"
))
cast_assignment
=
SingleAssignmentNode
(
self_pos
,
lhs
=
cast_underlying_obj
,
rhs
=
cast_operation
)
# > access the method of the underlying object
cfunc
=
ExprNodes
.
AttributeNode
(
cfunc_method
.
pos
,
obj
=
cast_underlying_obj
,
attribute
=
cfunc_name
)
# > call to the underlying method
...
...
@@ -5463,7 +5469,7 @@ class CypclassWrapperDefNode(CClassDefNode):
py_stat
=
ExprStatNode
(
cfunc_method
.
pos
,
expr
=
c_call
)
else
:
py_stat
=
ReturnStatNode
(
cfunc_method
.
pos
,
return_type
=
PyrexTypes
.
py_object_type
,
value
=
c_call
)
py_body
=
StatListNode
(
cfunc_method
.
pos
,
stats
=
[
py_stat
])
py_body
=
StatListNode
(
cfunc_method
.
pos
,
stats
=
[
cast_assignment
,
py_stat
])
# > lock around the call in checklock mode
if
self
.
wrapped_cypclass
.
lock_mode
==
'checklock'
:
...
...
@@ -5471,7 +5477,7 @@ class CypclassWrapperDefNode(CClassDefNode):
lock_node
=
LockCypclassNode
(
cfunc_method
.
pos
,
state
=
'wlocked'
if
need_wlock
else
'rlocked'
,
obj
=
underlying_obj
,
obj
=
cast_
underlying_obj
,
body
=
py_body
)
py_body
=
lock_node
...
...
Cython/Compiler/PyrexTypes.py
View file @
080269ba
...
...
@@ -1362,11 +1362,13 @@ class PyExtensionType(PyObjectType):
# defered_declarations [thunk] Used to declare class hierarchies in order
# check_size 'warn', 'error', 'ignore' What to do if tp_basicsize does not match
# is_cyp_wrapper boolean Whether this extension type wraps a cypclass
# wrapped_decl string or None The declaration code of the wrapped cypclass type when this is a cyp_wrapper
is_extension_type
=
1
has_attributes
=
1
early_init
=
1
is_cyp_wrapper
=
0
wrapped_decl
=
None
objtypedef_cname
=
None
...
...
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