summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-08-14 12:47:47 +1000
committerDamien George <damien.p.george@gmail.com>2017-08-14 12:47:47 +1000
commitf6e6776d6f8233432615f1ef438cbd1447c51aac (patch)
tree34589f98ab4d89914025b7d4ee10d2801cd80b3d /unix
parentd9d9b0a3005a810543724622374cc26a5399bd0e (diff)
parentc8d31585a00616b39839d112b7c696dafed6b08d (diff)
downloadmicropython-f6e6776d6f8233432615f1ef438cbd1447c51aac.tar.gz
micropython-f6e6776d6f8233432615f1ef438cbd1447c51aac.zip
Merge tag 'v1.8.5' into parse-bytecode
New port to Zephyr, upip runs on baremetal, and reduction in code size This release adds a new port of MicroPython to run on top of the Zephyr real-time operating system. As part of this there is now basic support for using mbedTLS as the ussl module. The release also brings initial support for running the package manager upip on baremetal systems with low heap memory (such as esp8266), through a Python module interface. Work has been done in this release to clean up the core, removing redundant and/or unreachable code, and factoring existing duplicated code patterns. This brings a reduction of 828 bytes in code size to the bare-arm port, and 1368 bytes to the minimal port. There is also improved coverage through the addition of new tests for corner cases. The "micropython" module sees the addition of the "const" identity function which should be used as "from micropython import const" in scripts that want to use the MicroPython constant optimisations in the compile stage. There is also the addition of the "opt_level" function to change the parser/compiler optimisation level at runtime. The behaviour of "sys.exit" (and "raise SystemExit") on baremetal is now changed: this function no longer does a soft-reset of the board, rather it just stops the running script and drops to the REPL. In order to do an actual soft reset the "machine.soft_reset" function has been added (to the stmhal port only, for the time being). Following CPython, KeyError exceptions for dictionary lookups now have the failed key stored as the argument of the exception instance, accessible as exc.args[0]. The "ujson.load" function has also been added, to load JSON data from an arbitrary stream. The I2C support in the machine module now has clock stretching, the addition of the "addrsize" parameter in memory transfer methods, and I2C scanning now uses dummy writes instead of dummy reads to make the scanning more reliable. The CMSIS library has been upgrade to v4.30, and the boards section of the stmhal port has been refactored to use a common.ld script. The stmhal port now has a full implementation of the machine.SPI class, with support for both hardware SPI peripherals and fast software SPI. The USB HID driver in stmhal has added support to receive USB HID messages from the host. py core: - asmthumb: flush D-cache, and invalidate I-cache on STM32F7 - makeqstrdefs.py: use python 2.6 syntax for set creation - objnone: remove unnecessary handling of MP_UNARY_OP_BOOL - move frozen modules rules from esp8266 port for reuse across ports - combine 3 comprehension emit functions (list/dict/set) into 1 - combine 3 comprehension opcodes (list/dict/set) into 1 - vstr: remove vstr.had_error flag and inline basic vstr functions - objnone: use mp_generic_unary_op instead of custom one - showbc: make printf's go to the platform print stream - remove 'name' member from mp_obj_module_t struct - builtinimport: fix nanbox build after change to better handle -m modules - stream: remove unnecessary check for NULL return from vstr_extend - py.mk: suppress some compiler warnings when building berkeley-db - shrink mp_arg_t struct by using reduced-size integer members - update opcode format table because 3 opcodes were removed, 1 added - parse: only replace constants that are standalone identifiers - py.mk: add support for building modussl_mbedtls - only store the exception instance on Py stack in bytecode try block - vm: use MP_OBJ_FROM_PTR to cast a type to an object - modmicropython: add micropython.const, alias for identity function - objstr: remove unreachable function used only for terse error msgs - emitbc: remove/refactor unreachable code, to improve coverage - objfun: remove unnecessary check for viper fun with 5 or more args - objfun: use if instead of switch to check return value of VM execute - objset: use mp_check_self() to check args of set/frozenset methods - objset: ensure that use of frozenset.update raises an exception - compile: fix async-for/async-with to work with simpler exc on stack - scope: use lookup-table to determine a scope's simple name - scope: shrink scope_t struct by 1 machine word - scope: factor common code to find locals and close over them - compile: fix typo when checking for parse-node kind - argcheck: simplify if-chain so that the last one is the default - objbool: defer bool's unary op implementation to small int - objbool: make a slight simplification of bool constructor - modstruct: remove unreachable code, and add comment about CPy diff - add mp_raise_OSError(errno) helper function - objstringio: add readinto() method - modmicropython: add micropython.opt_level([value]) function - compile: remove unreachable code - mpz: in divmod, replace check for rhs!=0 with assert - mpz: use assert to verify mpz does not have a fixed digit buffer - factor duplicated function to calculate size of formatted int - objint: use size_t for arguments that measure bytes/sizes - compile: remove debugging code for compiler dispatch - lexer: remove unnecessary code, and unreachable code - vstr: combine vstr_new_size with vstr_new since they are rarely used - objdict: fix optimisation for allocating result in fromkeys - objdict: actually provide the key that failed in KeyError exception - use mp_raise_msg helper function where appropriate - add the module specified by -m to sys.modules as '__main__' extmod: - modussl_mbedtls: initial implementation of mbedTLS ussl module - uctypes: allow full 32-bit address range - modubinascii: fix crc32() function on 32-bit platforms - modussl_mbedtls: implement key= and cert= args to wrap_socket() - modussl_mbedtls: use 2-component include paths - machine_i2c: add clock stretching support - modussl_mbedtls: add server_hostname param for wrap_socket() - uzlib: add tinfgzip.c (gzip header parsing) from upstream - moduzlib: DecompIO: Add support for gzip-formatted streams - uzlib/: update uzlib to v2.0.3 - vfs_fat: add fat_vfs_statvfs(), reused from stmhal - machine_i2c: add support for the addrsize parameter in mem xfers - machine_spi: simplify SPI xfer function to only take one buf len - machine_spi: factor out software SPI code from esp8266 to extmod - machine_spi: use delay_half, not baudrate, for internal timing - machine_spi: add optional support for fast software SPI - vfs_fat: use mp_raise_OSError helper function - modlwip: use mp_raise_OSError helper function - use mp_raise_OSError helper function - vfs_fat_file: use MP_Exxx errno constants - uzlib: update to upstream v2.1 - machine_i2c: use writes not reads in i2c.scan() - vfs_fat: add file and directory checks for remove and rmdir - modujson: implement ujson.load() to load JSON from a stream - modujson: fix nanbox build - utime_mphal: factor out implementations in terms of mp_hal_* for reuse - utime_mphal: sleep_us/ms(): Don't wait on negative argument - modussl_mbedtls: add dummy setblocking() method lib: - interrupt_char: factor out typical Ctrl+C handling from esp8266 port - cmsis: move CMSIS headers to lib/ - cmsis: remove CMSIS-DSP headers, they are unused - cmsis: upgrade CMSIS-CORE to V4.30 - utils/pyexec: don't treat SystemExit as "forced exit" - utils/pyexec: allow behaviour of SystemExit to be configurable drivers: - dht: use mp_raise_OSError helper function tools: - update upip to 0.8, fixes IPv6 support - upgrade upip to 1.0, fully self-hosted release (without fallbacks), and uses stream gzip decompression (step towards support for limited-heap baremetal systems) - upgrade upip to 1.1.3, initial support for running on a baremetal, low-heap systems (like esp8266), using Python module interface tests: - pyb: add test for ExtInt when doing swint while disabled - pyb: update exp file for previously updated extint test - extmod/urandom: add urandom tests for error cases - basics: add errno1 test, to check basics of uerrno module - extmod: add test for machine.time_pulse_us() - struct1: test "l" specifier to improve coverage - array1: add tests for "l", "L" array types to improve coverage - get cmdline verbose tests running again - run-tests: add --via-mpy option to run test from precompiled code - uzlib_decompio_gz: test for DecompIO with gzip bitstream - basics: add test case for overflowing Py stack in try-finally - micropython: add tests for const names being replaced in parser - cmdline/cmd_showbc: fix test now that 1 value is stored on stack - extmod/vfs_fat_ramdisk: add test for VFS.statvfs() - float: add test for parsing a float from an empty string - basics: add test for set.difference_update with arg being itself - basics: add further tests for nonlocal scoping and closures - import: add test for compiling "import a.b as c" - basics: add test constructing a set from a non-trivial expression - basics: add test for printing OSError when errno is unknown - run-tests: disable cmdline/cmd_showbc test on Windows - extmod/btree1: checks for put, seq, string print and unsupported binary op - fix expected output of verbose cmdline test - extmod/uzlib: test adaptive huffman tree for tinflate coverage - improve coverage of struct with test for non-compliant behaviour - io/write_ext: add description comment - io/bytesio_ext: add test for readinto() - micropython: add test for micropython.opt_level() function - improve test coverage of py/compile.c - extmod/vfs_fat: test coverage for remove() and rmdir() - extmod: add test for ujson.load() - extmod/vfs_fat: replace asserts with prints and expected outputs - micropython: add tests for heap_lock, and emergency exceptions - cmdline: improve coverage test for printing bytecode - improve coverage of array, range, dict, slice, exc, unicode - add test to print full KeyError exc from failed dict lookup - run-tests: enable extmod/machine1.py on pyboard unix port: - fix build for when MICROPY_PY_SOCKET=0 - modjni: implement subscription for object arrays - modjni: add array() top-level function to create Java array - modjni: array(): Support creation of object arrays - enable btree module for coverage build - use mp_raise_OSError helper function - use common RAISE_ERRNO macro from mphalport.h windows port: - enable MICROPY_PY_UERRNO qemu-arm port: - enable lots of extmods and enable tests for them stmhal port: - lcd: de-assert chip select after completing SPI transmission - {accel,lcd}: use GPIO_{set,clear}_pin - extint: force 0 to 1 transition on swint() - boards: add pllvalues.py script to compute PLL values for sysclk - boards: for OLIMEX_E407, enable UART1 and fix I2C1 mapping - use attribute to avoid inlining - put common definitions from linker files to common.ld - remove STM32CubeF2 HAL files, they are unused/unsupported - modmachine: fix clearing of reset-cause flags - add virtual com port support for STM32L476DISC - remove CMSIS STM32F2xx files, they are unused/unsupported - spi: simplify spi_transfer function to take only one buf len arg - mphalport: implement mp_hal_pin_{input,output,write} - spi: make machine.SPI class conform to correct API - mphalport: fix mp_hal_pin_write to use correct pin_mask - spi: use software SPI if no periph id given, even if pins given - spi: enable use of fast software SPI - fix linker map for STM32L476 chips - usbdev: add OUT endpoint to HID interface - usb: add support to receive USB HID messages from host - usb: use correct ClassData structure for HID receive - usb: use real packet size (not maximum) in HID receive - fix ESPRUINO_PICO by adding ld scripts with correct flash size - mphalport: change pin obj type to const pointer, to avoid casts - moduos: implement total-number-of-blocks field in statvfs - disable network and usocket for ESPRUINO_PICO - enable machine.time_pulse_us() function - use mp_raise_OSError helper function - pybstdio: use size_t instead of mp_uint_t - modutime: refactor to use extmod/utime_mphal.c - implement machine.soft_reset() - enable str.center(), str.[r]partition() and builtin compile() cc3200 port: - add ssl_version argument to ssl.wrap_socket() esp8266 port: - Makefile: rename SCRIPTDIR to FROZEN_DIR for consistency with FROZEN_MPY_DIR - ets_alt_task: ets_post: Should return 0 on success, !0 - failure - esp_mphal: add tentative change to mp_hal_stdin_rx_chr() to wait IRQ - extend system microsecond counter to 64-bits; use in ticks_ms - add uos.statvfs() to get filesystem status - moduos: move stat/statvfs funcs to sit within #if VFS guard - modmachine: idle(): Return number of CPU cycles spent idling - main: put /lib before / in sys.path - modpybrtc.c: implement machine.RTC.alarm_left() - make PY_UHASHLIB_SHA1 config depend on PY_USSL and SSL_AXTLS - add FLASH_MODE,FLASH_SIZE options for make deploy target - use mp_raise_OSError helper function - make neopixel support configurable - mpconfigport: enable MICROPY_PY_BUILTINS_SLICE_ATTRS - enable sys.{stdin,stdout,stderr}.buffer for raw serial access - enable importing of precompiled .mpy files - enable micropython.alloc_emergency_exception_buf() zephyr port: - initial Zephyr RTOS port, MicroPython part - initial Zephyr RTOS port, Zephyr part - add zephyr_getchar module to handle console input - switch to microkernel, required for network to work in background - automatically derive ARCH - support extra make targets - Makefile: automatically derive target-specific CFLAGS - use recently added "make outputexports" Zephyr target - add README - enable stack checking and micropython.mem_info() - enable frozen modules support - main: execute main.py frozen module on boot, if available - zephyr_getchar: add support for Ctrl+C handling - add Ctrl+C handling - implement the help() function - add copyright blurbs README: - remove issue-stats badges, the service is no longer available - mention _thread module availability in select ports docs: - library/pyb.SPI: init(): describe "bits" argument - library/machine: update description of disable/enable IRQ funcs - uos: add uos.statvfs() documentation - wipy: correct deep sleep current figure - wipy: small doc fixes - reference: add constrained.rst doc travis: - abandon mingw32 in favour of mingw-w64 - run feature and coverage test for precompiled mpy files examples: - network/http_client*: use \r\n line-endings in request
Diffstat (limited to 'unix')
-rw-r--r--unix/Makefile6
-rw-r--r--unix/coverage.c2
-rw-r--r--unix/file.c2
-rw-r--r--unix/modffi.c10
-rw-r--r--unix/modjni.c78
-rw-r--r--unix/modmachine.c5
-rw-r--r--unix/modos.c6
-rw-r--r--unix/modsocket.c12
-rw-r--r--unix/modtermios.c7
-rw-r--r--unix/modtime.c1
-rw-r--r--unix/moduselect.c11
-rw-r--r--unix/mpconfigport.mk1
-rw-r--r--unix/mphalport.h2
-rw-r--r--unix/mpthreadport.c3
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) {