Skip to content

Commit 966d25c

Browse files
committed
Merge MicroPython v1.15 into CircuitPython
2 parents a70fc0c + 321d189 commit 966d25c

Some content is hidden

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

70 files changed

+1807
-909
lines changed

.git-blame-ignore-revs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# tests/run-tests.py: Reformat with Black.
2+
2a38d7103672580882fb621a5b76e8d26805d593
3+
4+
# all: Update Python code to conform to latest black formatting.
5+
06659077a81b85882254cf0953c33b27614e018e
6+
7+
# tools/uncrustify: Enable more opts to remove space between func and '('.
8+
77ed6f69ac35c1663a5633a8ee1d8a2446542204
9+
10+
# tools/codeformat.py: Include extmod/{btstack,nimble} in code formatting.
11+
026fda605e03113d6e753290d65fed774418bc53
12+
13+
# all: Format code to add space after C++-style comment start.
14+
84fa3312cfa7d2237d4b56952f2cd6e3591210c4
15+
16+
# tests: Format all Python code with black, except tests in basics subdir.
17+
3dc324d3f1312e40d3a8ed87e7244966bb756f26
18+
19+
# all: Remove spaces inside and around parenthesis.
20+
1a3e386c67e03a79eb768cb6e9f6777e002d6660
21+
22+
# all: Remove spaces between nested paren and inside function arg paren.
23+
feb25775851ba0c04b8d1013716f442258879d9c
24+
25+
# all: Reformat C and Python source code with tools/codeformat.py.
26+
69661f3343bedf86e514337cff63d96cc42f8859
27+
28+
# stm32/usbdev: Convert files to unix line endings.
29+
abde0fa2267f9062b28c3c015d7662a550125cc6
30+
31+
# all: Remove trailing spaces, per coding conventions.
32+
761e4c7ff62896c7d8f8c3dfc3cc98a4cc4f2f6f

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ jobs:
7373
run: |
7474
make -C ports/unix VARIANT=coverage -j2
7575
- name: Test all
76-
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests -j1
76+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1
7777
working-directory: tests
7878
- name: Native Tests
79-
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests -j1 --emit native
79+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --emit native
8080
working-directory: tests
8181
- name: mpy Tests
82-
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests -j1 --mpy-cross-flags='-mcache-lookup-bc' --via-mpy -d basics float micropython
82+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --mpy-cross-flags='-mcache-lookup-bc' --via-mpy -d basics float micropython
8383
working-directory: tests
8484
- name: Native mpy Tests
85-
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests -j1 --mpy-cross-flags='-mcache-lookup-bc' --via-mpy --emit native -d basics float micropython
85+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --mpy-cross-flags='-mcache-lookup-bc' --via-mpy --emit native -d basics float micropython
8686
working-directory: tests
8787
- name: Build mpy-cross.static-aarch64
8888
run: make -C mpy-cross -j2 -f Makefile.static-aarch64

docs/library/uasyncio.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Core functions
4040

4141
Returns the corresponding `Task` object.
4242

43+
.. function:: current_task()
44+
45+
Return the `Task` object associated with the currently running task.
46+
4347
.. function:: run(coro)
4448

4549
Create a new task from the given coroutine and run it until it completes.

extmod/extmod.cmake

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# CMake fragment for MicroPython extmod component
2+
3+
set(MICROPY_EXTMOD_DIR "${MICROPY_DIR}/extmod")
4+
set(MICROPY_OOFATFS_DIR "${MICROPY_DIR}/lib/oofatfs")
5+
6+
set(MICROPY_SOURCE_EXTMOD
7+
${MICROPY_DIR}/lib/embed/abort_.c
8+
${MICROPY_DIR}/lib/utils/printf.c
9+
${MICROPY_EXTMOD_DIR}/machine_i2c.c
10+
${MICROPY_EXTMOD_DIR}/machine_mem.c
11+
${MICROPY_EXTMOD_DIR}/machine_pulse.c
12+
${MICROPY_EXTMOD_DIR}/machine_signal.c
13+
${MICROPY_EXTMOD_DIR}/machine_spi.c
14+
${MICROPY_EXTMOD_DIR}/modbluetooth.c
15+
${MICROPY_EXTMOD_DIR}/modbtree.c
16+
${MICROPY_EXTMOD_DIR}/modframebuf.c
17+
${MICROPY_EXTMOD_DIR}/modonewire.c
18+
${MICROPY_EXTMOD_DIR}/moduasyncio.c
19+
${MICROPY_EXTMOD_DIR}/modubinascii.c
20+
${MICROPY_EXTMOD_DIR}/moducryptolib.c
21+
${MICROPY_EXTMOD_DIR}/moductypes.c
22+
${MICROPY_EXTMOD_DIR}/moduhashlib.c
23+
${MICROPY_EXTMOD_DIR}/moduheapq.c
24+
${MICROPY_EXTMOD_DIR}/modujson.c
25+
${MICROPY_EXTMOD_DIR}/modurandom.c
26+
${MICROPY_EXTMOD_DIR}/modure.c
27+
${MICROPY_EXTMOD_DIR}/moduselect.c
28+
${MICROPY_EXTMOD_DIR}/modussl_axtls.c
29+
${MICROPY_EXTMOD_DIR}/modussl_mbedtls.c
30+
${MICROPY_EXTMOD_DIR}/modutimeq.c
31+
${MICROPY_EXTMOD_DIR}/moduwebsocket.c
32+
${MICROPY_EXTMOD_DIR}/moduzlib.c
33+
${MICROPY_EXTMOD_DIR}/modwebrepl.c
34+
${MICROPY_EXTMOD_DIR}/uos_dupterm.c
35+
${MICROPY_EXTMOD_DIR}/utime_mphal.c
36+
${MICROPY_EXTMOD_DIR}/vfs.c
37+
${MICROPY_EXTMOD_DIR}/vfs_blockdev.c
38+
${MICROPY_EXTMOD_DIR}/vfs_fat.c
39+
${MICROPY_EXTMOD_DIR}/vfs_fat_diskio.c
40+
${MICROPY_EXTMOD_DIR}/vfs_fat_file.c
41+
${MICROPY_EXTMOD_DIR}/vfs_lfs.c
42+
${MICROPY_EXTMOD_DIR}/vfs_posix.c
43+
${MICROPY_EXTMOD_DIR}/vfs_posix_file.c
44+
${MICROPY_EXTMOD_DIR}/vfs_reader.c
45+
${MICROPY_EXTMOD_DIR}/virtpin.c
46+
${MICROPY_EXTMOD_DIR}/nimble/modbluetooth_nimble.c
47+
)
48+
49+
# Library for btree module and associated code
50+
51+
set(MICROPY_LIB_BERKELEY_DIR "${MICROPY_DIR}/lib/berkeley-db-1.xx")
52+
53+
if(EXISTS "${MICROPY_LIB_BERKELEY_DIR}/btree/bt_close.c")
54+
add_library(micropy_extmod_btree OBJECT
55+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_close.c
56+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_conv.c
57+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_debug.c
58+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_delete.c
59+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_get.c
60+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_open.c
61+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_overflow.c
62+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_page.c
63+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_put.c
64+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_search.c
65+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_seq.c
66+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_split.c
67+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_utils.c
68+
${MICROPY_LIB_BERKELEY_DIR}/mpool/mpool.c
69+
)
70+
71+
target_include_directories(micropy_extmod_btree PRIVATE
72+
${MICROPY_LIB_BERKELEY_DIR}/PORT/include
73+
)
74+
75+
target_compile_definitions(micropy_extmod_btree PRIVATE
76+
__DBINTERFACE_PRIVATE=1
77+
mpool_error=printf
78+
abort=abort_
79+
"virt_fd_t=void*"
80+
)
81+
82+
# The include directories and compile definitions below are needed to build
83+
# modbtree.c and should be added to the main MicroPython target.
84+
85+
list(APPEND MICROPY_INC_CORE
86+
"${MICROPY_LIB_BERKELEY_DIR}/PORT/include"
87+
)
88+
89+
list(APPEND MICROPY_DEF_CORE
90+
__DBINTERFACE_PRIVATE=1
91+
"virt_fd_t=void*"
92+
)
93+
endif()

extmod/moduselect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) {
128128
// poll the objects
129129
mp_uint_t n_ready = poll_map_poll(&poll_map, rwx_len);
130130

131-
if (n_ready > 0 || (timeout != -1 && mp_hal_ticks_ms() - start_tick >= timeout)) {
131+
if (n_ready > 0 || (timeout != (mp_uint_t)-1 && mp_hal_ticks_ms() - start_tick >= timeout)) {
132132
// one or more objects are ready, or we had a timeout
133133
mp_obj_t list_array[3];
134134
list_array[0] = mp_obj_new_list(rwx_len[0], NULL);
@@ -230,7 +230,7 @@ STATIC mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) {
230230
for (;;) {
231231
// poll the objects
232232
n_ready = poll_map_poll(&self->poll_map, NULL);
233-
if (n_ready > 0 || (timeout != -1 && mp_hal_ticks_ms() - start_tick >= timeout)) {
233+
if (n_ready > 0 || (timeout != (mp_uint_t)-1 && mp_hal_ticks_ms() - start_tick >= timeout)) {
234234
break;
235235
}
236236
MICROPY_EVENT_POLL_HOOK

extmod/uasyncio/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"wait_for_ms": "funcs",
1111
"gather": "funcs",
1212
"Event": "event",
13+
"ThreadSafeFlag": "event",
1314
"Lock": "lock",
1415
"open_connection": "stream",
1516
"start_server": "stream",

extmod/uasyncio/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ def get_event_loop(runq_len=0, waitq_len=0):
264264
return Loop
265265

266266

267+
def current_task():
268+
return cur_task
269+
270+
267271
def new_event_loop():
268272
global _task_queue, _io_queue
269273
# TaskQueue of Task instances

extmod/uasyncio/event.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def is_set(self):
1414

1515
def set(self):
1616
# Event becomes set, schedule any tasks waiting on it
17+
# Note: This must not be called from anything except the thread running
18+
# the asyncio loop (i.e. neither hard or soft IRQ, or a different thread).
1719
while self.waiting.peek():
1820
core._task_queue.push_head(self.waiting.pop_head())
1921
self.state = True

extmod/vfs_posix_file.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t
137137

138138
STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
139139
mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in);
140-
check_fd_is_open(o);
140+
141+
if (request != MP_STREAM_CLOSE) {
142+
check_fd_is_open(o);
143+
}
144+
141145
switch (request) {
142146
case MP_STREAM_FLUSH: {
143147
int ret;

lib/utils/gchelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef uintptr_t gc_helper_regs_t[6];
3939
typedef uintptr_t gc_helper_regs_t[4];
4040
#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
4141
typedef uintptr_t gc_helper_regs_t[10];
42+
#elif defined(__aarch64__)
43+
typedef uintptr_t gc_helper_regs_t[11]; // x19-x29
4244
#endif
4345

4446
#endif

lib/utils/gchelper_generic.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,33 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
123123
arr[9] = r13;
124124
}
125125

126+
#elif defined(__aarch64__)
127+
128+
STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
129+
const register long x19 asm ("x19");
130+
const register long x20 asm ("x20");
131+
const register long x21 asm ("x21");
132+
const register long x22 asm ("x22");
133+
const register long x23 asm ("x23");
134+
const register long x24 asm ("x24");
135+
const register long x25 asm ("x25");
136+
const register long x26 asm ("x26");
137+
const register long x27 asm ("x27");
138+
const register long x28 asm ("x28");
139+
const register long x29 asm ("x29");
140+
arr[0] = x19;
141+
arr[1] = x20;
142+
arr[2] = x21;
143+
arr[3] = x22;
144+
arr[4] = x23;
145+
arr[5] = x24;
146+
arr[6] = x25;
147+
arr[7] = x26;
148+
arr[8] = x27;
149+
arr[9] = x28;
150+
arr[10] = x29;
151+
}
152+
126153
#else
127154

128155
#error "Architecture not supported for gc_helper_get_regs. Set MICROPY_GCREGS_SETJMP to use the fallback implementation."

mpy-cross/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ STATIC void pre_process_options(int argc, char **argv) {
149149
heap_size *= 1024 * 1024;
150150
}
151151
if (word_adjust) {
152-
heap_size = heap_size * BYTES_PER_WORD / 4;
152+
heap_size = heap_size * MP_BYTES_PER_OBJ_WORD / 4;
153153
}
154154
} else {
155155
exit(usage(argv));
@@ -161,7 +161,7 @@ STATIC void pre_process_options(int argc, char **argv) {
161161
}
162162

163163
MP_NOINLINE int main_(int argc, char **argv) {
164-
mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4));
164+
mp_stack_set_limit(40000 * (sizeof(void *) / 4));
165165

166166
pre_process_options(argc, argv);
167167

ports/unix/Makefile

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,26 +226,23 @@ include $(TOP)/py/mkrules.mk
226226

227227
.PHONY: test test_full
228228

229-
test: $(PROG) $(TOP)/tests/run-tests
229+
test: $(PROG) $(TOP)/tests/run-tests.py
230230
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
231-
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --auto-jobs
231+
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py --auto-jobs
232232

233-
test_full: $(PROG) $(TOP)/tests/run-tests
233+
test_full: $(PROG) $(TOP)/tests/run-tests.py
234234
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
235-
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
236-
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests -d thread
237-
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --emit native
238-
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --via-mpy $(RUN_TESTS_MPY_CROSS_FLAGS) -d basics float micropython
239-
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --via-mpy $(RUN_TESTS_MPY_CROSS_FLAGS) --emit native -d basics float micropython
235+
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py
236+
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py -d thread
237+
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py --emit native
238+
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py --via-mpy $(RUN_TESTS_MPY_CROSS_FLAGS) -d basics float micropython
239+
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py --via-mpy $(RUN_TESTS_MPY_CROSS_FLAGS) --emit native -d basics float micropython
240240
cat $(TOP)/tests/basics/0prelim.py | ./$(PROG) | grep -q 'abc'
241241

242242
test_gcov: test_full
243243
gcov -o $(BUILD)/py $(TOP)/py/*.c
244244
gcov -o $(BUILD)/extmod $(TOP)/extmod/*.c
245245

246-
coverage_clean:
247-
$(MAKE) V=2 BUILD=build-coverage PROG=micropython_coverage clean
248-
249246
# build an interpreter for fuzzing
250247
fuzz:
251248
$(MAKE) \

ports/unix/main.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ STATIC int invalid_args(void) {
340340
STATIC void pre_process_options(int argc, char **argv) {
341341
for (int a = 1; a < argc; a++) {
342342
if (argv[a][0] == '-') {
343+
if (strcmp(argv[a], "-c") == 0 || strcmp(argv[a], "-m") == 0) {
344+
break; // Everything after this is a command/module and arguments for it
345+
}
343346
if (strcmp(argv[a], "-h") == 0) {
344347
print_help(argv);
345348
exit(0);
@@ -386,7 +389,7 @@ STATIC void pre_process_options(int argc, char **argv) {
386389
goto invalid_arg;
387390
}
388391
if (word_adjust) {
389-
heap_size = heap_size * BYTES_PER_WORD / 4;
392+
heap_size = heap_size * MP_BYTES_PER_OBJ_WORD / 4;
390393
}
391394
// If requested size too small, we'll crash anyway
392395
if (heap_size < 700) {
@@ -399,6 +402,8 @@ STATIC void pre_process_options(int argc, char **argv) {
399402
}
400403
a++;
401404
}
405+
} else {
406+
break; // Not an option but a file
402407
}
403408
}
404409
}
@@ -445,7 +450,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
445450
signal(SIGPIPE, SIG_IGN);
446451
#endif
447452

448-
mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4));
453+
mp_stack_set_limit(40000 * (sizeof(void *) / 4));
449454

450455
pre_process_options(argc, argv);
451456

@@ -571,11 +576,10 @@ MP_NOINLINE int main_(int argc, char **argv) {
571576
if (a + 1 >= argc) {
572577
return invalid_args();
573578
}
579+
set_sys_argv(argv, a + 1, a); // The -c becomes first item of sys.argv, as in CPython
580+
set_sys_argv(argv, argc, a + 2); // Then what comes after the command
574581
ret = do_str(argv[a + 1]);
575-
if (ret & FORCED_EXIT) {
576-
break;
577-
}
578-
a += 1;
582+
break;
579583
} else if (strcmp(argv[a], "-m") == 0) {
580584
if (a + 1 >= argc) {
581585
return invalid_args();
@@ -595,7 +599,12 @@ MP_NOINLINE int main_(int argc, char **argv) {
595599

596600
mp_obj_t mod;
597601
nlr_buf_t nlr;
598-
bool subpkg_tried = false;
602+
603+
// Allocating subpkg_tried on the stack can lead to compiler warnings about this
604+
// variable being clobbered when nlr is implemented using setjmp/longjmp. Its
605+
// value must be preserved across calls to setjmp/longjmp.
606+
static bool subpkg_tried;
607+
subpkg_tried = false;
599608

600609
reimport:
601610
if (nlr_push(&nlr) == 0) {

ports/unix/moduselect.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
#if MICROPY_PY_USELECT_POSIX
3131

32+
#if MICROPY_PY_USELECT
33+
#error "Can't have both MICROPY_PY_USELECT and MICROPY_PY_USELECT_POSIX."
34+
#endif
35+
3236
#include <stdio.h>
3337
#include <errno.h>
3438
#include <poll.h>

0 commit comments

Comments
 (0)