From f48b70050e3e4122eaae3eee47d35fc30bda2a4c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 28 Jul 2018 13:29:47 -0400 Subject: [PATCH] merge finished --- extmod/moduhashlib.c | 16 +++++----- extmod/vfs_fat.h | 9 ------ extmod/vfs_fat_diskio.c | 6 ++-- lib/mp-readline/readline.h | 2 ++ ports/atmel-samd/mpconfigport.h | 3 ++ .../common-hal/neopixel_write/__init__.c | 2 +- ports/esp8266/esp_mphal.c | 23 +++++++++----- ports/esp8266/esp_mphal.h | 3 -- ports/esp8266/uart.c | 31 ++++++------------- .../nrf/modules/ubluepy/ubluepy_scan_entry.c | 2 +- ports/nrf/modules/ubluepy/ubluepy_scanner.c | 2 +- ports/unix/Makefile | 3 ++ ports/unix/coverage.c | 2 +- py/binary.c | 4 +-- py/frozenmod.c | 8 ++++- py/objnamedtuple.h | 6 ++-- shared-bindings/bleio/Adapter.c | 2 +- tests/import/mpy_invalid.py.exp | 6 ++-- tests/run-tests | 4 +-- 19 files changed, 66 insertions(+), 68 deletions(-) diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 6389455c06..5e14fc8d43 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -29,14 +29,6 @@ #include "py/runtime.h" -static void check_not_unicode(const mp_obj_t arg) { -#if MICROPY_CPYTHON_COMPAT - if (MP_OBJ_IS_STR(arg)) { - mp_raise_TypeError("a bytes-like object is required"); - } -#endif -} - #if MICROPY_PY_UHASHLIB #if MICROPY_PY_UHASHLIB_SHA256 @@ -102,6 +94,14 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) { #else +static void check_not_unicode(const mp_obj_t arg) { +#if MICROPY_CPYTHON_COMPAT + if (MP_OBJ_IS_STR(arg)) { + mp_raise_TypeError("a bytes-like object is required"); + } +#endif +} + STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX)); diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index ded8bc885a..dd5e5ffcb2 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -60,15 +60,6 @@ typedef struct _pyb_file_obj_t { FIL fp; } pyb_file_obj_t; - -// These should be general types (mpy TOOD says so). In micropython, these are defined in -// mpconfigport.h. -////////////#define mp_type_fileio mp_type_vfs_fat_fileio -////////////#define mp_type_textio mp_type_vfs_fat_textio - -////////////extern const mp_obj_type_t mp_type_fileio; -////////////extern const mp_obj_type_t mp_type_textio; - extern const byte fresult_to_errno_table[20]; extern const mp_obj_type_t mp_fat_vfs_type; extern const mp_obj_type_t mp_type_vfs_fat_fileio; diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 3b5c7d8887..0e442d8fa9 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -75,8 +75,9 @@ DRESULT disk_read ( return RES_ERROR; } } else { + mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count * SECSIZE(&vfs->fatfs), buff}; vfs->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector); - vfs->readblocks[3] = mp_obj_new_bytearray_by_ref(count * SECSIZE(&vfs->fatfs), buff); + vfs->readblocks[3] = MP_OBJ_FROM_PTR(&ar); nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->readblocks); @@ -120,8 +121,9 @@ DRESULT disk_write ( return RES_ERROR; } } else { + mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count * SECSIZE(&vfs->fatfs), (void*)buff}; vfs->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector); - vfs->writeblocks[3] = mp_obj_new_bytearray_by_ref(count * SECSIZE(&vfs->fatfs), (void*)buff); + vfs->writeblocks[3] = MP_OBJ_FROM_PTR(&ar); nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->writeblocks); diff --git a/lib/mp-readline/readline.h b/lib/mp-readline/readline.h index 00aa9622a8..17d4ec60ed 100644 --- a/lib/mp-readline/readline.h +++ b/lib/mp-readline/readline.h @@ -26,6 +26,8 @@ #ifndef MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H #define MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H +#include "py/misc.h" + #define CHAR_CTRL_A (1) #define CHAR_CTRL_B (2) #define CHAR_CTRL_C (3) diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 6324e7a930..49f71b2213 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -123,6 +123,9 @@ typedef long mp_off_t; #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len) +#define mp_type_fileio mp_type_vfs_fat_fileio +#define mp_type_textio mp_type_vfs_fat_textio + #define mp_import_stat mp_vfs_import_stat #define mp_builtin_open_obj mp_vfs_open_obj diff --git a/ports/esp8266/common-hal/neopixel_write/__init__.c b/ports/esp8266/common-hal/neopixel_write/__init__.c index 84a743d111..25fb0dcea5 100644 --- a/ports/esp8266/common-hal/neopixel_write/__init__.c +++ b/ports/esp8266/common-hal/neopixel_write/__init__.c @@ -29,5 +29,5 @@ #include "espneopixel.h" void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) { - esp_neopixel_write(digitalinout->pin->gpio_number, pixels, numBytes); + esp_neopixel_write(digitalinout->pin->gpio_number, pixels, numBytes, true /*800 kHz*/); } diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c index be284c8f34..fe669265e1 100644 --- a/ports/esp8266/esp_mphal.c +++ b/ports/esp8266/esp_mphal.c @@ -35,18 +35,15 @@ #include "extmod/misc.h" #include "lib/utils/pyexec.h" -STATIC byte stdin_ringbuf_array[256]; -ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0}; +STATIC byte input_buf_array[256]; +ringbuf_t stdin_ringbuf = {input_buf_array, sizeof(input_buf_array)}; void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len); const mp_print_t mp_debug_print = {NULL, mp_hal_debug_tx_strn_cooked}; -int uart_attached_to_dupterm; - void mp_hal_init(void) { //ets_wdt_disable(); // it's a pain while developing mp_hal_rtc_init(); uart_init(UART_BIT_RATE_115200, UART_BIT_RATE_115200); - uart_attached_to_dupterm = 0; } void mp_hal_delay_us(uint32_t us) { @@ -87,11 +84,19 @@ void mp_hal_debug_str(const char *str) { #endif void mp_hal_stdout_tx_str(const char *str) { - mp_uos_dupterm_tx_strn(str, strlen(str)); + const char *last = str; + while (*str) { + uart_tx_one_char(UART0, *str++); + } + mp_uos_dupterm_tx_strn(last, str - last); } void mp_hal_stdout_tx_strn(const char *str, uint32_t len) { - mp_uos_dupterm_tx_strn(str, len); + const char *last = str; + while (len--) { + uart_tx_one_char(UART0, *str++); + } + mp_uos_dupterm_tx_strn(last, str - last); } void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) { @@ -101,11 +106,13 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) { if (str > last) { mp_uos_dupterm_tx_strn(last, str - last); } + uart_tx_one_char(UART0, '\r'); + uart_tx_one_char(UART0, '\n'); mp_uos_dupterm_tx_strn("\r\n", 2); ++str; last = str; } else { - ++str; + uart_tx_one_char(UART0, *str++); } } if (str > last) { diff --git a/ports/esp8266/esp_mphal.h b/ports/esp8266/esp_mphal.h index 56d9fa35fe..5ecd392a6b 100644 --- a/ports/esp8266/esp_mphal.h +++ b/ports/esp8266/esp_mphal.h @@ -40,9 +40,6 @@ void mp_hal_signal_input(void); // Call this when data is available in dupterm object void mp_hal_signal_dupterm_input(void); -// This variable counts how many times the UART is attached to dupterm -extern int uart_attached_to_dupterm; - void mp_hal_init(void); void mp_hal_rtc_init(void); diff --git a/ports/esp8266/uart.c b/ports/esp8266/uart.c index 52707f9812..4a84053373 100644 --- a/ports/esp8266/uart.c +++ b/ports/esp8266/uart.c @@ -34,11 +34,6 @@ static int uart_os = UART_OS; static os_event_t uart_evt_queue[16]; #endif -// A small, static ring buffer for incoming chars -// This will only be populated if the UART is not attached to dupterm -static byte uart_ringbuf_array[16]; -static ringbuf_t uart_ringbuf = {uart_ringbuf_array, sizeof(uart_ringbuf_array), 0, 0}; - static void uart0_rx_intr_handler(void *para); void soft_reset(void); @@ -175,26 +170,18 @@ static void uart0_rx_intr_handler(void *para) { while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) { uint8 RcvChar = READ_PERI_REG(UART_FIFO(uart_no)) & 0xff; - // For efficiency, when connected to dupterm we put incoming chars - // directly on stdin_ringbuf, rather than going via uart_ringbuf - if (uart_attached_to_dupterm) { - if (RcvChar == mp_interrupt_char) { - mp_keyboard_interrupt(); - } else { - ringbuf_put(&stdin_ringbuf, RcvChar); - } + if (RcvChar == mp_interrupt_char) { + mp_keyboard_interrupt(); } else { - ringbuf_put(&uart_ringbuf, RcvChar); + ringbuf_put(&stdin_ringbuf, RcvChar); } } + mp_hal_signal_input(); + // Clear pending FIFO interrupts WRITE_PERI_REG(UART_INT_CLR(UART_REPL), UART_RXFIFO_TOUT_INT_CLR | UART_RXFIFO_FULL_INT_ST); ETS_UART_INTR_ENABLE(); - - if (uart_attached_to_dupterm) { - mp_hal_signal_input(); - } } } @@ -203,7 +190,7 @@ static void uart0_rx_intr_handler(void *para) { bool uart_rx_wait(uint32_t timeout_us) { uint32_t start = system_get_time(); for (;;) { - if (uart_ringbuf.iget != uart_ringbuf.iput) { + if (stdin_ringbuf.iget != stdin_ringbuf.iput) { return true; // have at least 1 char ready for reading } if (system_get_time() - start >= timeout_us) { @@ -214,7 +201,7 @@ bool uart_rx_wait(uint32_t timeout_us) { } int uart_rx_any(uint8 uart) { - if (uart_ringbuf.iget != uart_ringbuf.iput) { + if (stdin_ringbuf.iget != stdin_ringbuf.iput) { return true; // have at least 1 char ready for reading } return false; @@ -230,7 +217,7 @@ int uart_tx_any_room(uint8 uart) { // Returns char from the input buffer, else -1 if buffer is empty. int uart_rx_char(void) { - return ringbuf_get(&uart_ringbuf); + return ringbuf_get(&stdin_ringbuf); } int uart_rx_one_char(uint8 uart_no) { @@ -288,7 +275,7 @@ void uart_task_handler(os_event_t *evt) { } int c, ret = 0; - while ((c = ringbuf_get(&input_buf)) >= 0) { + while ((c = ringbuf_get(&stdin_ringbuf)) >= 0) { if (c == mp_interrupt_char) { mp_keyboard_interrupt(); } diff --git a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c index 8a936d5928..773070b089 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c +++ b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c @@ -109,7 +109,7 @@ STATIC mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) { vstr_t vstr; vstr_init(&vstr, len); vstr_printf(&vstr, "%s", text); - description = mp_obj_new_str(vstr.buf, vstr.len, false); + description = mp_obj_new_str(vstr.buf, vstr.len); vstr_clear(&vstr); } } diff --git a/ports/nrf/modules/ubluepy/ubluepy_scanner.c b/ports/nrf/modules/ubluepy/ubluepy_scanner.c index c92b7fd876..1cde3d551e 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_scanner.c +++ b/ports/nrf/modules/ubluepy/ubluepy_scanner.c @@ -49,7 +49,7 @@ STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_d data->p_peer_addr[5], data->p_peer_addr[4], data->p_peer_addr[3], data->p_peer_addr[2], data->p_peer_addr[1], data->p_peer_addr[0]); - item->addr = mp_obj_new_str(vstr.buf, vstr.len, false); + item->addr = mp_obj_new_str(vstr.buf, vstr.len); vstr_clear(&vstr); diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 1136c42b62..104ad3e5d1 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -261,6 +261,9 @@ coverage_test: coverage gcov -o build-coverage/py $(TOP)/py/*.c gcov -o build-coverage/extmod $(TOP)/extmod/*.c +coverage_clean: + $(MAKE) V=2 BUILD=build-coverage PROG=micropython_coverage clean + # Value of configure's --host= option (required for cross-compilation). # Deduce it from CROSS_COMPILE by default, but can be overridden. ifneq ($(CROSS_COMPILE),) diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 7820f6d736..841924c58d 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -173,7 +173,7 @@ STATIC mp_obj_t extra_coverage(void) { gc_unlock(); // using gc_realloc to resize to 0, which means free the memory - void *p = gc_alloc(4, false); + void *p = gc_alloc(4, false, false); mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false)); // calling gc_nbytes with a non-heap pointer diff --git a/py/binary.c b/py/binary.c index bb334ed3db..4f02525d76 100644 --- a/py/binary.c +++ b/py/binary.c @@ -148,7 +148,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) { #endif #if MICROPY_PY_BUILTINS_FLOAT case 'f': - return mp_obj_new_float((mp_float_t)((float*)p)[index]); + return mp_obj_new_float(((float*)p)[index]); case 'd': return mp_obj_new_float(((double*)p)[index]); #endif @@ -213,7 +213,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) { #if MICROPY_NONSTANDARD_TYPECODES } else if (val_type == 'S') { const char *s_val = (const char*)(uintptr_t)(mp_uint_t)val; - return mp_obj_new_str(s_val, strlen(s_val), false); + return mp_obj_new_str(s_val, strlen(s_val)); #endif #if MICROPY_PY_BUILTINS_FLOAT } else if (val_type == 'f') { diff --git a/py/frozenmod.c b/py/frozenmod.c index 5464d0af90..a9143b582a 100644 --- a/py/frozenmod.c +++ b/py/frozenmod.c @@ -43,8 +43,14 @@ extern const char mp_frozen_str_names[]; extern const uint32_t mp_frozen_str_sizes[]; extern const char mp_frozen_str_content[]; -// On input, *len contains size of name, on output - size of content +// str_len is length of str. *len is set on on output to size of content const char *mp_find_frozen_str(const char *str, size_t str_len, size_t *len) { + // If the frozen module pseudo dir (e.g., ".frozen/") is a prefix of str, remove it. + if (strncmp(str, MP_FROZEN_FAKE_DIR_SLASH, MP_FROZEN_FAKE_DIR_SLASH_LENGTH) == 0) { + str = str + MP_FROZEN_FAKE_DIR_SLASH_LENGTH; + str_len = str_len - MP_FROZEN_FAKE_DIR_SLASH_LENGTH; + } + const char *name = mp_frozen_str_names; size_t offset = 0; diff --git a/py/objnamedtuple.h b/py/objnamedtuple.h index a36404b8d4..deac7107be 100644 --- a/py/objnamedtuple.h +++ b/py/objnamedtuple.h @@ -39,7 +39,7 @@ typedef struct _mp_obj_namedtuple_type_t { mp_obj_type_t base; - mp_uint_t n_fields; + size_t n_fields; qstr fields[]; } mp_obj_namedtuple_type_t; @@ -48,9 +48,9 @@ typedef struct _mp_obj_namedtuple_t { } mp_obj_namedtuple_t; void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind); - +size_t mp_obj_namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr name); void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); - +mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t *fields); mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); #endif // MICROPY_PY_COLLECTIONS diff --git a/shared-bindings/bleio/Adapter.c b/shared-bindings/bleio/Adapter.c index 81efea54eb..bfe87071d7 100644 --- a/shared-bindings/bleio/Adapter.c +++ b/shared-bindings/bleio/Adapter.c @@ -86,7 +86,7 @@ STATIC mp_obj_t bleio_adapter_get_address(mp_obj_t self) { common_hal_bleio_adapter_get_address(&vstr); - const mp_obj_t mac_str = mp_obj_new_str(vstr.buf, vstr.len, false); + const mp_obj_t mac_str = mp_obj_new_str(vstr.buf, vstr.len); vstr_clear(&vstr); diff --git a/tests/import/mpy_invalid.py.exp b/tests/import/mpy_invalid.py.exp index 1727ea1cea..e4f2b13e99 100644 --- a/tests/import/mpy_invalid.py.exp +++ b/tests/import/mpy_invalid.py.exp @@ -1,3 +1,3 @@ -mod0 ValueError incompatible .mpy file -mod1 ValueError incompatible .mpy file -mod2 ValueError incompatible .mpy file +mod0 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. +mod1 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. +mod2 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. diff --git a/tests/run-tests b/tests/run-tests index 3064f6845a..94e1591e8a 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -396,7 +396,7 @@ def run_tests(pyb, tests, args, base_path=".", num_threads=1): if pat.search(test_file): verdict = action if verdict == "exclude": - continue + return test_basename = os.path.basename(test_file) test_name = os.path.splitext(test_basename)[0] @@ -419,7 +419,7 @@ def run_tests(pyb, tests, args, base_path=".", num_threads=1): if args.list_tests: if not skip_it: print(test_file) - continue + return if skip_it: print("skip ", test_file)