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
9005d6f7
Commit
9005d6f7
authored
Jun 06, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deferred cypclass attrs decrefing in destructor
parent
c4ebfc09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
6 deletions
+31
-6
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+31
-6
No files found.
Cython/Compiler/ModuleNode.py
View file @
9005d6f7
...
...
@@ -586,7 +586,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type_entries
.
append
(
entry
)
type_entries
=
[
t
for
t
in
type_entries
if
t
not
in
vtabslot_entries
]
self
.
generate_type_header_code
(
type_entries
,
code
)
self
.
generate_cyp_class_
wrapper
_definitions
(
type_entries
,
code
)
self
.
generate_cyp_class_
deferred
_definitions
(
type_entries
,
code
)
for
entry
in
vtabslot_list
:
self
.
generate_objstruct_definition
(
entry
.
type
,
code
)
self
.
generate_typeobj_predeclaration
(
entry
,
code
)
...
...
@@ -817,9 +817,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
elif
type
.
is_extension_type
:
self
.
generate_objstruct_definition
(
type
,
code
)
def
generate_cyp_class_
wrapper
_definitions
(
self
,
type_entries
,
code
):
def
generate_cyp_class_
deferred
_definitions
(
self
,
type_entries
,
code
):
for
entry
in
type_entries
:
if
entry
.
type
.
is_cyp_class
:
# Generate cypclass attr destructor
self
.
generate_cyp_class_attrs_destructor_definition
(
entry
,
code
)
# Generate wrapper constructor
scope
=
entry
.
type
.
scope
wrapper
=
scope
.
lookup_here
(
"<constructor>"
)
...
...
@@ -932,10 +934,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
put
(
" : public %s"
%
base_class_decl
)
code
.
putln
(
" {"
)
self
.
generate_type_header_code
(
scope
.
type_entries
,
code
)
self
.
generate_cyp_class_
wrapper
_definitions
(
scope
.
sue_entries
,
code
)
self
.
generate_cyp_class_
deferred
_definitions
(
scope
.
sue_entries
,
code
)
py_attrs
=
[
e
for
e
in
scope
.
entries
.
values
()
if
e
.
type
.
is_pyobject
and
not
e
.
is_inherited
]
cypclass_attrs
=
[
e
for
e
in
scope
.
var_entries
cypclass_attrs
=
[
e
for
e
in
scope
.
var_entries
+
scope
.
inherited_var_entries
if
e
.
type
.
is_cyp_class
and
not
e
.
name
==
"this"
and
not
e
.
is_type
]
has_virtual_methods
=
False
...
...
@@ -997,13 +999,22 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
arg_names
=
[]
generate_cpp_constructor_code
(
arg_decls
,
arg_names
,
is_implementing
,
py_attrs
,
constructor
)
if
type
.
is_cyp_class
and
cypclass_attrs
:
# Declaring a small destruction handler which will always try to Cy_XDECREF
# every cypclass attribute. This handler is defined after all class definition.
# We cannot define it inplace, because we won't be able to decref forward declare attributes
# (as they're not defined, they're not considered CyObject subclasses, so Cy_DECREF will be lost)
cypclass_attrs_destructor_name
=
"%s__cypclass_attrs_destructor__%s"
%
(
Naming
.
func_prefix
,
type
.
name
)
code
.
putln
(
"void "
+
cypclass_attrs_destructor_name
+
"();"
)
if
type
.
is_cyp_class
or
destructor
or
py_attrs
or
has_virtual_methods
:
if
has_virtual_methods
or
type
.
is_cyp_class
:
code
.
put
(
"virtual "
)
if
is_implementing
:
code
.
putln
(
"~%s() {"
%
type
.
cname
)
for
cypattr
in
cypclass_attrs
:
code
.
put_cyxdecref
(
cypattr
.
cname
)
if
cypclass_attrs
:
cypclass_attrs_destructor_name
=
"%s__cypclass_attrs_destructor__%s"
%
(
Naming
.
func_prefix
,
entry
.
name
)
code
.
putln
(
cypclass_attrs_destructor_name
+
"();"
)
if
py_attrs
:
code
.
put_ensure_gil
()
if
destructor
:
...
...
@@ -1054,6 +1065,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load
(
"CyObjects"
,
"CyObjects.cpp"
,
proto_block
=
"utility_code_proto_before_types"
))
def
generate_cyp_class_attrs_destructor_definition
(
self
,
entry
,
code
):
scope
=
entry
.
type
.
scope
cypclass_attrs
=
[
e
for
e
in
scope
.
var_entries
+
scope
.
inherited_var_entries
if
e
.
type
.
is_cyp_class
and
not
e
.
name
==
"this"
and
not
e
.
is_type
]
if
cypclass_attrs
:
cypclass_attrs_destructor_name
=
"%s__cypclass_attrs_destructor__%s"
%
(
Naming
.
func_prefix
,
entry
.
name
)
destructor_with_namespace
=
"void %s::%s()"
%
(
entry
.
type
.
empty_declaration_code
(),
cypclass_attrs_destructor_name
)
code
.
putln
(
destructor_with_namespace
)
code
.
putln
(
"{"
)
for
attr
in
cypclass_attrs
:
code
.
putln
(
"Cy_XDECREF(this->%s);"
%
attr
.
cname
)
code
.
putln
(
"}"
)
def
generate_cyp_class_wrapper_definition
(
self
,
type
,
wrapper_entry
,
constructor_entry
,
new_entry
,
alloc_entry
,
code
):
if
type
.
templates
:
code
.
putln
(
"template <typename %s>"
%
", class "
.
join
(
...
...
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