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
7af30ae2
Commit
7af30ae2
authored
May 27, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make C lines in exception tracebacks a runtime setting.
Also changes the default to False.
parent
1b7a91a2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
2 deletions
+60
-2
CHANGES.rst
CHANGES.rst
+4
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+5
-0
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+1
-0
Cython/Utility/Exceptions.c
Cython/Utility/Exceptions.c
+15
-2
tests/run/tracebacks.pyx
tests/run/tracebacks.pyx
+35
-0
No files found.
CHANGES.rst
View file @
7af30ae2
...
...
@@ -24,6 +24,10 @@ Features added
* cdef classes now support pickling by default when possible.
* The display of C lines in Cython tracebacks is now settable at runtime
via `import cython_runtime; cython_runtime.cline_in_traceback=True`.
The default has been changed to False.
Bugs fixed
----------
...
...
Cython/Compiler/ModuleNode.py
View file @
7af30ae2
...
...
@@ -702,6 +702,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
'static PyObject *%s;'
%
env
.
module_cname
)
code
.
putln
(
'static PyObject *%s;'
%
env
.
module_dict_cname
)
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
builtins_cname
)
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
cython_runtime_cname
)
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
empty_tuple
)
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
empty_bytes
)
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
empty_unicode
)
...
...
@@ -2476,6 +2477,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
'%s = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); %s'
%
(
Naming
.
builtins_cname
,
code
.
error_goto_if_null
(
Naming
.
builtins_cname
,
self
.
pos
)))
code
.
putln
(
'%s = PyImport_AddModule((char *) "cython_runtime"); %s'
%
(
Naming
.
cython_runtime_cname
,
code
.
error_goto_if_null
(
Naming
.
cython_runtime_cname
,
self
.
pos
)))
code
.
putln
(
'#if CYTHON_COMPILING_IN_PYPY'
)
code
.
putln
(
'Py_INCREF(%s);'
%
Naming
.
builtins_cname
)
code
.
putln
(
'#endif'
)
...
...
Cython/Compiler/Naming.py
View file @
7af30ae2
...
...
@@ -112,6 +112,7 @@ frame_code_cname = pyrex_prefix + "frame_code"
binding_cfunc
=
pyrex_prefix
+
"binding_PyCFunctionType"
fused_func_prefix
=
pyrex_prefix
+
'fuse_'
quick_temp_cname
=
pyrex_prefix
+
"temp"
# temp variable for quick'n'dirty temping
cython_runtime_cname
=
pyrex_prefix
+
"cython_runtime"
global_code_object_cache_find
=
pyrex_prefix
+
'find_code_object'
global_code_object_cache_insert
=
pyrex_prefix
+
'insert_code_object'
...
...
Cython/Utility/Exceptions.c
View file @
7af30ae2
...
...
@@ -600,13 +600,25 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
int
py_line
,
const
char
*
filename
)
{
PyCodeObject
*
py_code
=
0
;
PyFrameObject
*
py_frame
=
0
;
PyObject
*
use_cline
=
0
;
PyObject
*
ptype
,
*
pvalue
,
*
ptraceback
;
py_code
=
$
global_code_object_cache_find
(
c_line
?
c_line
:
py_line
);
if
(
c_line
)
{
PyErr_Fetch
(
&
ptype
,
&
pvalue
,
&
ptraceback
);
use_cline
=
PyObject_GetAttrString
(
$
{
cython_runtime_cname
},
"cline_in_traceback"
);
if
(
use_cline
==
NULL
||
PyObject_Not
(
use_cline
)
!=
0
)
{
c_line
=
0
;
}
PyErr_Restore
(
ptype
,
pvalue
,
ptraceback
);
}
// Negate to avoid collisions between py and c lines.
py_code
=
$
global_code_object_cache_find
(
c_line
?
-
c_line
:
py_line
);
if
(
!
py_code
)
{
py_code
=
__Pyx_CreateCodeObjectForTraceback
(
funcname
,
c_line
,
py_line
,
filename
);
if
(
!
py_code
)
goto
bad
;
$
global_code_object_cache_insert
(
c_line
?
c_line
:
py_line
,
py_code
);
$
global_code_object_cache_insert
(
c_line
?
-
c_line
:
py_line
,
py_code
);
}
py_frame
=
PyFrame_New
(
PyThreadState_GET
(),
/*PyThreadState *tstate,*/
...
...
@@ -620,4 +632,5 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
bad:
Py_XDECREF
(
py_code
);
Py_XDECREF
(
py_frame
);
Py_XDECREF
(
use_cline
);
}
tests/run/tracebacks.pyx
0 → 100644
View file @
7af30ae2
import
traceback
def
foo1
():
foo2
()
cdef
foo2
():
foo3
()
cdef
int
foo3
()
except
-
1
:
raise
RuntimeError
(
'my_message'
)
def
test_traceback
(
cline_in_traceback
=
None
):
"""
>>> test_traceback()
>>> test_traceback(True)
>>> test_traceback(False)
"""
if
cline_in_traceback
is
not
None
:
import
cython_runtime
cython_runtime
.
cline_in_traceback
=
cline_in_traceback
try
:
foo1
()
except
:
tb_string
=
traceback
.
format_exc
()
expected
=
(
'tracebacks.pyx'
,
'foo1'
,
'foo2'
,
'foo3'
,
'line 4'
,
'line 7'
,
'line 10'
,
'my_message'
)
for
s
in
expected
:
assert
s
in
tb_string
,
s
if
cline_in_traceback
:
assert
'tracebacks.c'
in
tb_string
else
:
assert
'tracebacks.c'
not
in
tb_string
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