Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
91e556af
Commit
91e556af
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
objexcept: Support tracebacks for user Exception subclasses.
parent
0a7e01ae
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/objexcept.c
+26
-24
26 additions, 24 deletions
py/objexcept.c
with
26 additions
and
24 deletions
py/objexcept.c
+
26
−
24
View file @
91e556af
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include
"qstr.h"
#include
"qstr.h"
#include
"obj.h"
#include
"obj.h"
#include
"objtuple.h"
#include
"objtuple.h"
#include
"objtype.h"
#include
"runtime.h"
#include
"runtime.h"
#include
"runtime0.h"
#include
"runtime0.h"
...
@@ -271,23 +272,27 @@ bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type) {
...
@@ -271,23 +272,27 @@ bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type) {
return
mp_binary_op
(
MP_BINARY_OP_EXCEPTION_MATCH
,
exc
,
(
mp_obj_t
)
exc_type
)
==
mp_const_true
;
return
mp_binary_op
(
MP_BINARY_OP_EXCEPTION_MATCH
,
exc
,
(
mp_obj_t
)
exc_type
)
==
mp_const_true
;
}
}
void
mp_obj_exception_clear_traceback
(
mp_obj_t
self_in
)
{
// traceback handling functions
// make sure self_in is an exception instance
// TODO add traceback information to user-defined exceptions (need proper builtin subclassing for that)
if
(
mp_obj_get_type
(
self_in
)
->
make_new
==
mp_obj_exception_make_new
)
{
mp_obj_exception_t
*
self
=
self_in
;
#define GET_NATIVE_EXCEPTION(self, self_in) \
/* make sure self_in is an exception instance */
\
assert(mp_obj_is_exception_instance(self_in)); \
mp_obj_exception_t *self; \
if (mp_obj_is_native_exception_instance(self_in)) { \
self = self_in; \
} else { \
self = ((mp_obj_instance_t*)self_in)->subobj[0]; \
}
void
mp_obj_exception_clear_traceback
(
mp_obj_t
self_in
)
{
GET_NATIVE_EXCEPTION
(
self
,
self_in
);
// just set the traceback to the null object
// just set the traceback to the null object
// we don't want to call any memory management functions here
// we don't want to call any memory management functions here
self
->
traceback
=
MP_OBJ_NULL
;
self
->
traceback
=
MP_OBJ_NULL
;
}
}
}
void
mp_obj_exception_add_traceback
(
mp_obj_t
self_in
,
qstr
file
,
machine_uint_t
line
,
qstr
block
)
{
void
mp_obj_exception_add_traceback
(
mp_obj_t
self_in
,
qstr
file
,
machine_uint_t
line
,
qstr
block
)
{
// make sure self_in is an exception instance
GET_NATIVE_EXCEPTION
(
self
,
self_in
);
// TODO add traceback information to user-defined exceptions (need proper builtin subclassing for that)
if
(
mp_obj_get_type
(
self_in
)
->
make_new
==
mp_obj_exception_make_new
&&
self_in
!=
&
mp_emergency_exception_obj
)
{
mp_obj_exception_t
*
self
=
self_in
;
// for traceback, we are just using the list object for convenience, it's not really a list of Python objects
// for traceback, we are just using the list object for convenience, it's not really a list of Python objects
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
...
@@ -297,12 +302,9 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t
...
@@ -297,12 +302,9 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
line
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
line
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
block
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
block
);
}
}
}
void
mp_obj_exception_get_traceback
(
mp_obj_t
self_in
,
machine_uint_t
*
n
,
machine_uint_t
**
values
)
{
void
mp_obj_exception_get_traceback
(
mp_obj_t
self_in
,
machine_uint_t
*
n
,
machine_uint_t
**
values
)
{
// make sure self_in is an exception instance
GET_NATIVE_EXCEPTION
(
self
,
self_in
);
assert
(
mp_obj_get_type
(
self_in
)
->
make_new
==
mp_obj_exception_make_new
);
mp_obj_exception_t
*
self
=
self_in
;
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
*
n
=
0
;
*
n
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment