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
96b1afdf
Commit
96b1afdf
authored
Nov 27, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
42db8ab3
7b49db41
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
26 deletions
+29
-26
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+7
-10
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+17
-11
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+4
-4
Cython/Compiler/UtilNodes.py
Cython/Compiler/UtilNodes.py
+1
-1
No files found.
Cython/Compiler/Buffer.py
View file @
96b1afdf
...
...
@@ -293,17 +293,15 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type,
# Acquire
retcode_cname
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
c_int_type
)
code
.
putln
(
"%s = %s;"
%
(
retcode_cname
,
getbuffer
%
rhs_cname
))
code
.
putln
(
'if (%s) '
%
(
code
.
unlikely
(
"%s < 0"
%
retcode_cname
)))
code
.
putln
(
'if (%s)
{
'
%
(
code
.
unlikely
(
"%s < 0"
%
retcode_cname
)))
# If acquisition failed, attempt to reacquire the old buffer
# before raising the exception. A failure of reacquisition
# will cause the reacquisition exception to be reported, one
# can consider working around this later.
code
.
begin_block
()
type
,
value
,
tb
=
[
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
py_object_type
)
type
,
value
,
tb
=
[
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
py_object_type
,
manage_ref
=
False
)
for
i
in
range
(
3
)]
code
.
putln
(
'PyErr_Fetch(&%s, &%s, &%s);'
%
(
type
,
value
,
tb
))
code
.
put
(
'if (%s) '
%
code
.
unlikely
(
"%s == -1"
%
(
getbuffer
%
lhs_cname
)))
code
.
begin_block
()
code
.
putln
(
'if (%s) {'
%
code
.
unlikely
(
"%s == -1"
%
(
getbuffer
%
lhs_cname
)))
code
.
putln
(
'Py_XDECREF(%s); Py_XDECREF(%s); Py_XDECREF(%s);'
%
(
type
,
value
,
tb
))
code
.
globalstate
.
use_utility_code
(
raise_buffer_fallback_code
)
code
.
putln
(
'__Pyx_RaiseBufferFallbackError();'
)
...
...
@@ -311,9 +309,9 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type,
code
.
putln
(
'PyErr_Restore(%s, %s, %s);'
%
(
type
,
value
,
tb
))
for
t
in
(
type
,
value
,
tb
):
code
.
funcstate
.
release_temp
(
t
)
code
.
end_block
()
code
.
putln
(
'}'
)
code
.
putln
(
'}'
)
# Unpack indices
code
.
end_block
()
put_unpack_buffer_aux_into_scope
(
buffer_aux
,
buffer_type
.
mode
,
code
)
code
.
putln
(
code
.
error_goto_if_neg
(
retcode_cname
,
pos
))
code
.
funcstate
.
release_temp
(
retcode_cname
)
...
...
@@ -374,11 +372,10 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, options, pos, cod
code
.
unlikely
(
"%s >= %s"
%
(
cname
,
shape
.
cname
)),
tmp_cname
,
dim
))
code
.
globalstate
.
use_utility_code
(
raise_indexerror_code
)
code
.
put
(
"if (%s) "
%
code
.
unlikely
(
"%s != -1"
%
tmp_cname
))
code
.
begin_block
()
code
.
putln
(
"if (%s) {"
%
code
.
unlikely
(
"%s != -1"
%
tmp_cname
))
code
.
putln
(
'__Pyx_RaiseBufferIndexError(%s);'
%
tmp_cname
)
code
.
putln
(
code
.
error_goto
(
pos
))
code
.
end_block
(
)
code
.
putln
(
'}'
)
code
.
funcstate
.
release_temp
(
tmp_cname
)
elif
negative_indices
:
# Only fix negative indices.
...
...
Cython/Compiler/Code.py
View file @
96b1afdf
...
...
@@ -40,7 +40,7 @@ class FunctionState(object):
self
.
in_try_finally
=
0
self
.
exc_vars
=
None
self
.
temps_allocated
=
[]
# of (name, type)
self
.
temps_allocated
=
[]
# of (name, type
, manage_ref
)
self
.
temps_free
=
{}
# type -> list of free vars
self
.
temps_used_type
=
{}
# name -> type
self
.
temp_counter
=
0
...
...
@@ -104,12 +104,17 @@ class FunctionState(object):
def
label_used
(
self
,
lbl
):
return
lbl
in
self
.
labels_used
def
allocate_temp
(
self
,
type
):
def
allocate_temp
(
self
,
type
,
manage_ref
=
True
):
"""
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
and handed back, but will usually be a PyrexType.
If type.is_pyobject, manage_ref comes into play. If manage_ref is set to
True, the temp will be decref-ed on return statements and in exception
handling clauses. Otherwise the caller has to deal with any reference
counting of the variable.
A C string referring to the variable is returned.
"""
freelist
=
self
.
temps_free
.
get
(
type
)
...
...
@@ -120,7 +125,7 @@ class FunctionState(object):
self
.
temp_counter
+=
1
result
=
"%s%d"
%
(
Naming
.
codewriter_temp_prefix
,
self
.
temp_counter
)
if
not
result
in
self
.
names_taken
:
break
self
.
temps_allocated
.
append
((
result
,
type
))
self
.
temps_allocated
.
append
((
result
,
type
,
manage_ref
))
self
.
temps_used_type
[
result
]
=
type
return
result
...
...
@@ -138,23 +143,24 @@ class FunctionState(object):
freelist
.
append
(
name
)
def
temps_in_use
(
self
):
"""Return a list of (cname,type) tuples of temp names and their type
"""Return a list of (cname,type
,manage_ref
) tuples of temp names and their type
that are currently in use.
"""
used
=
[]
for
name
,
type
in
self
.
temps_allocated
:
for
name
,
type
,
manage_ref
in
self
.
temps_allocated
:
freelist
=
self
.
temps_free
.
get
(
type
)
if
freelist
is
None
or
name
not
in
freelist
:
used
.
append
((
name
,
type
))
used
.
append
((
name
,
type
,
manage_ref
))
return
used
def
py_temps_in_us
e
(
self
):
def
temps_holding_referenc
e
(
self
):
"""Return a list of (cname,type) tuples of temp names and their type
that are currently in use. This includes only Python object types.
that are currently in use. This includes only temps of a
Python object type which owns its reference.
"""
return
[(
name
,
type
)
for
name
,
type
in
self
.
temps_in_use
()
if
type
.
is_pyobject
]
for
name
,
type
,
manage_ref
in
self
.
temps_in_use
()
if
(
type
.
is_pyobject
and
manage_ref
)
]
class
GlobalState
(
object
):
# filename_table {string : int} for finding filename table indexes
...
...
@@ -674,7 +680,7 @@ class CCodeWriter(object):
self
.
putln
(
";"
)
def
put_temp_declarations
(
self
,
func_context
):
for
name
,
type
in
func_context
.
temps_allocated
:
for
name
,
type
,
manage_ref
in
func_context
.
temps_allocated
:
decl
=
type
.
declaration_code
(
name
)
if
type
.
is_pyobject
:
self
.
putln
(
"%s = NULL;"
%
decl
)
...
...
Cython/Compiler/Nodes.py
View file @
96b1afdf
...
...
@@ -1063,8 +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
in
code
.
funcstate
.
temps_allocated
:
if
type
.
is_pyobject
:
for
cname
,
type
,
manage_ref
in
code
.
funcstate
.
temps_allocated
:
if
type
.
is_pyobject
and
manage_ref
:
code
.
put_xdecref
(
cname
,
type
)
# Clean up buffers -- this calls a Python function
...
...
@@ -2369,7 +2369,7 @@ class PyClassDefNode(ClassDefNode):
def
as_cclass
(
self
):
"""
Return this node as if it were declared as an extension class
"
Return this node as if it were declared as an extension class
"""
bases
=
self
.
classobj
.
bases
.
args
if
len
(
bases
)
==
0
:
...
...
@@ -3296,7 +3296,7 @@ class ReturnStatNode(StatNode):
for
entry
in
self
.
temps_in_use
:
code
.
put_var_decref_clear
(
entry
)
# free temps the new way
for
cname
,
type
in
code
.
funcstate
.
py_temps_in_us
e
():
for
cname
,
type
in
code
.
funcstate
.
temps_holding_referenc
e
():
code
.
put_decref_clear
(
cname
,
type
)
#code.putln(
# "goto %s;" %
...
...
Cython/Compiler/UtilNodes.py
View file @
96b1afdf
...
...
@@ -79,7 +79,7 @@ class TempsBlockNode(Node):
def
generate_execution_code
(
self
,
code
):
for
handle
in
self
.
temps
:
handle
.
temp
=
code
.
funcstate
.
allocate_temp
(
handle
.
type
)
handle
.
temp
=
code
.
funcstate
.
allocate_temp
(
handle
.
type
,
manage_ref
=
True
)
self
.
body
.
generate_execution_code
(
code
)
for
handle
in
self
.
temps
:
if
handle
.
needs_cleanup
:
...
...
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