extmod: Use mp_raise_OSError helper function.

This commit is contained in:
Damien George 2016-10-07 13:52:14 +11:00
parent 06d0083468
commit 75af908c0e
5 changed files with 7 additions and 7 deletions

View File

@ -58,7 +58,7 @@ STATIC mp_obj_t machine_time_pulse_us_(size_t n_args, const mp_obj_t *args) {
} }
mp_uint_t us = machine_time_pulse_us(pin, level, timeout_us); mp_uint_t us = machine_time_pulse_us(pin, level, timeout_us);
if (us == (mp_uint_t)-1) { if (us == (mp_uint_t)-1) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ETIMEDOUT))); mp_raise_OSError(MP_ETIMEDOUT);
} }
return mp_obj_new_int(us); return mp_obj_new_int(us);
} }

View File

@ -58,7 +58,7 @@ STATIC const mp_obj_type_t btree_type;
#define CHECK_ERROR(res) \ #define CHECK_ERROR(res) \
if (res == RET_ERROR) { \ if (res == RET_ERROR) { \
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); \ mp_raise_OSError(errno); \
} }
void __dbpanic(DB *db) { void __dbpanic(DB *db) {
@ -370,7 +370,7 @@ STATIC mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t
DB *db = __bt_open(pos_args[0], &btree_stream_fvtable, &openinfo, /*dflags*/0); DB *db = __bt_open(pos_args[0], &btree_stream_fvtable, &openinfo, /*dflags*/0);
if (db == NULL) { if (db == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); mp_raise_OSError(errno);
} }
return MP_OBJ_FROM_PTR(btree_new(db)); return MP_OBJ_FROM_PTR(btree_new(db));
} }

View File

@ -56,7 +56,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, bool server_side) {
uint32_t options = SSL_SERVER_VERIFY_LATER; uint32_t options = SSL_SERVER_VERIFY_LATER;
if ((o->ssl_ctx = ssl_ctx_new(options, SSL_DEFAULT_CLNT_SESS)) == NULL) { if ((o->ssl_ctx = ssl_ctx_new(options, SSL_DEFAULT_CLNT_SESS)) == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL))); mp_raise_OSError(MP_EINVAL);
} }
if (server_side) { if (server_side) {
@ -69,7 +69,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, bool server_side) {
if ((res = ssl_handshake_status(o->ssl_sock)) != SSL_OK) { if ((res = ssl_handshake_status(o->ssl_sock)) != SSL_OK) {
printf("ssl_handshake_status: %d\n", res); printf("ssl_handshake_status: %d\n", res);
ssl_display_error(res); ssl_display_error(res);
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EIO))); mp_raise_OSError(MP_EIO);
} }
} }

View File

@ -179,7 +179,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
//assert(0); //assert(0);
printf("mbedtls_ssl_handshake error: -%x\n", -ret); printf("mbedtls_ssl_handshake error: -%x\n", -ret);
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EIO))); mp_raise_OSError(MP_EIO);
} }
} }
} }

View File

@ -59,7 +59,7 @@ STATIC unsigned char read_src_stream(TINF_DATA *data) {
byte c; byte c;
mp_uint_t out_sz = stream->read(self->src_stream, &c, 1, &err); mp_uint_t out_sz = stream->read(self->src_stream, &c, 1, &err);
if (out_sz == MP_STREAM_ERROR) { if (out_sz == MP_STREAM_ERROR) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(err))); mp_raise_OSError(err);
} }
if (out_sz == 0) { if (out_sz == 0) {
nlr_raise(mp_obj_new_exception(&mp_type_EOFError)); nlr_raise(mp_obj_new_exception(&mp_type_EOFError));