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
Gwenaël Samain
cython
Commits
17e63f6a
Commit
17e63f6a
authored
Jul 25, 2017
by
Dmitry Trofimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests after handling the case when tracing function returns None
parent
dfc47cd4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
21 deletions
+61
-21
Cython/Utility/Profile.c
Cython/Utility/Profile.c
+6
-3
tests/run/line_trace.pyx
tests/run/line_trace.pyx
+55
-18
No files found.
Cython/Utility/Profile.c
View file @
17e63f6a
...
...
@@ -198,7 +198,8 @@
PyThreadState *tstate; \
PyGILState_STATE state = PyGILState_Ensure(); \
tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing && __pyx_frame->f_trace != Py_None)) { \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc \
&& __pyx_frame->f_trace != Py_None)) { \
ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
} \
PyGILState_Release(state); \
...
...
@@ -206,7 +207,8 @@
} \
} else { \
PyThreadState* tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing && __pyx_frame->f_trace != Py_None)) { \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc \
&& __pyx_frame->f_trace != Py_None)) { \
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
if (unlikely(ret)) goto_error; \
} \
...
...
@@ -216,7 +218,8 @@
#define __Pyx_TraceLine(lineno, nogil, goto_error) \
if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing && __pyx_frame->f_trace != Py_None)) { \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc \
&& __pyx_frame->f_trace != Py_None)) { \
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
if (unlikely(ret)) goto_error; \
} \
...
...
tests/run/line_trace.pyx
View file @
17e63f6a
...
...
@@ -30,25 +30,62 @@ map_trace_types = {
}.
get
cdef
int
_trace_func
(
PyObject
*
_traceobj
,
PyFrameObject
*
_frame
,
int
what
,
PyObject
*
arg
)
except
-
1
:
frame
,
traceobj
=
<
object
>
_frame
,
<
object
>
_traceobj
traceobj
.
append
((
map_trace_types
(
what
),
frame
.
f_lineno
-
frame
.
f_code
.
co_firstlineno
))
cdef
int
trace_trampoline
(
PyObject
*
_traceobj
,
PyFrameObject
*
_frame
,
int
what
,
PyObject
*
_arg
)
except
-
1
:
frame
=
<
object
>
_frame
traceobj
=
<
object
>
_traceobj
if
_traceobj
else
None
arg
=
<
object
>
_arg
if
_arg
else
None
if
what
==
PyTrace_CALL
:
callback
=
traceobj
else
:
callback
=
frame
.
f_trace
if
callback
is
None
:
return
0
result
=
callback
(
frame
,
what
,
arg
)
cdef
int
_failing_call_trace_func
(
PyObject
*
_traceobj
,
PyFrameObject
*
_frame
,
int
what
,
PyObject
*
arg
)
except
-
1
:
if
what
==
PyTrace_CALL
:
frame
.
f_trace
=
result
if
result
is
None
:
PyEval_SetTrace
(
NULL
,
None
)
return
-
1
else
:
return
0
def
_create_trace_func
(
trace
):
def
_trace_func
(
frame
,
event
,
arg
):
trace
.
append
((
map_trace_types
(
event
),
frame
.
f_lineno
-
frame
.
f_code
.
co_firstlineno
))
return
_trace_func
return
_trace_func
def
_create_failing_call_trace_func
(
trace
):
func
=
_create_trace_func
(
trace
)
def
_trace_func
(
frame
,
event
,
arg
):
if
event
==
PyTrace_CALL
:
raise
ValueError
(
"failing call trace!"
)
return
_trace_func
(
_traceobj
,
_frame
,
what
,
arg
)
func
(
frame
,
event
,
arg
)
return
_trace_func
return
_trace_func
cdef
int
_failing_line_trace_func
(
PyObject
*
_traceobj
,
PyFrameObject
*
_frame
,
int
what
,
PyObject
*
arg
)
except
-
1
:
if
what
==
PyTrace_LINE
and
_traceobj
:
frame
,
traceobj
=
<
object
>
_frame
,
<
object
>
_traceobj
if
traceobj
and
traceobj
[
0
]
==
frame
.
f_code
.
co_name
:
def
_create__failing_line_trace_func
(
trace
):
func
=
_create_trace_func
(
trace
)
def
_trace_func
(
frame
,
event
,
arg
):
if
event
==
PyTrace_LINE
and
trace
:
if
trace
and
trace
[
0
]
==
frame
.
f_code
.
co_name
:
# first line in the right function => fail!
raise
ValueError
(
"failing line trace!"
)
return
_trace_func
(
_traceobj
,
_frame
,
what
,
arg
)
func
(
frame
,
event
,
arg
)
return
_trace_func
return
_trace_func
def
cy_add
(
a
,
b
):
...
...
@@ -87,7 +124,7 @@ def run_trace(func, *args):
[('line', 2), ('line', 5), ('return', 5)]
"""
trace
=
[]
PyEval_SetTrace
(
<
Py_tracefunc
>
_trace_func
,
trace
)
PyEval_SetTrace
(
<
Py_tracefunc
>
trace_trampoline
,
_create_trace_func
(
trace
)
)
try
:
func
(
*
args
)
finally
:
...
...
@@ -105,7 +142,7 @@ def fail_on_call_trace(func, *args):
ValueError: failing call trace!
"""
trace
=
[]
PyEval_SetTrace
(
<
Py_tracefunc
>
_failing_call_trace_func
,
trace
)
PyEval_SetTrace
(
<
Py_tracefunc
>
trace_trampoline
,
_create_failing_call_trace_func
(
trace
)
)
try
:
func
(
*
args
)
finally
:
...
...
@@ -142,7 +179,7 @@ def fail_on_line_trace(fail_func):
cdef
int
x
=
1
trace
=
[
'NO ERROR'
]
exception
=
None
PyEval_SetTrace
(
<
Py_tracefunc
>
_failing_line_trace_func
,
trace
)
PyEval_SetTrace
(
<
Py_tracefunc
>
trace_trampoline
,
_create__failing_line_trace_func
(
trace
)
)
try
:
x
+=
1
cy_add
(
1
,
2
)
...
...
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