Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
9512e9e8
Commit
9512e9e8
authored
Mar 25, 2014
by
Paul Sokolovsky
Browse files
objexcept: Add "args" exception attribute, as well as StopIteration.value.
parent
7f8b3134
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/objexcept.c
View file @
9512e9e8
...
@@ -53,16 +53,31 @@ STATIC mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, uint n_args, uint n_
...
@@ -53,16 +53,31 @@ STATIC mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, uint n_args, uint n_
o
->
base
.
type
=
type
;
o
->
base
.
type
=
type
;
o
->
traceback
=
MP_OBJ_NULL
;
o
->
traceback
=
MP_OBJ_NULL
;
o
->
msg
=
NULL
;
o
->
msg
=
NULL
;
o
->
args
.
base
.
type
=
&
tuple_type
;
o
->
args
.
len
=
n_args
;
o
->
args
.
len
=
n_args
;
memcpy
(
o
->
args
.
items
,
args
,
n_args
*
sizeof
(
mp_obj_t
));
memcpy
(
o
->
args
.
items
,
args
,
n_args
*
sizeof
(
mp_obj_t
));
return
o
;
return
o
;
}
}
STATIC
void
exception_load_attr
(
mp_obj_t
self_in
,
qstr
attr
,
mp_obj_t
*
dest
)
{
mp_obj_exception_t
*
self
=
self_in
;
if
(
attr
==
MP_QSTR_args
)
{
dest
[
0
]
=
&
self
->
args
;
}
else
if
(
self
->
base
.
type
==
&
mp_type_StopIteration
&&
attr
==
MP_QSTR_value
)
{
if
(
self
->
args
.
len
==
0
)
{
dest
[
0
]
=
mp_const_none
;
}
else
{
dest
[
0
]
=
self
->
args
.
items
[
0
];
}
}
}
const
mp_obj_type_t
mp_type_BaseException
=
{
const
mp_obj_type_t
mp_type_BaseException
=
{
{
&
mp_type_type
},
{
&
mp_type_type
},
.
name
=
MP_QSTR_BaseException
,
.
name
=
MP_QSTR_BaseException
,
.
print
=
mp_obj_exception_print
,
.
print
=
mp_obj_exception_print
,
.
make_new
=
mp_obj_exception_make_new
,
.
make_new
=
mp_obj_exception_make_new
,
.
load_attr
=
exception_load_attr
,
};
};
#define MP_DEFINE_EXCEPTION_BASE(base_name) \
#define MP_DEFINE_EXCEPTION_BASE(base_name) \
...
@@ -74,6 +89,7 @@ const mp_obj_type_t mp_type_ ## exc_name = { \
...
@@ -74,6 +89,7 @@ const mp_obj_type_t mp_type_ ## exc_name = { \
.name = MP_QSTR_ ## exc_name, \
.name = MP_QSTR_ ## exc_name, \
.print = mp_obj_exception_print, \
.print = mp_obj_exception_print, \
.make_new = mp_obj_exception_make_new, \
.make_new = mp_obj_exception_make_new, \
.load_attr = exception_load_attr, \
.bases_tuple = (mp_obj_t)&mp_type_ ## base_name ## _base_tuple, \
.bases_tuple = (mp_obj_t)&mp_type_ ## base_name ## _base_tuple, \
};
};
...
...
py/qstrdefs.h
View file @
9512e9e8
...
@@ -78,6 +78,7 @@ Q(NoneType)
...
@@ -78,6 +78,7 @@ Q(NoneType)
Q
(
abs
)
Q
(
abs
)
Q
(
all
)
Q
(
all
)
Q
(
any
)
Q
(
any
)
Q
(
args
)
Q
(
array
)
Q
(
array
)
Q
(
bool
)
Q
(
bool
)
Q
(
bytearray
)
Q
(
bytearray
)
...
@@ -123,6 +124,7 @@ Q(str)
...
@@ -123,6 +124,7 @@ Q(str)
Q
(
sys
)
Q
(
sys
)
Q
(
tuple
)
Q
(
tuple
)
Q
(
type
)
Q
(
type
)
Q
(
value
)
Q
(
zip
)
Q
(
zip
)
Q
(
append
)
Q
(
append
)
...
...
tests/basics/exception1.py
View file @
9512e9e8
...
@@ -7,3 +7,9 @@ print(str(IndexError("foo")))
...
@@ -7,3 +7,9 @@ print(str(IndexError("foo")))
a
=
IndexError
(
1
,
"test"
,
[
100
,
200
])
a
=
IndexError
(
1
,
"test"
,
[
100
,
200
])
print
(
repr
(
a
))
print
(
repr
(
a
))
print
(
str
(
a
))
print
(
str
(
a
))
print
(
a
.
args
)
s
=
StopIteration
()
print
(
s
.
value
)
s
=
StopIteration
(
1
,
2
,
3
)
print
(
s
.
value
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment