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
9db97fa5
Commit
9db97fa5
authored
Feb 02, 2009
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make refnanny trap and complain about NULL arguments to xxxREF
parent
95471a58
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
Cython/Runtime/refnanny.pyx
Cython/Runtime/refnanny.pyx
+24
-12
No files found.
Cython/Runtime/refnanny.pyx
View file @
9db97fa5
...
@@ -19,15 +19,21 @@ class RefnannyContext(object):
...
@@ -19,15 +19,21 @@ class RefnannyContext(object):
self
.
refs
=
{}
# id -> (count, [lineno])
self
.
refs
=
{}
# id -> (count, [lineno])
self
.
errors
=
[]
self
.
errors
=
[]
def
regref
(
self
,
obj
,
lineno
):
def
regref
(
self
,
obj
,
lineno
,
is_null
):
log
(
LOG_ALL
,
'regref'
,
obj
,
lineno
)
log
(
LOG_ALL
,
'regref'
,
"<NULL>"
if
is_null
else
obj
,
lineno
)
if
is_null
:
self
.
errors
.
append
(
"NULL argument on line %d"
%
lineno
)
return
id_
=
id
(
obj
)
id_
=
id
(
obj
)
count
,
linenumbers
=
self
.
refs
.
get
(
id_
,
(
0
,
[]))
count
,
linenumbers
=
self
.
refs
.
get
(
id_
,
(
0
,
[]))
self
.
refs
[
id_
]
=
(
count
+
1
,
linenumbers
)
self
.
refs
[
id_
]
=
(
count
+
1
,
linenumbers
)
linenumbers
.
append
(
lineno
)
linenumbers
.
append
(
lineno
)
def
delref
(
self
,
obj
,
lineno
):
def
delref
(
self
,
obj
,
lineno
,
is_null
):
log
(
LOG_ALL
,
'delref'
,
obj
,
lineno
)
log
(
LOG_ALL
,
'delref'
,
"<NULL>"
if
is_null
else
obj
,
lineno
)
if
is_null
:
self
.
errors
.
append
(
"NULL argument on line %d"
%
lineno
)
return
id_
=
id
(
obj
)
id_
=
id
(
obj
)
count
,
linenumbers
=
self
.
refs
.
get
(
id_
,
(
0
,
[]))
count
,
linenumbers
=
self
.
refs
.
get
(
id_
,
(
0
,
[]))
if
count
==
0
:
if
count
==
0
:
...
@@ -56,12 +62,15 @@ cdef public void* __Pyx_Refnanny_NewContext(char* funcname, int lineno) except N
...
@@ -56,12 +62,15 @@ cdef public void* __Pyx_Refnanny_NewContext(char* funcname, int lineno) except N
Py_INCREF
(
ctx
)
Py_INCREF
(
ctx
)
return
<
void
*>
ctx
return
<
void
*>
ctx
cdef
public
void
__Pyx_Refnanny_GOTREF
(
void
*
ctx
,
object
obj
,
int
lineno
):
cdef
public
void
__Pyx_Refnanny_GOTREF
(
void
*
ctx
,
void
*
p_
obj
,
int
lineno
):
cdef
exc
.
PyObject
*
type
,
*
value
,
*
tb
cdef
exc
.
PyObject
*
type
,
*
value
,
*
tb
if
ctx
==
NULL
:
return
if
ctx
==
NULL
:
return
exc
.
PyErr_Fetch
(
&
type
,
&
value
,
&
tb
)
exc
.
PyErr_Fetch
(
&
type
,
&
value
,
&
tb
)
try
:
try
:
(
<
object
>
ctx
).
regref
(
obj
,
lineno
)
if
p_obj
is
NULL
:
(
<
object
>
ctx
).
regref
(
None
,
lineno
,
True
)
else
:
(
<
object
>
ctx
).
regref
(
<
object
>
p_obj
,
lineno
,
False
)
exc
.
PyErr_Restore
(
<
object
>
type
,
<
object
>
value
,
<
object
>
tb
)
exc
.
PyErr_Restore
(
<
object
>
type
,
<
object
>
value
,
<
object
>
tb
)
except
:
except
:
Py_XDECREF
(
<
object
>
type
)
Py_XDECREF
(
<
object
>
type
)
...
@@ -69,12 +78,15 @@ cdef public void __Pyx_Refnanny_GOTREF(void* ctx, object obj, int lineno):
...
@@ -69,12 +78,15 @@ cdef public void __Pyx_Refnanny_GOTREF(void* ctx, object obj, int lineno):
Py_XDECREF
(
<
object
>
tb
)
Py_XDECREF
(
<
object
>
tb
)
raise
raise
cdef
public
void
__Pyx_Refnanny_GIVEREF
(
void
*
ctx
,
object
obj
,
int
lineno
):
cdef
public
void
__Pyx_Refnanny_GIVEREF
(
void
*
ctx
,
void
*
p_
obj
,
int
lineno
):
cdef
exc
.
PyObject
*
type
,
*
value
,
*
tb
cdef
exc
.
PyObject
*
type
,
*
value
,
*
tb
if
ctx
==
NULL
:
return
if
ctx
==
NULL
:
return
exc
.
PyErr_Fetch
(
&
type
,
&
value
,
&
tb
)
exc
.
PyErr_Fetch
(
&
type
,
&
value
,
&
tb
)
try
:
try
:
(
<
object
>
ctx
).
delref
(
obj
,
lineno
)
if
p_obj
is
NULL
:
(
<
object
>
ctx
).
delref
(
None
,
lineno
,
True
)
else
:
(
<
object
>
ctx
).
delref
(
<
object
>
p_obj
,
lineno
,
False
)
exc
.
PyErr_Restore
(
<
object
>
type
,
<
object
>
value
,
<
object
>
tb
)
exc
.
PyErr_Restore
(
<
object
>
type
,
<
object
>
value
,
<
object
>
tb
)
except
:
except
:
Py_XDECREF
(
<
object
>
type
)
Py_XDECREF
(
<
object
>
type
)
...
@@ -82,15 +94,15 @@ cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, object obj, int lineno):
...
@@ -82,15 +94,15 @@ cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, object obj, int lineno):
Py_XDECREF
(
<
object
>
tb
)
Py_XDECREF
(
<
object
>
tb
)
raise
raise
cdef
public
void
__Pyx_Refnanny_INCREF
(
void
*
ctx
,
object
obj
,
int
lineno
):
cdef
public
void
__Pyx_Refnanny_INCREF
(
void
*
ctx
,
void
*
obj
,
int
lineno
):
Py_INCREF
(
obj
)
if
obj
is
not
NULL
:
Py_INCREF
(
<
object
>
obj
)
__Pyx_Refnanny_GOTREF
(
ctx
,
obj
,
lineno
)
__Pyx_Refnanny_GOTREF
(
ctx
,
obj
,
lineno
)
cdef
public
void
__Pyx_Refnanny_DECREF
(
void
*
ctx
,
object
obj
,
int
lineno
):
cdef
public
void
__Pyx_Refnanny_DECREF
(
void
*
ctx
,
void
*
obj
,
int
lineno
):
# GIVEREF raises exception if we hit 0
# GIVEREF raises exception if we hit 0
#
#
__Pyx_Refnanny_GIVEREF
(
ctx
,
obj
,
lineno
)
__Pyx_Refnanny_GIVEREF
(
ctx
,
obj
,
lineno
)
Py_DECREF
(
obj
)
if
obj
is
not
NULL
:
Py_DECREF
(
<
object
>
obj
)
cdef
public
int
__Pyx_Refnanny_FinishContext
(
void
*
ctx
)
except
-
1
:
cdef
public
int
__Pyx_Refnanny_FinishContext
(
void
*
ctx
)
except
-
1
:
cdef
exc
.
PyObject
*
type
,
*
value
,
*
tb
cdef
exc
.
PyObject
*
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