Skip to content

Commit 918145f

Browse files
authored
Merge pull request #6038 from jepler/merge-1.18
Merge 1.18
2 parents 291a335 + 090b153 commit 918145f

File tree

109 files changed

+1763
-1371
lines changed

Some content is hidden

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

109 files changed

+1763
-1371
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ jobs:
7272
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --emit native
7373
working-directory: tests
7474
- name: mpy Tests
75-
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
75+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --via-mpy -d basics float micropython
7676
working-directory: tests
7777
- name: Native mpy Tests
78-
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
78+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --via-mpy --emit native -d basics float micropython
7979
working-directory: tests
8080
- name: Build native modules
8181
run: |

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013-2021 Damien P. George
3+
Copyright (c) 2013-2022 Damien P. George
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docs/library/framebuf.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ For example::
2121
import framebuf
2222

2323
# FrameBuffer needs 2 bytes for every RGB565 pixel
24-
fbuf = framebuf.FrameBuffer(bytearray(10 * 100 * 2), 10, 100, framebuf.RGB565)
24+
fbuf = framebuf.FrameBuffer(bytearray(100 * 10 * 2), 100, 10, framebuf.RGB565)
2525

2626
fbuf.fill(0)
2727
fbuf.text('MicroPython!', 0, 0, 0xffff)
28-
fbuf.hline(0, 10, 96, 0xffff)
28+
fbuf.hline(0, 9, 96, 0xffff)
2929

3030
Constructors
3131
------------

docs/library/sys.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ Constants
8080

8181
A mutable list of directories to search for imported modules.
8282

83+
.. admonition:: Difference to CPython
84+
:class: attention
85+
86+
On MicroPython, an entry with the value ``".frozen"`` will indicate that import
87+
should search :term:`frozen modules <frozen module>` at that point in the search.
88+
If no frozen module is found then search will *not* look for a directory called
89+
``.frozen``, instead it will continue with the next entry in ``sys.path``.
90+
8391
.. data:: platform
8492

8593
The platform that CircuitPython is running on. For OS/RTOS ports, this is

extmod/extmod.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ set(MICROPY_SOURCE_EXTMOD
1010
${MICROPY_EXTMOD_DIR}/machine_i2c.c
1111
${MICROPY_EXTMOD_DIR}/machine_mem.c
1212
${MICROPY_EXTMOD_DIR}/machine_pulse.c
13+
${MICROPY_EXTMOD_DIR}/machine_pwm.c
1314
${MICROPY_EXTMOD_DIR}/machine_signal.c
1415
${MICROPY_EXTMOD_DIR}/machine_spi.c
1516
${MICROPY_EXTMOD_DIR}/modbluetooth.c
1617
${MICROPY_EXTMOD_DIR}/modbtree.c
1718
${MICROPY_EXTMOD_DIR}/modframebuf.c
19+
${MICROPY_EXTMOD_DIR}/modnetwork.c
1820
${MICROPY_EXTMOD_DIR}/modonewire.c
1921
${MICROPY_EXTMOD_DIR}/moduasyncio.c
2022
${MICROPY_EXTMOD_DIR}/modubinascii.c
@@ -23,9 +25,11 @@ set(MICROPY_SOURCE_EXTMOD
2325
${MICROPY_EXTMOD_DIR}/moduhashlib.c
2426
${MICROPY_EXTMOD_DIR}/moduheapq.c
2527
${MICROPY_EXTMOD_DIR}/modujson.c
28+
${MICROPY_EXTMOD_DIR}/moduplatform.c
2629
${MICROPY_EXTMOD_DIR}/modurandom.c
2730
${MICROPY_EXTMOD_DIR}/modure.c
2831
${MICROPY_EXTMOD_DIR}/moduselect.c
32+
${MICROPY_EXTMOD_DIR}/modusocket.c
2933
${MICROPY_EXTMOD_DIR}/modussl_axtls.c
3034
${MICROPY_EXTMOD_DIR}/modussl_mbedtls.c
3135
${MICROPY_EXTMOD_DIR}/modutimeq.c

extmod/modonewire.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "py/obj.h"
1010
#include "py/mphal.h"
1111

12+
#if MICROPY_PY_ONEWIRE
13+
1214
/******************************************************************************/
1315
// Low-level 1-Wire routines
1416

@@ -139,3 +141,5 @@ const mp_obj_module_t mp_module_onewire = {
139141
.base = { &mp_type_module },
140142
.globals = (mp_obj_dict_t *)&onewire_module_globals,
141143
};
144+
145+
#endif // MICROPY_PY_ONEWIRE

extmod/moduplatform.c

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2021 Ibrahim Abdelkader <[email protected]>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
28+
#include "py/runtime.h"
29+
#include "py/objtuple.h"
30+
#include "py/objstr.h"
31+
#include "py/mphal.h"
32+
#include "genhdr/mpversion.h"
33+
34+
#if MICROPY_PY_UPLATFORM
35+
36+
// platform - Access to underlying platform's identifying data
37+
38+
// TODO: Add more architectures, compilers and libraries.
39+
// See: https://sourceforge.net/p/predef/wiki/Home/
40+
41+
#if defined(__ARM_ARCH)
42+
#define PLATFORM_ARCH "arm"
43+
#elif defined(__x86_64__) || defined(_WIN64)
44+
#define PLATFORM_ARCH "x86_64"
45+
#elif defined(__i386__) || defined(_M_IX86)
46+
#define PLATFORM_ARCH "x86"
47+
#elif defined(__xtensa__) || defined(_M_IX86)
48+
#define PLATFORM_ARCH "xtensa"
49+
#else
50+
#define PLATFORM_ARCH ""
51+
#endif
52+
53+
#if defined(__GNUC__)
54+
#define PLATFORM_COMPILER \
55+
"GCC " \
56+
MP_STRINGIFY(__GNUC__) "." \
57+
MP_STRINGIFY(__GNUC_MINOR__) "." \
58+
MP_STRINGIFY(__GNUC_PATCHLEVEL__)
59+
#elif defined(__ARMCC_VERSION)
60+
#define PLATFORM_COMPILER \
61+
"ARMCC " \
62+
MP_STRINGIFY((__ARMCC_VERSION / 1000000)) "." \
63+
MP_STRINGIFY((__ARMCC_VERSION / 10000 % 100)) "." \
64+
MP_STRINGIFY((__ARMCC_VERSION % 10000))
65+
#elif defined(_MSC_VER)
66+
#if defined(_WIN64)
67+
#define COMPILER_BITS "64 bit"
68+
#elif defined(_M_IX86)
69+
#define COMPILER_BITS "32 bit"
70+
#else
71+
#define COMPILER_BITS ""
72+
#endif
73+
#define PLATFORM_COMPILER \
74+
"MSC v." MP_STRINGIFY(_MSC_VER) " " COMPILER_BITS
75+
#else
76+
#define PLATFORM_COMPILER ""
77+
#endif
78+
79+
#if defined(__GLIBC__)
80+
#define PLATFORM_LIBC_LIB "glibc"
81+
#define PLATFORM_LIBC_VER \
82+
MP_STRINGIFY(__GLIBC__) "." \
83+
MP_STRINGIFY(__GLIBC_MINOR__)
84+
#elif defined(__NEWLIB__)
85+
#define PLATFORM_LIBC_LIB "newlib"
86+
#define PLATFORM_LIBC_VER _NEWLIB_VERSION
87+
#else
88+
#define PLATFORM_LIBC_LIB ""
89+
#define PLATFORM_LIBC_VER ""
90+
#endif
91+
92+
#if defined(__linux)
93+
#define PLATFORM_SYSTEM "Linux"
94+
#elif defined(__unix__)
95+
#define PLATFORM_SYSTEM "Unix"
96+
#elif defined(__CYGWIN__)
97+
#define PLATFORM_SYSTEM "Cygwin"
98+
#elif defined(_WIN32)
99+
#define PLATFORM_SYSTEM "Windows"
100+
#else
101+
#define PLATFORM_SYSTEM "MicroPython"
102+
#endif
103+
104+
#ifndef MICROPY_PLATFORM_VERSION
105+
#define MICROPY_PLATFORM_VERSION ""
106+
#endif
107+
108+
STATIC const MP_DEFINE_STR_OBJ(info_platform_obj, PLATFORM_SYSTEM "-" MICROPY_VERSION_STRING "-" \
109+
PLATFORM_ARCH "-" MICROPY_PLATFORM_VERSION "-with-" PLATFORM_LIBC_LIB "" PLATFORM_LIBC_VER);
110+
STATIC const MP_DEFINE_STR_OBJ(info_python_compiler_obj, PLATFORM_COMPILER);
111+
STATIC const MP_DEFINE_STR_OBJ(info_libc_lib_obj, PLATFORM_LIBC_LIB);
112+
STATIC const MP_DEFINE_STR_OBJ(info_libc_ver_obj, PLATFORM_LIBC_VER);
113+
STATIC const mp_rom_obj_tuple_t info_libc_tuple_obj = {
114+
{&mp_type_tuple}, 2, {MP_ROM_PTR(&info_libc_lib_obj), MP_ROM_PTR(&info_libc_ver_obj)}
115+
};
116+
117+
STATIC mp_obj_t platform_platform(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
118+
return MP_OBJ_FROM_PTR(&info_platform_obj);
119+
}
120+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_platform_obj, 0, platform_platform);
121+
122+
STATIC mp_obj_t platform_python_compiler(void) {
123+
return MP_OBJ_FROM_PTR(&info_python_compiler_obj);
124+
}
125+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(platform_python_compiler_obj, platform_python_compiler);
126+
127+
STATIC mp_obj_t platform_libc_ver(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
128+
return MP_OBJ_FROM_PTR(&info_libc_tuple_obj);
129+
}
130+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_libc_ver_obj, 0, platform_libc_ver);
131+
132+
STATIC const mp_rom_map_elem_t modplatform_globals_table[] = {
133+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uplatform) },
134+
{ MP_ROM_QSTR(MP_QSTR_platform), MP_ROM_PTR(&platform_platform_obj) },
135+
{ MP_ROM_QSTR(MP_QSTR_python_compiler), MP_ROM_PTR(&platform_python_compiler_obj) },
136+
{ MP_ROM_QSTR(MP_QSTR_libc_ver), MP_ROM_PTR(&platform_libc_ver_obj) },
137+
};
138+
139+
STATIC MP_DEFINE_CONST_DICT(modplatform_globals, modplatform_globals_table);
140+
141+
const mp_obj_module_t mp_module_uplatform = {
142+
.base = { &mp_type_module },
143+
.globals = (mp_obj_dict_t *)&modplatform_globals,
144+
};
145+
146+
#endif // MICROPY_PY_UPLATFORM

extmod/modure.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,16 @@ MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure, MICROPY_PY_URE);
477477
// only if module is enabled by config setting.
478478

479479
#define re1_5_fatal(x) assert(!x)
480+
480481
#include "lib/re1.5/compilecode.c"
482+
#include "lib/re1.5/recursiveloop.c"
483+
#include "lib/re1.5/charclass.c"
484+
481485
#if MICROPY_PY_URE_DEBUG
486+
// Make sure the output print statements go to the same output as other Python output.
487+
#define printf(...) mp_printf(&mp_plat_print, __VA_ARGS__)
482488
#include "lib/re1.5/dumpcode.c"
489+
#undef printf
483490
#endif
484-
#include "lib/re1.5/recursiveloop.c"
485-
#include "lib/re1.5/charclass.c"
486491

487492
#endif // MICROPY_PY_URE

extmod/uasyncio/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self):
3636
self.state = None
3737
self.exc = StopIteration()
3838

39-
def __iter__(self):
39+
def __await__(self):
4040
return self
4141

4242
def __next__(self):

extmod/uasyncio/funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def gather(*aws, return_exceptions=False):
6666
# # cancel all waiting tasks
6767
# raise er
6868
ts[i] = await ts[i]
69-
except Exception as er:
69+
except (core.CancelledError, Exception) as er:
7070
if return_exceptions:
7171
ts[i] = er
7272
else:

extmod/uasyncio/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(self, coro, globals=None):
130130
self.ph_next = None # Paring heap
131131
self.ph_rightmost_parent = None # Paring heap
132132

133-
def __iter__(self):
133+
def __await__(self):
134134
if not self.state:
135135
# Task finished, signal that is has been await'ed on.
136136
self.state = False

extmod/vfs_posix_file.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#ifdef _WIN32
1919
#define fsync _commit
20+
#else
21+
#include <poll.h>
2022
#endif
2123

2224
typedef struct _mp_obj_vfs_posix_file_t {
@@ -180,6 +182,32 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
180182
return 0;
181183
case MP_STREAM_GET_FILENO:
182184
return o->fd;
185+
#if MICROPY_PY_USELECT
186+
case MP_STREAM_POLL: {
187+
#ifdef _WIN32
188+
mp_raise_NotImplementedError(MP_ERROR_TEXT("poll on file not available on win32"));
189+
#else
190+
mp_uint_t ret = 0;
191+
uint8_t pollevents = 0;
192+
if (arg & MP_STREAM_POLL_RD) {
193+
pollevents |= POLLIN;
194+
}
195+
if (arg & MP_STREAM_POLL_WR) {
196+
pollevents |= POLLOUT;
197+
}
198+
struct pollfd pfd = { .fd = o->fd, .events = pollevents };
199+
if (poll(&pfd, 1, 0) > 0) {
200+
if (pfd.revents & POLLIN) {
201+
ret |= MP_STREAM_POLL_RD;
202+
}
203+
if (pfd.revents & POLLOUT) {
204+
ret |= MP_STREAM_POLL_WR;
205+
}
206+
}
207+
return ret;
208+
#endif
209+
}
210+
#endif
183211
default:
184212
*errcode = EINVAL;
185213
return MP_STREAM_ERROR;

locale/circuitpython.pot

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,6 +2886,10 @@ msgstr ""
28862886
msgid "can't load with '%q' index"
28872887
msgstr ""
28882888

2889+
#: py/builtinimport.c
2890+
msgid "can't perform relative import"
2891+
msgstr ""
2892+
28892893
#: py/objgenerator.c
28902894
msgid "can't send non-None value to a just-started generator"
28912895
msgstr ""
@@ -2948,10 +2952,6 @@ msgstr ""
29482952
msgid "cannot import name %q"
29492953
msgstr ""
29502954

2951-
#: py/builtinimport.c
2952-
msgid "cannot perform relative import"
2953-
msgstr ""
2954-
29552955
#: extmod/moductypes.c
29562956
msgid "cannot unambiguously get sizeof scalar"
29572957
msgstr ""
@@ -3642,7 +3642,7 @@ msgstr ""
36423642
msgid "matrix is not positive definite"
36433643
msgstr ""
36443644

3645-
#: shared-bindings/wifi/Radio.c
3645+
#: ports/espressif/common-hal/wifi/Radio.c
36463646
msgid "max_connections must be between 0 and 10"
36473647
msgstr ""
36483648

@@ -4023,6 +4023,10 @@ msgstr ""
40234023
msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter"
40244024
msgstr ""
40254025

4026+
#: extmod/vfs_posix_file.c
4027+
msgid "poll on file not available on win32"
4028+
msgstr ""
4029+
40264030
#: shared-module/vectorio/Polygon.c
40274031
msgid "polygon can only be registered in one parent"
40284032
msgstr ""
@@ -4068,6 +4072,7 @@ msgstr ""
40684072
#: ports/espressif/boards/crumpspace_crumps2/mpconfigboard.h
40694073
#: ports/espressif/boards/electroniccats_bastwifi/mpconfigboard.h
40704074
#: ports/espressif/boards/espressif_esp32c3_devkitm_1_n4/mpconfigboard.h
4075+
#: ports/espressif/boards/espressif_esp32s2_devkitc_1_n4r2/mpconfigboard.h
40714076
#: ports/espressif/boards/espressif_esp32s3_box/mpconfigboard.h
40724077
#: ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/mpconfigboard.h
40734078
#: ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/mpconfigboard.h

main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ STATIC void start_mp(supervisor_allocation *heap, bool first_run) {
162162
mp_obj_list_init((mp_obj_list_t *)mp_sys_path, 0);
163163
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
164164
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
165-
// Frozen modules are in their own pseudo-dir, e.g., ".frozen".
166-
// Prioritize .frozen over /lib.
167-
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_FROZEN_FAKE_DIR_QSTR));
165+
#if MICROPY_MODULE_FROZEN
166+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
167+
#endif
168168
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
169169

170170
mp_obj_list_init((mp_obj_list_t *)mp_sys_argv, 0);

0 commit comments

Comments
 (0)