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
48d867b4
Commit
48d867b4
authored
Jun 15, 2017
by
Damien George
Browse files
all: Make more use of mp_raise_{msg,TypeError,ValueError} helpers.
parent
1e70fda6
Changes
17
Hide whitespace changes
Inline
Side-by-side
esp8266/machine_uart.c
View file @
48d867b4
...
...
@@ -104,7 +104,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
self
->
bits
=
8
;
break
;
default:
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"invalid data bits"
)
)
;
mp_rais
e_ValueError
(
"invalid data bits"
);
break
;
}
...
...
@@ -140,7 +140,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
self
->
stop
=
2
;
break
;
default:
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"invalid stop bits"
)
)
;
mp_rais
e_ValueError
(
"invalid stop bits"
);
break
;
}
...
...
@@ -215,7 +215,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
pyb_uart_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
if
(
self
->
uart_id
==
1
)
{
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_OSError
,
"UART(1) can't read"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_OSError
,
"UART(1) can't read"
);
}
// make sure we want at least 1 char
...
...
extmod/modframebuf.c
View file @
48d867b4
...
...
@@ -244,8 +244,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
o
->
stride
=
(
o
->
stride
+
7
)
&
~
7
;
break
;
default:
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"invalid format"
));
mp_raise_ValueError
(
"invalid format"
);
}
return
MP_OBJ_FROM_PTR
(
o
);
...
...
extmod/modubinascii.c
View file @
48d867b4
...
...
@@ -75,7 +75,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
mp_get_buffer_raise
(
data
,
&
bufinfo
,
MP_BUFFER_READ
);
if
((
bufinfo
.
len
&
1
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"odd-length string"
)
)
;
mp_rais
e_ValueError
(
"odd-length string"
);
}
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
bufinfo
.
len
/
2
);
...
...
@@ -86,7 +86,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
if
(
unichar_isxdigit
(
hex_ch
))
{
hex_byte
+=
unichar_xdigit_value
(
hex_ch
);
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"non-hex digit found"
)
)
;
mp_rais
e_ValueError
(
"non-hex digit found"
);
}
if
(
i
&
1
)
{
hex_byte
<<=
4
;
...
...
py/builtinimport.c
View file @
48d867b4
...
...
@@ -230,8 +230,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
#endif
// If we get here then the file was not frozen and we can't compile scripts.
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ImportError
,
"script compilation not supported"
));
mp_raise_msg
(
&
mp_type_ImportError
,
"script compilation not supported"
);
}
STATIC
void
chop_component
(
const
char
*
start
,
const
char
**
end
)
{
...
...
py/modbuiltins.c
View file @
48d867b4
...
...
@@ -398,8 +398,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
#endif
if
(
MICROPY_ERROR_REPORTING
==
MICROPY_ERROR_REPORTING_TERSE
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"ord expects a character"
));
mp_raise_TypeError
(
"ord expects a character"
);
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"ord() expected a character, but string of length %d found"
,
(
int
)
len
));
...
...
py/modmath.c
View file @
48d867b4
...
...
@@ -25,7 +25,7 @@
*/
#include
"py/builtin.h"
#include
"py/
nlr
.h"
#include
"py/
runtime
.h"
#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH
...
...
@@ -41,7 +41,7 @@
/// working with floating-point numbers.
STATIC
NORETURN
void
math_error
(
void
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"math domain error"
)
)
;
mp_rais
e_ValueError
(
"math domain error"
);
}
#define MATH_FUN_1(py_name, c_name) \
...
...
py/obj.c
View file @
48d867b4
...
...
@@ -460,8 +460,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
}
}
else
if
(
value
==
MP_OBJ_SENTINEL
)
{
if
(
MICROPY_ERROR_REPORTING
==
MICROPY_ERROR_REPORTING_TERSE
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"object is not subscriptable"
));
mp_raise_TypeError
(
"object is not subscriptable"
);
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"'%s' object is not subscriptable"
,
mp_obj_get_type_str
(
base
)));
...
...
py/objcomplex.c
View file @
48d867b4
...
...
@@ -196,7 +196,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
}
case
MP_BINARY_OP_FLOOR_DIVIDE
:
case
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE
:
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_TypeError
,
"can't do truncated division of a complex number"
)
)
;
mp_rais
e_TypeError
(
"can't do truncated division of a complex number"
);
case
MP_BINARY_OP_TRUE_DIVIDE
:
case
MP_BINARY_OP_INPLACE_TRUE_DIVIDE
:
...
...
py/objint_longlong.c
View file @
48d867b4
...
...
@@ -247,7 +247,7 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) {
mp_obj_t
mp_obj_new_int_from_ull
(
unsigned
long
long
val
)
{
// TODO raise an exception if the unsigned long long won't fit
if
(
val
>>
(
sizeof
(
unsigned
long
long
)
*
8
-
1
)
!=
0
)
{
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_OverflowError
,
"ulonglong too large"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_OverflowError
,
"ulonglong too large"
);
}
mp_obj_int_t
*
o
=
m_new_obj
(
mp_obj_int_t
);
o
->
base
.
type
=
&
mp_type_int
;
...
...
py/objstrunicode.c
View file @
48d867b4
...
...
@@ -142,7 +142,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if
(
is_slice
)
{
return
self_data
;
}
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_IndexError
,
"string index out of range"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_IndexError
,
"string index out of range"
);
}
if
(
!
UTF8_IS_CONT
(
*
s
))
{
++
i
;
...
...
@@ -161,7 +161,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if
(
is_slice
)
{
return
top
;
}
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_IndexError
,
"string index out of range"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_IndexError
,
"string index out of range"
);
}
// Then check completion
if
(
i
--
==
0
)
{
...
...
py/stream.c
View file @
48d867b4
...
...
@@ -142,7 +142,7 @@ STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte fl
while
(
more_bytes
>
0
)
{
char
*
p
=
vstr_add_len
(
&
vstr
,
more_bytes
);
if
(
p
==
NULL
)
{
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_MemoryError
,
"out of memory"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_MemoryError
,
"out of memory"
);
}
int
error
;
mp_uint_t
out_sz
=
mp_stream_read_exactly
(
args
[
0
],
p
,
more_bytes
,
&
error
);
...
...
@@ -381,7 +381,7 @@ STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args)
while
(
max_size
==
-
1
||
max_size
--
!=
0
)
{
char
*
p
=
vstr_add_len
(
&
vstr
,
1
);
if
(
p
==
NULL
)
{
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_MemoryError
,
"out of memory"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_MemoryError
,
"out of memory"
);
}
int
error
;
...
...
stmhal/accel.c
View file @
48d867b4
...
...
@@ -90,7 +90,7 @@ STATIC void accel_start(void) {
}
if
(
status
!=
HAL_OK
)
{
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_OSError
,
"accelerometer not found"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_OSError
,
"accelerometer not found"
);
}
// set MMA to active mode
...
...
stmhal/can.c
View file @
48d867b4
...
...
@@ -473,7 +473,7 @@ STATIC mp_obj_t pyb_can_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
pyb_buf_get_for_send
(
args
[
0
].
u_obj
,
&
bufinfo
,
data
);
if
(
bufinfo
.
len
>
8
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"CAN data field too long"
)
)
;
mp_rais
e_ValueError
(
"CAN data field too long"
);
}
// send the data
...
...
@@ -738,7 +738,7 @@ STATIC mp_obj_t pyb_can_setfilter(mp_uint_t n_args, const mp_obj_t *pos_args, mp
return
mp_const_none
;
error:
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"CAN filter parameter error"
)
)
;
mp_rais
e_ValueError
(
"CAN filter parameter error"
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_can_setfilter_obj
,
1
,
pyb_can_setfilter
);
...
...
stmhal/dac.c
View file @
48d867b4
...
...
@@ -189,7 +189,7 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, mp_uint_t n_args, const
if
(
args
[
0
].
u_int
==
8
||
args
[
0
].
u_int
==
12
)
{
self
->
bits
=
args
[
0
].
u_int
;
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"unsupported bits"
)
)
;
mp_rais
e_ValueError
(
"unsupported bits"
);
}
// reset state of DAC
...
...
stmhal/uart.c
View file @
48d867b4
...
...
@@ -597,7 +597,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
}
else
if
(
bits
==
9
)
{
init
->
WordLength
=
UART_WORDLENGTH_9B
;
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"unsupported combination of bits and parity"
)
)
;
mp_rais
e_ValueError
(
"unsupported combination of bits and parity"
);
}
// stop bits
...
...
unix/modffi.c
View file @
48d867b4
...
...
@@ -134,7 +134,7 @@ STATIC ffi_type *get_ffi_type(mp_obj_t o_in)
}
// TODO: Support actual libffi type objects
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_TypeError
,
"Unknown type"
)
)
;
mp_rais
e_TypeError
(
"Unknown type"
);
}
STATIC
mp_obj_t
return_ffi_value
(
ffi_arg
val
,
char
type
)
...
...
@@ -203,7 +203,7 @@ STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in)
int
res
=
ffi_prep_cif
(
&
o
->
cif
,
FFI_DEFAULT_ABI
,
nparams
,
char2ffi_type
(
*
rettype
),
o
->
params
);
if
(
res
!=
FFI_OK
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"Error in ffi_prep_cif"
)
)
;
mp_rais
e_ValueError
(
"Error in ffi_prep_cif"
);
}
return
MP_OBJ_FROM_PTR
(
o
);
...
...
@@ -261,12 +261,12 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t
int
res
=
ffi_prep_cif
(
&
o
->
cif
,
FFI_DEFAULT_ABI
,
nparams
,
char2ffi_type
(
*
rettype
),
o
->
params
);
if
(
res
!=
FFI_OK
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"Error in ffi_prep_cif"
)
)
;
mp_rais
e_ValueError
(
"Error in ffi_prep_cif"
);
}
res
=
ffi_prep_closure_loc
(
o
->
clo
,
&
o
->
cif
,
call_py_func
,
MP_OBJ_TO_PTR
(
func_in
),
o
->
func
);
if
(
res
!=
FFI_OK
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_ValueError
,
"ffi_prep_closure_loc"
)
)
;
mp_rais
e_ValueError
(
"ffi_prep_closure_loc"
);
}
return
MP_OBJ_FROM_PTR
(
o
);
...
...
unix/modjni.c
View file @
48d867b4
...
...
@@ -159,7 +159,7 @@ STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
STATIC
mp_obj_t
jclass_call
(
mp_obj_t
self_in
,
size_t
n_args
,
size_t
n_kw
,
const
mp_obj_t
*
args
)
{
if
(
n_kw
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_TypeError
,
"kwargs not supported"
)
)
;
mp_rais
e_TypeError
(
"kwargs not supported"
);
}
mp_obj_jclass_t
*
self
=
self_in
;
...
...
@@ -433,7 +433,7 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) {
}
out
->
l
=
NULL
;
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_TypeError
,
"arg type not supported"
)
)
;
mp_rais
e_TypeError
(
"arg type not supported"
);
}
*
jtypesig
=
arg_type
;
...
...
@@ -534,7 +534,7 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool
ret
=
new_jobject
(
res
);
}
else
{
JJ
(
ReleaseStringUTFChars
,
name_o
,
decl
);
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_TypeError
,
"cannot handle return type"
)
)
;
mp_rais
e_TypeError
(
"cannot handle return type"
);
}
JJ
(
ReleaseStringUTFChars
,
name_o
,
decl
);
...
...
@@ -550,13 +550,13 @@ next_method:
JJ
(
DeleteLocalRef
,
meth
);
}
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_TypeError
,
"method not found"
)
)
;
mp_rais
e_TypeError
(
"method not found"
);
}
STATIC
mp_obj_t
jmethod_call
(
mp_obj_t
self_in
,
size_t
n_args
,
size_t
n_kw
,
const
mp_obj_t
*
args
)
{
if
(
n_kw
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_typ
e_TypeError
,
"kwargs not supported"
)
)
;
mp_rais
e_TypeError
(
"kwargs not supported"
);
}
mp_obj_jmethod_t
*
self
=
self_in
;
...
...
@@ -602,13 +602,13 @@ STATIC void create_jvm() {
void
*
libjvm
=
dlopen
(
LIBJVM_SO
,
RTLD_NOW
|
RTLD_GLOBAL
);
if
(
!
libjvm
)
{
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_OSError
,
"unable to load libjvm.so, use LD_LIBRARY_PATH"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_OSError
,
"unable to load libjvm.so, use LD_LIBRARY_PATH"
);
}
int
(
*
_JNI_CreateJavaVM
)(
void
*
,
void
**
,
void
*
)
=
dlsym
(
libjvm
,
"JNI_CreateJavaVM"
);
int
st
=
_JNI_CreateJavaVM
(
&
jvm
,
(
void
**
)
&
env
,
&
args
);
if
(
st
<
0
||
!
env
)
{
nlr
_raise
(
mp_obj_new_exception_msg_var
g
(
&
mp_type_OSError
,
"unable to create JVM"
)
)
;
mp
_raise
_ms
g
(
&
mp_type_OSError
,
"unable to create JVM"
);
}
Class_class
=
JJ
(
FindClass
,
"java/lang/Class"
);
...
...
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