From fa6f0506c1380d0d96ca7bb5d30d89259a235102 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 22 Apr 2014 00:16:46 +0300 Subject: [PATCH] unix: Workaround MP_OBJ_NEW_SMALL_INT() 64-bit issues. --- unix/file.c | 2 +- unix/modffi.c | 6 +++--- unix/modsocket.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/unix/file.c b/unix/file.c index 5c33bc5900..041e28e956 100644 --- a/unix/file.c +++ b/unix/file.c @@ -106,7 +106,7 @@ STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const int fd = open(fname, mode, 0644); if (fd == -1) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); } return fdfile_new(fd); } diff --git a/unix/modffi.c b/unix/modffi.c index f00b90f879..56ea6ed307 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -145,7 +145,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) { void *sym = dlsym(self->handle, symname); if (sym == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); } int nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[3])); mp_obj_ffifunc_t *o = m_new_obj_var(mp_obj_ffifunc_t, ffi_type*, nparams); @@ -219,7 +219,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna void *sym = dlsym(self->handle, symname); if (sym == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); } mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t); o->base.type = &ffivar_type; @@ -235,7 +235,7 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const void *mod = dlopen(fname, RTLD_NOW | RTLD_LOCAL); if (mod == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); } mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t); o->base.type = type_in; diff --git a/unix/modsocket.c b/unix/modsocket.c index 567bf5c9ba..b7d167c8ad 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -33,7 +33,7 @@ STATIC const mp_obj_type_t microsocket_type; // Helper functions #define RAISE_ERRNO(err_flag, error_val) \ { if (err_flag == -1) \ - { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } } + { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)error_val))); } } STATIC mp_obj_socket_t *socket_new(int fd) { mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t); @@ -283,7 +283,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { struct hostent *h = gethostbyname(s); if (h == NULL) { // CPython: socket.herror - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(h_errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)h_errno))); } assert(h->h_length == 4); return mp_obj_new_int(*(int*)*h->h_addr_list);