Skip to content

Commit

Permalink
merge finished
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed Jul 28, 2018
1 parent bc760dd commit f48b700
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 68 deletions.
16 changes: 8 additions & 8 deletions extmod/moduhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
9 changes: 0 additions & 9 deletions extmod/vfs_fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions extmod/vfs_fat_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/mp-readline/readline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ports/atmel-samd/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ports/esp8266/common-hal/neopixel_write/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*/);
}
23 changes: 15 additions & 8 deletions ports/esp8266/esp_mphal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions ports/esp8266/esp_mphal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
31 changes: 9 additions & 22 deletions ports/esp8266/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
}

Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion ports/nrf/modules/ubluepy/ubluepy_scan_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ports/nrf/modules/ubluepy/ubluepy_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions ports/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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),)
Expand Down
2 changes: 1 addition & 1 deletion ports/unix/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions py/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') {
Expand Down
8 changes: 7 additions & 1 deletion py/frozenmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions py/objnamedtuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/bleio/Adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions tests/import/mpy_invalid.py.exp
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions tests/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down

0 comments on commit f48b700

Please sign in to comment.