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
d8351ca8
Commit
d8351ca8
authored
May 1, 2014
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
objtype: .print() Exception instances in adhoc way.
This is ugly, just as expected.
parent
f2021ffe
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
py/obj.h
+6
-3
6 additions, 3 deletions
py/obj.h
py/objexcept.c
+10
-5
10 additions, 5 deletions
py/objexcept.c
py/objtype.c
+9
-1
9 additions, 1 deletion
py/objtype.c
tests/basics/subclass-native3.py
+1
-2
1 addition, 2 deletions
tests/basics/subclass-native3.py
with
26 additions
and
11 deletions
py/obj.h
+
6
−
3
View file @
d8351ca8
...
@@ -169,9 +169,10 @@ typedef mp_obj_t (*mp_fun_var_t)(uint n, const mp_obj_t *);
...
@@ -169,9 +169,10 @@ typedef mp_obj_t (*mp_fun_var_t)(uint n, const mp_obj_t *);
typedef
mp_obj_t
(
*
mp_fun_kw_t
)(
uint
n
,
const
mp_obj_t
*
,
mp_map_t
*
);
typedef
mp_obj_t
(
*
mp_fun_kw_t
)(
uint
n
,
const
mp_obj_t
*
,
mp_map_t
*
);
typedef
enum
{
typedef
enum
{
PRINT_STR
,
PRINT_STR
=
0
,
PRINT_REPR
,
PRINT_REPR
=
1
,
PRINT_EXC
,
// Special format for printing exception in unhandled exception message
PRINT_EXC
=
2
,
// Special format for printing exception in unhandled exception message
PRINT_EXC_SUBCLASS
=
4
,
// Internal flag for printing exception subclasses
}
mp_print_kind_t
;
}
mp_print_kind_t
;
typedef
void
(
*
mp_print_fun_t
)(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
o
,
mp_print_kind_t
kind
);
typedef
void
(
*
mp_print_fun_t
)(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
o
,
mp_print_kind_t
kind
);
...
@@ -424,6 +425,7 @@ mp_float_t mp_obj_int_as_float(mp_obj_t self_in);
...
@@ -424,6 +425,7 @@ mp_float_t mp_obj_int_as_float(mp_obj_t self_in);
machine_int_t
mp_obj_int_get_checked
(
mp_obj_t
self_in
);
machine_int_t
mp_obj_int_get_checked
(
mp_obj_t
self_in
);
// exception
// exception
#define mp_obj_is_native_exception_instance(o) (mp_obj_get_type(o)->make_new == mp_obj_exception_make_new)
bool
mp_obj_is_exception_type
(
mp_obj_t
self_in
);
bool
mp_obj_is_exception_type
(
mp_obj_t
self_in
);
bool
mp_obj_is_exception_instance
(
mp_obj_t
self_in
);
bool
mp_obj_is_exception_instance
(
mp_obj_t
self_in
);
bool
mp_obj_exception_match
(
mp_obj_t
exc
,
const
mp_obj_type_t
*
exc_type
);
bool
mp_obj_exception_match
(
mp_obj_t
exc
,
const
mp_obj_type_t
*
exc_type
);
...
@@ -431,6 +433,7 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in);
...
@@ -431,6 +433,7 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in);
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
);
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
);
mp_obj_t
mp_obj_exception_get_value
(
mp_obj_t
self_in
);
mp_obj_t
mp_obj_exception_get_value
(
mp_obj_t
self_in
);
mp_obj_t
mp_obj_exception_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
);
// str
// str
mp_obj_t
mp_obj_str_builder_start
(
const
mp_obj_type_t
*
type
,
uint
len
,
byte
**
data
);
mp_obj_t
mp_obj_str_builder_start
(
const
mp_obj_type_t
*
type
,
uint
len
,
byte
**
data
);
...
...
This diff is collapsed.
Click to expand it.
py/objexcept.c
+
10
−
5
View file @
d8351ca8
...
@@ -30,12 +30,17 @@ const mp_obj_exception_t mp_const_GeneratorExit_obj = {{&mp_type_GeneratorExit},
...
@@ -30,12 +30,17 @@ const mp_obj_exception_t mp_const_GeneratorExit_obj = {{&mp_type_GeneratorExit},
STATIC
void
mp_obj_exception_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
o_in
,
mp_print_kind_t
kind
)
{
STATIC
void
mp_obj_exception_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
o_in
,
mp_print_kind_t
kind
)
{
mp_obj_exception_t
*
o
=
o_in
;
mp_obj_exception_t
*
o
=
o_in
;
if
(
kind
==
PRINT_REPR
)
{
mp_print_kind_t
k
=
kind
&
~
PRINT_EXC_SUBCLASS
;
bool
is_subclass
=
kind
&
PRINT_EXC_SUBCLASS
;
if
(
!
is_subclass
&&
(
k
==
PRINT_REPR
||
k
==
PRINT_EXC
))
{
print
(
env
,
"%s"
,
qstr_str
(
o
->
base
.
type
->
name
));
print
(
env
,
"%s"
,
qstr_str
(
o
->
base
.
type
->
name
));
}
else
if
(
kind
==
PRINT_EXC
)
{
print
(
env
,
"%s: "
,
qstr_str
(
o
->
base
.
type
->
name
));
}
}
if
(
kind
==
PRINT_STR
||
kind
==
PRINT_EXC
)
{
if
(
k
==
PRINT_EXC
)
{
print
(
env
,
": "
);
}
if
(
k
==
PRINT_STR
||
k
==
PRINT_EXC
)
{
if
(
o
->
args
==
NULL
||
o
->
args
->
len
==
0
)
{
if
(
o
->
args
==
NULL
||
o
->
args
->
len
==
0
)
{
print
(
env
,
""
);
print
(
env
,
""
);
return
;
return
;
...
@@ -47,7 +52,7 @@ STATIC void mp_obj_exception_print(void (*print)(void *env, const char *fmt, ...
...
@@ -47,7 +52,7 @@ STATIC void mp_obj_exception_print(void (*print)(void *env, const char *fmt, ...
tuple_print
(
print
,
env
,
o
->
args
,
kind
);
tuple_print
(
print
,
env
,
o
->
args
,
kind
);
}
}
STATIC
mp_obj_t
mp_obj_exception_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
mp_obj_t
mp_obj_exception_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
mp_obj_type_t
*
type
=
type_in
;
mp_obj_type_t
*
type
=
type_in
;
if
(
n_kw
!=
0
)
{
if
(
n_kw
!=
0
)
{
...
...
This diff is collapsed.
Click to expand it.
py/objtype.c
+
9
−
1
View file @
d8351ca8
...
@@ -148,7 +148,15 @@ STATIC void class_print(void (*print)(void *env, const char *fmt, ...), void *en
...
@@ -148,7 +148,15 @@ STATIC void class_print(void (*print)(void *env, const char *fmt, ...), void *en
}
}
if
(
member
[
0
]
==
MP_OBJ_SENTINEL
)
{
if
(
member
[
0
]
==
MP_OBJ_SENTINEL
)
{
// Handle Exception subclasses specially
if
(
mp_obj_is_native_exception_instance
(
self
->
subobj
[
0
]))
{
if
(
kind
!=
PRINT_STR
)
{
print
(
env
,
"%s"
,
qstr_str
(
self
->
base
.
type
->
name
));
}
mp_obj_print_helper
(
print
,
env
,
self
->
subobj
[
0
],
kind
|
PRINT_EXC_SUBCLASS
);
}
else
{
mp_obj_print_helper
(
print
,
env
,
self
->
subobj
[
0
],
kind
);
mp_obj_print_helper
(
print
,
env
,
self
->
subobj
[
0
],
kind
);
}
return
;
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/basics/subclass-native3.py
+
1
−
2
View file @
d8351ca8
...
@@ -3,6 +3,5 @@ class MyExc(Exception):
...
@@ -3,6 +3,5 @@ class MyExc(Exception):
e
=
MyExc
(
100
,
"
Some error
"
)
e
=
MyExc
(
100
,
"
Some error
"
)
print
(
e
)
print
(
e
)
# TODO: Prints native base class name
print
(
repr
(
e
))
#print(repr(e))
print
(
e
.
args
)
print
(
e
.
args
)
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