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
0d5c18b2
Commit
0d5c18b2
authored
Jun 14, 2019
by
gsamain
Committed by
Xavier Thompson
Aug 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Messages take their own ref of cyobjects
parent
8f81a750
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+30
-1
No files found.
Cython/Compiler/ModuleNode.py
View file @
0d5c18b2
...
...
@@ -1237,6 +1237,32 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
target_object_code
=
target_object_type
.
declaration_code
(
target_object_cname
)
target_object_argument_code
=
target_object_type
.
declaration_code
(
target_object_name
)
def
put_refcount_op_on_narg_optarg
(
op
,
func_type
,
opt_arg_name
,
code
):
opt_arg_count
=
func_type
.
optional_arg_count
narg_count
=
len
(
func_type
.
args
)
-
opt_arg_count
for
narg
in
func_type
.
args
[:
narg_count
]:
if
narg
.
type
.
is_cyp_class
:
code
.
putln
(
"%s(this->%s);"
%
(
op
,
narg
.
cname
))
code
.
putln
(
"if (this->%s != NULL) {"
%
opt_arg_name
)
num_if
=
0
for
opt_idx
,
optarg
in
enumerate
(
func_type
.
args
[
narg_count
:]):
if
optarg
.
type
.
is_cyp_class
:
code
.
putln
(
"if (this->%s->%sn > %s) {"
%
(
opt_arg_name
,
Naming
.
pyrex_prefix
,
opt_idx
))
code
.
putln
(
"%s(this->%s->%s);"
%
(
op
,
opt_arg_name
,
func_type
.
opt_arg_cname
(
optarg
.
name
)
))
num_if
+=
1
for
_
in
range
(
num_if
):
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
for
reifying_class_entry
in
entry
.
type
.
scope
.
reifying_entries
:
reified_function_entry
=
reifying_class_entry
.
reified_entry
reifying_class_full_name
=
reifying_class_entry
.
type
.
empty_declaration_code
()
...
...
@@ -1258,11 +1284,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
initialized_arg_names
.
append
(
arg
.
name
)
initialized_arg_cnames
.
append
(
arg
.
cname
)
message_opt_arg_attr_name
=
"opt_args"
if
opt_arg_count
:
# We cannot initialize the struct before allocating memory, so
# it must be handled in constructor body, not initializer list
opt_decl_code
=
reified_function_entry
.
type
.
op_arg_struct
.
declaration_code
(
Naming
.
optional_args_cname
)
message_opt_arg_attr_name
=
"opt_args"
message_opt_arg_attr_decl
=
reified_function_entry
.
type
.
op_arg_struct
.
declaration_code
(
message_opt_arg_attr_name
)
code
.
putln
(
"%s;"
%
message_opt_arg_attr_decl
)
constructor_decl_list
.
append
(
opt_decl_code
)
...
...
@@ -1292,6 +1318,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"} else {"
)
code
.
putln
(
"this->%s = NULL;"
%
message_opt_arg_attr_name
)
code
.
putln
(
"}"
)
# Acquire a ref on CyObject, as we don't know when the message will be processed
put_refcount_op_on_narg_optarg
(
"Cy_INCREF"
,
reified_function_entry
.
type
,
message_opt_arg_attr_name
,
code
)
code
.
putln
(
"}"
)
code
.
putln
(
"int activate() {"
)
code
.
putln
(
"/* Activate only if its sync object agrees to do so */"
)
...
...
@@ -1324,6 +1352,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# Destructor
code
.
putln
(
"virtual ~%s() {"
%
class_name
)
put_refcount_op_on_narg_optarg
(
"Cy_DECREF"
,
reified_function_entry
.
type
,
message_opt_arg_attr_name
,
code
)
if
opt_arg_count
:
code
.
putln
(
"free(this->%s);"
%
message_opt_arg_attr_name
)
code
.
putln
(
"}"
)
...
...
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