8000 unix: Use mp_raise_OSError helper function. · ladyada/circuitpython@503089e · GitHub
[go: up one dir, main page]

Skip to content

Commit 503089e

Browse files
committed
unix: Use mp_raise_OSError helper function.
1 parent 23a5682 commit 503089e

9 files changed

+18
-16
lines changed

unix/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ STATIC mp_obj_t fdfile_open(const mp_obj_type_t *type, mp_arg_val_t *args) {
203203
const char *fname = mp_obj_str_get_str(fid);
204204
int fd = open(fname, mode_x | mode_rw, 0644);
205205
if (fd == -1) {
206-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
206+
mp_raise_OSError(errno);
207207
}
208208
o->fd = fd;
209209
return MP_OBJ_FROM_PTR(o);

unix/modffi.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "py/nlr.h"
3636
#include "py/runtime.h"
3737
#include "py/binary.h"
38+
#include "py/mperrno.h"
3839

3940
/*
4041
* modffi uses character codes to encode a value type, based on "struct"
@@ -215,7 +216,7 @@ STATIC mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) {
215216

216217
void *sym = dlsym(self->handle, symname);
217218
if (sym == NULL) {
218-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT)));
219+
mp_raise_OSError(MP_ENOENT);
219220
}
220221
return make_func(args[1], sym, args[3]);
221222
}
@@ -278,7 +279,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna
278279

279280
void *sym = dlsym(self->handle, symname);
280281
if (sym == NULL) {
281-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT)));
282+
mp_raise_OSError(MP_ENOENT);
282283
}
283284
mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t);
284285
o->base.type = &ffivar_type;
@@ -295,7 +296,7 @@ STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) {
295296

296297
void *sym = dlsym(self->handle, symname);
297298
if (sym == NULL) {
298-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT)));
299+
mp_raise_OSError(MP_ENOENT);
299300
}
300301
return mp_obj_new_int((uintptr_t)sym);
301302
}
@@ -312,7 +313,7 @@ STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t
312313
void *mod = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
313314

314315
if (mod == NULL) {
315-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
316+
mp_raise_OSError(errno);
316317
}
317318
mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t);
318319
o->base.type = type;

unix/modmachine.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <stdio.h>
2828
#include <stdint.h>
2929

30-
#include "py/nlr.h"
30+
#include "py/runtime.h"
3131
#include "py/obj.h"
3232

3333
#include "extmod/machine_mem.h"
@@ -58,7 +58,7 @@ uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) {
5858
if (!fd) {
5959
fd = open("/dev/mem", O_RDWR | O_SYNC);
6060
if (fd == -1) {
61-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
61+
mp_raise_OSError(errno);
6262
}
6363
}
6464

unix/modos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern const mp_obj_type_t mp_fat_vfs_type;
5353

5454
#define RAISE_ERRNO(err_flag, error_val) \
5555
{ if (err_flag == -1) \
56-
{ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } }
56+
{ mp_raise_OSError(error_val); } }
5757

5858
STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
5959
struct stat sb;

unix/modsocket.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const mp_obj_type_t mp_type_socket;
7474
// Helper functions
7575
#define RAISE_ERRNO(err_flag, error_val) \
7676
{ if (err_flag == -1) \
77-
{ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } }
77+
{ mp_raise_OSError(error_val); } }
7878

7979
static inline mp_obj_t mp_obj_from_sockaddr(const struct sockaddr *addr, socklen_t len) {
8080
return mp_obj_new_bytes((const byte *)addr, len);
@@ -400,7 +400,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
400400
struct hostent *h = gethostbyname(s);
401401
if (h == NULL) {
402402
// CPython: socket.herror
403-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(h_errno)));
403+
mp_raise_OSError(h_errno);
404404
}
405405
assert(h->h_length == 4);
406406
return mp_obj_new_int(*(int*)*h->h_addr_list);
@@ -415,7 +415,7 @@ STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) {
415415
int r = inet_pton(family, mp_obj_str_get_str(addr_in), binaddr);
416416
RAISE_ERRNO(r, errno);
417417
if (r == 0) {
418-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL)));
418+
mp_raise_OSError(MP_EINVAL);
419419
}
420420
int binaddr_len = 0;
421421
switch (family) {
@@ -437,7 +437,7 @@ STATIC mp_obj_t mod_socket_inet_ntop(mp_obj_t family_in, mp_obj_t binaddr_in) {
437437
vstr_t vstr;
438438
vstr_init_len(&vstr, family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN);
439439
if (inet_ntop(family, bufinfo.buf, vstr.buf, vstr.len) == NULL) {
440-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
440+
mp_raise_OSError(errno);
441441
}
442442
vstr.len = strlen(vstr.buf);
443443
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);

unix/modtermios.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#define RAISE_ERRNO(err_flag, error_val) \
3737
{ if (err_flag == -1) \
38-
{ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } }
38+
{ mp_raise_OSError(error_val); } }
3939

4040
STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) {
4141
struct termios term;

unix/moduselect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <errno.h>
3434
#include <poll.h>
3535

36-
#include "py/nlr.h"
36+
#include "py/runtime.h"
3737
#include "py/obj.h"
3838
#include "py/objlist.h"
3939
#include "py/objtuple.h"

unix/mphalport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ static inline void mp_hal_delay_us(mp_uint_t us) { usleep(us); }
3939

4040
#define RAISE_ERRNO(err_flag, error_val) \
4141
{ if (err_flag == -1) \
42-
{ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } }
42+
{ mp_raise_OSError(error_val); } }

unix/mpthreadport.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <errno.h>
3030

3131
#include "py/mpstate.h"
32+
#include "py/runtime.h"
3233
#include "py/mpthread.h"
3334
#include "py/gc.h"
3435

@@ -182,7 +183,7 @@ void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
182183
return;
183184

184185
er:
185-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ret)));
186+
mp_raise_OSError(ret);
186187
}
187188

188189
void mp_thread_finish(void) {

0 commit comments

Comments
 (0)
0