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
Boxiang Sun
cython
Commits
751d5612
Commit
751d5612
authored
Nov 27, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup, make manage_ref mandatory for allocate_temp. This caught a bug too.
parent
5e19cbac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
14 deletions
+25
-14
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+2
-2
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+17
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-3
No files found.
Cython/Compiler/Buffer.py
View file @
751d5612
...
...
@@ -291,7 +291,7 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type,
# Release any existing buffer
code
.
putln
(
'__Pyx_SafeReleaseBuffer(&%s);'
%
bufstruct
)
# Acquire
retcode_cname
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
c_int_type
)
retcode_cname
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
c_int_type
,
manage_ref
=
False
)
code
.
putln
(
"%s = %s;"
%
(
retcode_cname
,
getbuffer
%
rhs_cname
))
code
.
putln
(
'if (%s) {'
%
(
code
.
unlikely
(
"%s < 0"
%
retcode_cname
)))
# If acquisition failed, attempt to reacquire the old buffer
...
...
@@ -353,7 +353,7 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, options, pos, cod
# We allocate a temporary which is initialized to -1, meaning OK (!).
# If an error occurs, the temp is set to the dimension index the
# error is occuring at.
tmp_cname
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
c_int_type
)
tmp_cname
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
c_int_type
,
manage_ref
=
False
)
code
.
putln
(
"%s = -1;"
%
tmp_cname
)
for
dim
,
(
signed
,
cname
,
shape
)
in
enumerate
(
zip
(
index_signeds
,
index_cnames
,
bufaux
.
shapevars
)):
...
...
Cython/Compiler/Code.py
View file @
751d5612
...
...
@@ -104,7 +104,7 @@ class FunctionState(object):
def
label_used
(
self
,
lbl
):
return
lbl
in
self
.
labels_used
def
allocate_temp
(
self
,
type
,
manage_ref
=
True
):
def
allocate_temp
(
self
,
type
,
manage_ref
):
"""
Allocates a temporary (which may create a new one or get a previously
allocated and released one of the same type). Type is simply registered
...
...
@@ -115,11 +115,16 @@ class FunctionState(object):
handling clauses. Otherwise the caller has to deal with any reference
counting of the variable.
If not type.is_pyobject, then manage_ref will be ignored, but it
still has to be passed. It is recommended to pass False by convention
if it is known that type will never be a Python object.
A C string referring to the variable is returned.
"""
if
not
type
.
is_pyobject
and
manage_ref
is
not
True
:
# Make manage_ref canonical for temps_free lookup purposes
raise
ValueError
(
"manage_ref only applicable when type.is_pyobject"
)
if
not
type
.
is_pyobject
:
# Make manage_ref canonical, so that manage_ref will always mean
# a decref is needed.
manage_ref
=
False
freelist
=
self
.
temps_free
.
get
((
type
,
manage_ref
))
if
freelist
is
not
None
and
len
(
freelist
)
>
0
:
result
=
freelist
.
pop
()
...
...
@@ -163,7 +168,14 @@ class FunctionState(object):
"""
return
[(
name
,
type
)
for
name
,
type
,
manage_ref
in
self
.
temps_in_use
()
if
(
type
.
is_pyobject
and
manage_ref
)]
if
manage_ref
]
def
all_managed_temps
(
self
):
"""Return a list of (cname, type) tuples of refcount-managed Python objects.
"""
return
[(
cname
,
type
)
for
cname
,
type
,
manage_ref
in
self
.
temps_allocated
if
manage_ref
]
class
GlobalState
(
object
):
# filename_table {string : int} for finding filename table indexes
...
...
Cython/Compiler/ExprNodes.py
View file @
751d5612
...
...
@@ -613,7 +613,7 @@ class NewTempExprNode(ExprNode):
if
self
.
backwards_compatible_result
:
self
.
temp_code
=
self
.
backwards_compatible_result
else
:
self
.
temp_code
=
code
.
funcstate
.
allocate_temp
(
type
)
self
.
temp_code
=
code
.
funcstate
.
allocate_temp
(
type
,
manage_ref
=
True
)
else
:
self
.
temp_code
=
None
...
...
@@ -1718,9 +1718,9 @@ class IndexNode(ExprNode):
if
self
.
buffer_type
.
dtype
.
is_pyobject
:
# Must manage refcounts. Decref what is already there
# and incref what we put in.
ptr
=
code
.
funcstate
.
allocate_temp
(
self
.
buffer_type
.
buffer_ptr_type
)
ptr
=
code
.
funcstate
.
allocate_temp
(
self
.
buffer_type
.
buffer_ptr_type
,
manage_ref
=
False
)
if
rhs
.
is_temp
:
rhs_code
=
code
.
funcstate
.
allocate_temp
(
rhs
.
type
)
rhs_code
=
code
.
funcstate
.
allocate_temp
(
rhs
.
type
,
manage_ref
=
False
)
else
:
rhs_code
=
rhs
.
result
()
code
.
putln
(
"%s = %s;"
%
(
ptr
,
ptrexpr
))
...
...
@@ -1772,7 +1772,7 @@ class IndexNode(ExprNode):
def
buffer_lookup_code
(
self
,
code
):
# Assign indices to temps
index_temps
=
[
code
.
funcstate
.
allocate_temp
(
i
.
type
)
for
i
in
self
.
indices
]
index_temps
=
[
code
.
funcstate
.
allocate_temp
(
i
.
type
,
manage_ref
=
False
)
for
i
in
self
.
indices
]
for
temp
,
index
in
zip
(
index_temps
,
self
.
indices
):
code
.
putln
(
"%s = %s;"
%
(
temp
,
index
.
result
()))
# Generate buffer access code using these temps
...
...
Cython/Compiler/Nodes.py
View file @
751d5612
...
...
@@ -1063,9 +1063,8 @@ class FuncDefNode(StatNode, BlockNode):
# cleanup temps the old way
code
.
put_var_xdecrefs
(
lenv
.
temp_entries
)
# cleanup temps the new way
for
cname
,
type
,
manage_ref
in
code
.
funcstate
.
temps_allocated
:
if
type
.
is_pyobject
and
manage_ref
:
code
.
put_xdecref
(
cname
,
type
)
for
cname
,
type
in
code
.
funcstate
.
all_managed_temps
():
code
.
put_xdecref
(
cname
,
type
)
# Clean up buffers -- this calls a Python function
# so need to save and restore error state
...
...
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