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
5fcc3e2e
Commit
5fcc3e2e
authored
Apr 22, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speed up refnanny
parent
019ef377
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
16 deletions
+25
-16
Cython/Runtime/refnanny.pyx
Cython/Runtime/refnanny.pyx
+25
-16
No files found.
Cython/Runtime/refnanny.pyx
View file @
5fcc3e2e
from
cpython.ref
cimport
PyObject
,
Py_INCREF
,
Py_DECREF
,
Py_XDECREF
from
cpython.ref
cimport
PyObject
,
Py_INCREF
,
Py_DECREF
,
Py_XDECREF
,
Py_XINCREF
from
cpython.exc
cimport
PyErr_Fetch
,
PyErr_Restore
from
cpython.pystate
cimport
PyThreadState_Get
cimport
cython
loglevel
=
0
reflog
=
[]
...
...
@@ -12,7 +13,13 @@ cdef log(level, action, obj, lineno):
LOG_NONE
,
LOG_ALL
=
range
(
2
)
class
Context
(
object
):
@
cython
.
final
cdef
class
Context
(
object
):
cdef
object
name
,
filename
cdef
dict
refs
cdef
list
errors
cdef
Py_ssize_t
start
def
__init__
(
self
,
name
,
line
=
0
,
filename
=
None
):
self
.
name
=
name
self
.
start
=
line
...
...
@@ -20,7 +27,7 @@ class Context(object):
self
.
refs
=
{}
# id -> (count, [lineno])
self
.
errors
=
[]
def
regref
(
self
,
obj
,
lineno
,
is_null
):
cdef
regref
(
self
,
obj
,
lineno
,
bint
is_null
):
log
(
LOG_ALL
,
u'regref'
,
u"<NULL>"
if
is_null
else
obj
,
lineno
)
if
is_null
:
self
.
errors
.
append
(
u"NULL argument on line %d"
%
lineno
)
...
...
@@ -30,7 +37,7 @@ class Context(object):
self
.
refs
[
id_
]
=
(
count
+
1
,
linenumbers
)
linenumbers
.
append
(
lineno
)
def
delref
(
self
,
obj
,
lineno
,
is_null
)
:
cdef
bint
delref
(
self
,
obj
,
lineno
,
bint
is_null
)
except
-
1
:
# returns whether it is ok to do the decref operation
log
(
LOG_ALL
,
u'delref'
,
u"<NULL>"
if
is_null
else
obj
,
lineno
)
if
is_null
:
...
...
@@ -49,8 +56,8 @@ class Context(object):
self
.
refs
[
id_
]
=
(
count
-
1
,
linenumbers
)
return
True
def
end
(
self
):
if
len
(
self
.
refs
)
>
0
:
c
def
end
(
self
):
if
self
.
refs
:
msg
=
u""
for
count
,
linenos
in
self
.
refs
.
itervalues
():
msg
+=
u"
\
n
Acquired on lines: "
+
u", "
.
join
([
u"%d"
%
x
for
x
in
linenos
])
...
...
@@ -99,9 +106,9 @@ cdef void GOTREF(PyObject* ctx, PyObject* p_obj, int lineno):
try
:
try
:
if
p_obj
is
NULL
:
(
<
objec
t
>
ctx
).
regref
(
None
,
lineno
,
True
)
(
<
Contex
t
>
ctx
).
regref
(
None
,
lineno
,
True
)
else
:
(
<
objec
t
>
ctx
).
regref
(
<
object
>
p_obj
,
lineno
,
False
)
(
<
Contex
t
>
ctx
).
regref
(
<
object
>
p_obj
,
lineno
,
False
)
except
:
report_unraisable
()
except
:
...
...
@@ -117,9 +124,9 @@ cdef int GIVEREF_and_report(PyObject* ctx, PyObject* p_obj, int lineno):
try
:
try
:
if
p_obj
is
NULL
:
decref_ok
=
(
<
objec
t
>
ctx
).
delref
(
None
,
lineno
,
True
)
decref_ok
=
(
<
Contex
t
>
ctx
).
delref
(
None
,
lineno
,
True
)
else
:
decref_ok
=
(
<
objec
t
>
ctx
).
delref
(
<
object
>
p_obj
,
lineno
,
False
)
decref_ok
=
(
<
Contex
t
>
ctx
).
delref
(
<
object
>
p_obj
,
lineno
,
False
)
except
:
report_unraisable
()
except
:
...
...
@@ -132,34 +139,36 @@ cdef void GIVEREF(PyObject* ctx, PyObject* p_obj, int lineno):
GIVEREF_and_report
(
ctx
,
p_obj
,
lineno
)
cdef
void
INCREF
(
PyObject
*
ctx
,
PyObject
*
obj
,
int
lineno
):
if
obj
is
not
NULL
:
Py_INCREF
(
<
object
>
obj
)
Py_XINCREF
(
obj
)
PyThreadState_Get
()
GOTREF
(
ctx
,
obj
,
lineno
)
cdef
void
DECREF
(
PyObject
*
ctx
,
PyObject
*
obj
,
int
lineno
):
if
GIVEREF_and_report
(
ctx
,
obj
,
lineno
):
if
obj
is
not
NULL
:
Py_DECREF
(
<
object
>
obj
)
Py_XDECREF
(
obj
)
PyThreadState_Get
()
cdef
void
FinishContext
(
PyObject
**
ctx
):
if
ctx
==
NULL
or
ctx
[
0
]
==
NULL
:
return
cdef
PyObject
*
type
=
NULL
,
*
value
=
NULL
,
*
tb
=
NULL
cdef
object
errors
=
None
cdef
Context
context
PyThreadState_Get
()
PyErr_Fetch
(
&
type
,
&
value
,
&
tb
)
try
:
try
:
errors
=
(
<
object
>
ctx
[
0
]).
end
()
pos
=
(
<
object
>
ctx
[
0
]).
filename
,
(
<
object
>
ctx
[
0
]).
name
context
=
<
Context
>
ctx
[
0
]
errors
=
context
.
end
()
if
errors
:
print
u"%s: %s()"
%
pos
print
u"%s: %s()"
%
(
context
.
filename
,
context
.
name
)
print
errors
context
=
None
except
:
report_unraisable
()
except
:
# __Pyx_GetException may itself raise errors
pass
Py_
DECREF
(
<
object
>
ctx
[
0
])
Py_
XDECREF
(
ctx
[
0
])
ctx
[
0
]
=
NULL
PyErr_Restore
(
type
,
value
,
tb
)
...
...
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