diff options
Diffstat (limited to 'unix')
-rw-r--r-- | unix/Makefile | 6 | ||||
-rw-r--r-- | unix/coverage.c | 2 | ||||
-rw-r--r-- | unix/file.c | 2 | ||||
-rw-r--r-- | unix/modffi.c | 10 | ||||
-rw-r--r-- | unix/modjni.c | 78 | ||||
-rw-r--r-- | unix/modmachine.c | 5 | ||||
-rw-r--r-- | unix/modos.c | 6 | ||||
-rw-r--r-- | unix/modsocket.c | 12 | ||||
-rw-r--r-- | unix/modtermios.c | 7 | ||||
-rw-r--r-- | unix/modtime.c | 1 | ||||
-rw-r--r-- | unix/moduselect.c | 11 | ||||
-rw-r--r-- | unix/mpconfigport.mk | 1 | ||||
-rw-r--r-- | unix/mphalport.h | 2 | ||||
-rw-r--r-- | unix/mpthreadport.c | 3 |
14 files changed, 105 insertions, 41 deletions
diff --git a/unix/Makefile b/unix/Makefile index 956b1daef3..53ff4cb487 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -262,10 +262,8 @@ freedos: MICROPY_PY_JNI=0 # build an interpreter for coverage testing and do the testing -# btree module is disabled, because with extra warnings enabled, -# building berkeleydb errors out coverage: - $(MAKE) COPT="-O0" MICROPY_PY_BTREE=0 CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_coverage.h>" -fprofile-arcs -ftest-coverage -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -Wpointer-arith -Wshadow -Wsign-compare -Wuninitialized -Wunused-parameter -DMICROPY_UNIX_COVERAGE' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage + $(MAKE) COPT="-O0" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_coverage.h>" -fprofile-arcs -ftest-coverage -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -Wpointer-arith -Wshadow -Wsign-compare -Wuninitialized -Wunused-parameter -DMICROPY_UNIX_COVERAGE' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage coverage_test: coverage $(eval DIRNAME=$(notdir $(CURDIR))) @@ -275,7 +273,7 @@ coverage_test: coverage gcov -o build-coverage/extmod ../extmod/*.c $(BUILD)/_frozen_upip.c: $(BUILD)/frozen_upip/upip.py - ../tools/make-frozen.py $(dir $^) > $@ + $(MAKE_FROZEN) $(dir $^) > $@ # Select latest upip version available UPIP_TARBALL := $(shell ls -1 -v ../tools/micropython-upip-*.tar.gz | tail -n1) diff --git a/unix/coverage.c b/unix/coverage.c index c84a653f75..6a1b43fdce 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -34,7 +34,7 @@ STATIC mp_obj_t extra_coverage(void) { // vstr { mp_printf(&mp_plat_print, "# vstr\n"); - vstr_t *vstr = vstr_new_size(16); + vstr_t *vstr = vstr_new(16); vstr_hint_size(vstr, 32); vstr_add_str(vstr, "ts"); vstr_ins_byte(vstr, 1, 'e'); diff --git a/unix/file.c b/unix/file.c index 203a5a3abe..6d59a736ce 100644 --- a/unix/file.c +++ b/unix/file.c @@ -203,7 +203,7 @@ STATIC mp_obj_t fdfile_open(const mp_obj_type_t *type, mp_arg_val_t *args) { const char *fname = mp_obj_str_get_str(fid); int fd = open(fname, mode_x | mode_rw, 0644); if (fd == -1) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); + mp_raise_OSError(errno); } o->fd = fd; return MP_OBJ_FROM_PTR(o); diff --git a/unix/modffi.c b/unix/modffi.c index ba7141d242..cae16c579a 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -35,6 +35,7 @@ #include "py/nlr.h" #include "py/runtime.h" #include "py/binary.h" +#include "py/mperrno.h" /* * 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) { void *sym = dlsym(self->handle, symname); if (sym == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT))); + mp_raise_OSError(MP_ENOENT); } return make_func(args[1], sym, args[3]); } @@ -278,7 +279,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(ENOENT))); + mp_raise_OSError(MP_ENOENT); } mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t); 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) { void *sym = dlsym(self->handle, symname); if (sym == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT))); + mp_raise_OSError(MP_ENOENT); } return mp_obj_new_int((uintptr_t)sym); } @@ -312,7 +313,7 @@ STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t 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))); + mp_raise_OSError(errno); } mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t); o->base.type = type; @@ -499,6 +500,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ffi_globals, mp_module_ffi_globals_table); const mp_obj_module_t mp_module_ffi = { .base = { &mp_type_module }, - .name = MP_QSTR_ffi, .globals = (mp_obj_dict_t*)&mp_module_ffi_globals, }; diff --git a/unix/modjni.c b/unix/modjni.c index 20804e5a54..b54da8b15a 100644 --- a/unix/modjni.c +++ b/unix/modjni.c @@ -65,6 +65,7 @@ STATIC const mp_obj_type_t jmethod_type; STATIC mp_obj_t new_jobject(jobject jo); STATIC mp_obj_t new_jclass(jclass jc); STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, mp_uint_t n_args, const mp_obj_t *args); +STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out); typedef struct _mp_obj_jclass_t { mp_obj_base_t base; @@ -244,11 +245,36 @@ STATIC void get_jclass_name(jobject obj, char *buf) { STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_jobject_t *self = self_in; + mp_uint_t idx = mp_obj_get_int(index); + char class_name[64]; + get_jclass_name(self->obj, class_name); + //printf("class: %s\n", class_name); + + if (class_name[0] == '[') { + if (class_name[1] == 'L' || class_name[1] == '[') { + if (value == MP_OBJ_NULL) { + // delete + assert(0); + } else if (value == MP_OBJ_SENTINEL) { + // load + jobject el = JJ(GetObjectArrayElement, self->obj, idx); + return new_jobject(el); + } else { + // store + jvalue jval; + const char *t = class_name + 1; + py2jvalue(&t, value, &jval); + JJ(SetObjectArrayElement, self->obj, idx, jval.l); + return mp_const_none; + } + } + mp_not_implemented(""); + } + if (!JJ(IsInstanceOf, self->obj, List_class)) { return MP_OBJ_NULL; } - mp_uint_t idx = mp_obj_get_int(index); if (value == MP_OBJ_NULL) { // delete @@ -628,6 +654,54 @@ STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls); +STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { + if (!env) { + create_jvm(); + } + mp_int_t size = mp_obj_get_int(size_in); + jobject res = NULL; + + if (MP_OBJ_IS_TYPE(type_in, &jclass_type)) { + + mp_obj_jclass_t *jcls = type_in; + res = JJ(NewObjectArray, size, jcls->cls, NULL); + + } else if (MP_OBJ_IS_STR(type_in)) { + const char *type = mp_obj_str_get_str(type_in); + switch (*type) { + case 'Z': + res = JJ(NewBooleanArray, size); + break; + case 'B': + res = JJ(NewByteArray, size); + break; + case 'C': + res = JJ(NewCharArray, size); + break; + case 'S': + res = JJ(NewShortArray, size); + break; + case 'I': + res = JJ(NewIntArray, size); + break; + case 'J': + res = JJ(NewLongArray, size); + break; + case 'F': + res = JJ(NewFloatArray, size); + break; + case 'D': + res = JJ(NewDoubleArray, size); + break; + } + + } + + return new_jobject(res); +} +MP_DEFINE_CONST_FUN_OBJ_2(mod_jni_array_obj, mod_jni_array); + + STATIC mp_obj_t mod_jni_env() { return mp_obj_new_int((mp_int_t)env); } @@ -636,6 +710,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(mod_jni_env_obj, mod_jni_env); STATIC const mp_map_elem_t mp_module_jni_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_jni) }, { MP_OBJ_NEW_QSTR(MP_QSTR_cls), (mp_obj_t)&mod_jni_cls_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mod_jni_array_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_env), (mp_obj_t)&mod_jni_env_obj }, }; @@ -643,6 +718,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table); const mp_obj_module_t mp_module_jni = { .base = { &mp_type_module }, - .name = MP_QSTR_jni, .globals = (mp_obj_dict_t*)&mp_module_jni_globals, }; diff --git a/unix/modmachine.c b/unix/modmachine.c index 166d47712d..e5f9ec8d70 100644 --- a/unix/modmachine.c +++ b/unix/modmachine.c @@ -27,7 +27,7 @@ #include <stdio.h> #include <stdint.h> -#include "py/nlr.h" +#include "py/runtime.h" #include "py/obj.h" #include "extmod/machine_mem.h" @@ -58,7 +58,7 @@ uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) { if (!fd) { fd = open("/dev/mem", O_RDWR | O_SYNC); if (fd == -1) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); + mp_raise_OSError(errno); } } @@ -91,7 +91,6 @@ STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table const mp_obj_module_t mp_module_machine = { .base = { &mp_type_module }, - .name = MP_QSTR_umachine, .globals = (mp_obj_dict_t*)&machine_module_globals, }; diff --git a/unix/modos.c b/unix/modos.c index 0e699ec1d6..36945720d1 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -37,6 +37,7 @@ #include "py/nlr.h" #include "py/runtime.h" #include "py/objtuple.h" +#include "py/mphal.h" #include "extmod/misc.h" // Can't include this, as FATFS structure definition is required, @@ -51,10 +52,6 @@ extern const mp_obj_type_t mp_fat_vfs_type; #define USE_STATFS 1 #endif -#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))); } } - STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) { struct stat sb; mp_uint_t len; @@ -253,6 +250,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table); const mp_obj_module_t mp_module_os = { .base = { &mp_type_module }, - .name = MP_QSTR_uos, .globals = (mp_obj_dict_t*)&mp_module_os_globals, }; diff --git a/unix/modsocket.c b/unix/modsocket.c index 56bab3494a..74d22eb731 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -44,6 +44,7 @@ #include "py/runtime.h" #include "py/stream.h" #include "py/builtin.h" +#include "py/mphal.h" /* The idea of this module is to implement reasonable minimum of @@ -72,10 +73,6 @@ typedef struct _mp_obj_socket_t { const mp_obj_type_t mp_type_socket; // 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))); } } - static inline mp_obj_t mp_obj_from_sockaddr(const struct sockaddr *addr, socklen_t len) { return mp_obj_new_bytes((const byte *)addr, len); } @@ -400,7 +397,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))); + mp_raise_OSError(h_errno); } assert(h->h_length == 4); return mp_obj_new_int(*(int*)*h->h_addr_list); @@ -415,7 +412,7 @@ STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) { int r = inet_pton(family, mp_obj_str_get_str(addr_in), binaddr); RAISE_ERRNO(r, errno); if (r == 0) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL))); + mp_raise_OSError(MP_EINVAL); } int binaddr_len = 0; switch (family) { @@ -437,7 +434,7 @@ STATIC mp_obj_t mod_socket_inet_ntop(mp_obj_t family_in, mp_obj_t binaddr_in) { vstr_t vstr; vstr_init_len(&vstr, family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN); if (inet_ntop(family, bufinfo.buf, vstr.buf, vstr.len) == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); + mp_raise_OSError(errno); } vstr.len = strlen(vstr.buf); return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); @@ -586,6 +583,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_t const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, - .name = MP_QSTR_usocket, .globals = (mp_obj_dict_t*)&mp_module_socket_globals, }; diff --git a/unix/modtermios.c b/unix/modtermios.c index 38be729e22..2cb5f26df5 100644 --- a/unix/modtermios.c +++ b/unix/modtermios.c @@ -29,13 +29,9 @@ #include <unistd.h> #include <errno.h> -#include "py/nlr.h" #include "py/objlist.h" #include "py/runtime.h" - -#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))); } } +#include "py/mphal.h" STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { struct termios term; @@ -151,6 +147,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_termios_globals, mp_module_termios_globals const mp_obj_module_t mp_module_termios = { .base = { &mp_type_module }, - .name = MP_QSTR_termios, .globals = (mp_obj_dict_t*)&mp_module_termios_globals, }; diff --git a/unix/modtime.c b/unix/modtime.c index 6843238cf3..8d6d9f4d7e 100644 --- a/unix/modtime.c +++ b/unix/modtime.c @@ -198,7 +198,6 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table const mp_obj_module_t mp_module_time = { .base = { &mp_type_module }, - .name = MP_QSTR_utime, .globals = (mp_obj_dict_t*)&mp_module_time_globals, }; diff --git a/unix/moduselect.c b/unix/moduselect.c index 38f8d11ed8..4a6973c0d5 100644 --- a/unix/moduselect.c +++ b/unix/moduselect.c @@ -33,14 +33,16 @@ #include <errno.h> #include <poll.h> -#include "py/nlr.h" +#include "py/runtime.h" #include "py/obj.h" #include "py/objlist.h" #include "py/objtuple.h" #include "py/mphal.h" #include "fdfile.h" +#if MICROPY_PY_SOCKET extern const mp_obj_type_t mp_type_socket; +#endif // Flags for poll() #define FLAG_ONESHOT (1) @@ -57,7 +59,11 @@ typedef struct _mp_obj_poll_t { STATIC int get_fd(mp_obj_t fdlike) { int fd; // Shortcut for fdfile compatible types - if (MP_OBJ_IS_TYPE(fdlike, &mp_type_fileio) || MP_OBJ_IS_TYPE(fdlike, &mp_type_socket)) { + if (MP_OBJ_IS_TYPE(fdlike, &mp_type_fileio) + #if MICROPY_PY_SOCKET + || MP_OBJ_IS_TYPE(fdlike, &mp_type_socket) + #endif + ) { mp_obj_fdfile_t *fdfile = MP_OBJ_TO_PTR(fdlike); fd = fdfile->fd; } else { @@ -229,7 +235,6 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_t const mp_obj_module_t mp_module_uselect = { .base = { &mp_type_module }, - .name = MP_QSTR_uselect, .globals = (mp_obj_dict_t*)&mp_module_select_globals, }; diff --git a/unix/mpconfigport.mk b/unix/mpconfigport.mk index f7912141af..3b335ae78e 100644 --- a/unix/mpconfigport.mk +++ b/unix/mpconfigport.mk @@ -29,6 +29,7 @@ MICROPY_PY_FFI = 1 # ussl module requires axtls MICROPY_PY_USSL = 1 MICROPY_SSL_AXTLS = 1 +MICROPY_SSL_MBEDTLS = 0 # jni module requires JVM/JNI MICROPY_PY_JNI = 0 diff --git a/unix/mphalport.h b/unix/mphalport.h index 2a775d9828..e440eafd4e 100644 --- a/unix/mphalport.h +++ b/unix/mphalport.h @@ -39,4 +39,4 @@ static inline void mp_hal_delay_us(mp_uint_t us) { usleep(us); } #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))); } } + { mp_raise_OSError(error_val); } } diff --git a/unix/mpthreadport.c b/unix/mpthreadport.c index 663d3a5dee..09f5702e38 100644 --- a/unix/mpthreadport.c +++ b/unix/mpthreadport.c @@ -29,6 +29,7 @@ #include <errno.h> #include "py/mpstate.h" +#include "py/runtime.h" #include "py/mpthread.h" #include "py/gc.h" @@ -182,7 +183,7 @@ void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) { return; er: - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ret))); + mp_raise_OSError(ret); } void mp_thread_finish(void) { |