Skip to content

Commit ef0830b

Browse files
committed
merge from upstream + wip
2 parents 9dbea36 + e778fc1 commit ef0830b

File tree

112 files changed

+4194
-1209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+4194
-1209
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ jobs:
198198
- "circuitplayground_express_displayio"
199199
- "clue_nrf52840_express"
200200
- "cp32-m4"
201+
- "cp_sapling_m0"
202+
- "cp_sapling_m0_spiflash"
201203
- "datalore_ip_m4"
202204
- "datum_distance"
203205
- "datum_imu"
@@ -317,7 +319,8 @@ jobs:
317319
- "teensy40"
318320
- "teensy41"
319321
- "teknikio_bluebird"
320-
- "thunderpack"
322+
- "thunderpack_v11"
323+
- "thunderpack_v12"
321324
- "tinkeringtech_scoutmakes_azul"
322325
- "trellis_m4_express"
323326
- "trinket_m0"

extmod/machine_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
2222
uintptr_t addr = mp_obj_int_get_truncated(addr_o);
2323
if ((addr & (align - 1)) != 0) {
24-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, translate("address %08x is not aligned to %d bytes"), addr, align));
24+
mp_raise_ValueError_varg(translate("address %08x is not aligned to %d bytes"), addr, align);
2525
}
2626
return addr;
2727
}

extmod/moduheapq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush);
6262
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
6363
mp_obj_list_t *heap = get_heap(heap_in);
6464
if (heap->len == 0) {
65-
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, translate("empty heap")));
65+
mp_raise_IndexError(translate("empty heap"));
6666
}
6767
mp_obj_t item = heap->items[0];
6868
heap->len -= 1;

extmod/modujson.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ typedef struct _ujson_stream_t {
5757
int errcode;
5858
mp_obj_t python_readinto[2 + 1];
5959
mp_obj_array_t bytearray_obj;
60+
size_t start;
61+
size_t end;
6062
byte cur;
6163
} ujson_stream_t;
6264

@@ -77,28 +79,44 @@ STATIC byte ujson_stream_next(ujson_stream_t *s) {
7779
return s->cur;
7880
}
7981

82+
// We read from an object's `readinto` method in chunks larger than the json
83+
// parser needs to reduce the number of function calls done.
84+
85+
#define CIRCUITPY_JSON_READ_CHUNK_SIZE 64
86+
8087
STATIC mp_uint_t ujson_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
88+
(void) size; // Ignore size because we know it's always 1.
8189
ujson_stream_t* s = obj;
82-
s->bytearray_obj.items = buf;
83-
s->bytearray_obj.len = size;
84-
*errcode = 0;
85-
mp_obj_t ret = mp_call_method_n_kw(1, 0, s->python_readinto);
86-
if (ret == mp_const_none) {
87-
*errcode = MP_EAGAIN;
88-
return MP_STREAM_ERROR;
90+
91+
if (s->start == s->end) {
92+
*errcode = 0;
93+
mp_obj_t ret = mp_call_method_n_kw(1, 0, s->python_readinto);
94+
if (ret == mp_const_none) {
95+
*errcode = MP_EAGAIN;
96+
return MP_STREAM_ERROR;
97+
}
98+
s->start = 0;
99+
s->end = mp_obj_get_int(ret);
89100
}
90-
return mp_obj_get_int(ret);
101+
102+
*((uint8_t *)buf) = ((uint8_t*) s->bytearray_obj.items)[s->start];
103+
s->start++;
104+
return 1;
91105
}
92106

93107
STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
94108
const mp_stream_p_t *stream_p = mp_proto_get(MP_QSTR_protocol_stream, stream_obj);
95109
ujson_stream_t s;
110+
uint8_t character_buffer[CIRCUITPY_JSON_READ_CHUNK_SIZE];
96111
if (stream_p == NULL) {
112+
s.start = 0;
113+
s.end = 0;
97114
mp_load_method(stream_obj, MP_QSTR_readinto, s.python_readinto);
98115
s.bytearray_obj.base.type = &mp_type_bytearray;
99116
s.bytearray_obj.typecode = BYTEARRAY_TYPECODE;
117+
s.bytearray_obj.len = CIRCUITPY_JSON_READ_CHUNK_SIZE;
100118
s.bytearray_obj.free = 0;
101-
// len and items are set at read time
119+
s.bytearray_obj.items = character_buffer;
102120
s.python_readinto[2] = MP_OBJ_FROM_PTR(&s.bytearray_obj);
103121
s.stream_obj = &s;
104122
s.read = ujson_python_readinto;

extmod/modure.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
4343
mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
4444
mp_int_t no = mp_obj_get_int(no_in);
4545
if (no < 0 || no >= self->num_matches) {
46-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, no_in));
46+
mp_raise_arg1(&mp_type_IndexError, no_in);
4747
}
4848

4949
const char *start = self->caps[no * 2];
@@ -82,7 +82,7 @@ STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span
8282
if (n_args == 2) {
8383
no = mp_obj_get_int(args[1]);
8484
if (no < 0 || no >= self->num_matches) {
85-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, args[1]));
85+
mp_raise_arg1(&mp_type_IndexError, args[1]);
8686
}
8787
}
8888

@@ -326,7 +326,7 @@ STATIC mp_obj_t re_sub_helper(mp_obj_t self_in, size_t n_args, const mp_obj_t *a
326326
}
327327

328328
if (match_no >= (unsigned int)match->num_matches) {
329-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no)));
329+
mp_raise_arg1(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no));
330330
}
331331

332332
const char *start_match = match->caps[match_no * 2];

extmod/moduzlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
179179
return res;
180180

181181
error:
182-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)));
182+
mp_raise_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st));
183183
}
184184
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress);
185185

extmod/ulab

Submodule ulab updated 81 files

extmod/vfs_posix_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef struct _mp_obj_vfs_posix_file_t {
2424
#ifdef MICROPY_CPYTHON_COMPAT
2525
STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
2626
if (o->fd < 0) {
27-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, translate("I/O operation on closed file")));
27+
mp_raise_ValueError(translate("I/O operation on closed file"));
2828
}
2929
}
3030
#else

lib/tinyusb

Submodule tinyusb updated 226 files

0 commit comments

Comments
 (0)