summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-09-14 10:44:31 -0400
committerLucian Copeland <hierophect@gmail.com>2020-09-14 10:44:31 -0400
commitecc219fe504f348d5dceb13b0a12d04d1c858781 (patch)
tree3e6d79d558e821e3daac90b711275be5c0153015 /py
parentf95ad7b27c040e54daeb4c71d6bb6c35844be66e (diff)
parent94e261370b4ffc7739d6e3e0ca99db9f36f3027b (diff)
Merge remote-tracking branch 'upstream/main' into esp32-displayio-fix
Diffstat (limited to 'py')
-rw-r--r--py/binary.c9
-rw-r--r--py/circuitpy_defns.mk24
-rw-r--r--py/circuitpy_mpconfig.h41
-rw-r--r--py/circuitpy_mpconfig.mk18
-rw-r--r--py/makeqstrdata.py41
-rw-r--r--py/modbuiltins.c3
-rw-r--r--py/modstruct.c17
-rw-r--r--py/obj.h2
-rw-r--r--py/objarray.c7
-rw-r--r--py/objexcept.c10
-rw-r--r--py/objset.c1
-rw-r--r--py/runtime.c8
-rw-r--r--py/runtime.h2
13 files changed, 163 insertions, 20 deletions
diff --git a/py/binary.c b/py/binary.c
index cd0f1aa4d..b85edba62 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -126,7 +126,6 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
break;
case BYTEARRAY_TYPECODE:
case 'B':
- case 'x': // value will be discarded
val = ((unsigned char*)p)[index];
break;
case 'h':
@@ -330,7 +329,11 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
}
}
- mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val);
+ if (val_type == 'x') {
+ memset(p, 0, 1);
+ } else {
+ mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val);
+ }
}
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in) {
@@ -379,8 +382,6 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
case 'B':
((unsigned char*)p)[index] = val;
break;
- case 'x':
- ((unsigned char*)p)[index] = 0;
case 'h':
((short*)p)[index] = val;
break;
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index 36524b2fb..0e87287c1 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -31,6 +31,7 @@ BASE_CFLAGS = \
-fsingle-precision-constant \
-fno-strict-aliasing \
-Wdouble-promotion \
+ -Wimplicit-fallthrough=2 \
-Wno-endif-labels \
-Wstrict-prototypes \
-Werror-implicit-function-declaration \
@@ -168,6 +169,9 @@ endif
ifeq ($(CIRCUITPY_I2CPERIPHERAL),1)
SRC_PATTERNS += i2cperipheral/%
endif
+ifeq ($(CIRCUITPY_IPADDRESS),1)
+SRC_PATTERNS += ipaddress/%
+endif
ifeq ($(CIRCUITPY_MATH),1)
SRC_PATTERNS += math/%
endif
@@ -228,6 +232,12 @@ endif
ifeq ($(CIRCUITPY_SHARPDISPLAY),1)
SRC_PATTERNS += sharpdisplay/%
endif
+ifeq ($(CIRCUITPY_SOCKETPOOL),1)
+SRC_PATTERNS += socketpool/%
+endif
+ifeq ($(CIRCUITPY_SSL),1)
+SRC_PATTERNS += ssl/%
+endif
ifeq ($(CIRCUITPY_STAGE),1)
SRC_PATTERNS += _stage/%
endif
@@ -264,6 +274,9 @@ endif
ifeq ($(CIRCUITPY_WATCHDOG),1)
SRC_PATTERNS += watchdog/%
endif
+ifeq ($(CIRCUITPY_WIFI),1)
+SRC_PATTERNS += wifi/%
+endif
ifeq ($(CIRCUITPY_PEW),1)
SRC_PATTERNS += _pew/%
endif
@@ -332,11 +345,20 @@ SRC_COMMON_HAL_ALL = \
rtc/__init__.c \
sdioio/SDCard.c \
sdioio/__init__.c \
+ socketpool/__init__.c \
+ socketpool/SocketPool.c \
+ socketpool/Socket.c \
+ ssl/__init__.c \
+ ssl/SSLContext.c \
supervisor/Runtime.c \
supervisor/__init__.c \
watchdog/WatchDogMode.c \
watchdog/WatchDogTimer.c \
watchdog/__init__.c \
+ wifi/Network.c \
+ wifi/Radio.c \
+ wifi/ScannedNetworks.c \
+ wifi/__init__.c \
ifeq ($(CIRCUITPY_BLEIO_HCI),1)
# Helper code for _bleio HCI.
@@ -414,6 +436,8 @@ SRC_SHARED_MODULE_ALL = \
fontio/__init__.c \
framebufferio/FramebufferDisplay.c \
framebufferio/__init__.c \
+ ipaddress/IPv4Address.c \
+ ipaddress/__init__.c \
sdcardio/SDCard.c \
sdcardio/__init__.c \
gamepad/GamePad.c \
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index d144f0ba8..0fafbe876 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -364,6 +364,13 @@ extern const struct _mp_obj_module_t terminalio_module;
#define TERMINALIO_MODULE
#endif
+#if CIRCUITPY_ESPIDF
+extern const struct _mp_obj_module_t espidf_module;
+#define ESPIDF_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_espidf),(mp_obj_t)&espidf_module },
+#else
+#define ESPIDF_MODULE
+#endif
+
#if CIRCUITPY_FRAMEBUFFERIO
extern const struct _mp_obj_module_t framebufferio_module;
#define FRAMEBUFFERIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_framebufferio), (mp_obj_t)&framebufferio_module },
@@ -421,6 +428,13 @@ extern const struct _mp_obj_module_t i2cperipheral_module;
#define I2CPERIPHERAL_MODULE
#endif
+#if CIRCUITPY_IPADDRESS
+extern const struct _mp_obj_module_t ipaddress_module;
+#define IPADDRESS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ipaddress), (mp_obj_t)&ipaddress_module },
+#else
+#define IPADDRESS_MODULE
+#endif
+
#if CIRCUITPY_MATH
extern const struct _mp_obj_module_t math_module;
#define MATH_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module },
@@ -574,6 +588,7 @@ extern const struct _mp_obj_module_t sdioio_module;
#define SDIOIO_MODULE
#endif
+
#if CIRCUITPY_SHARPDISPLAY
extern const struct _mp_obj_module_t sharpdisplay_module;
#define SHARPDISPLAY_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_sharpdisplay),(mp_obj_t)&sharpdisplay_module },
@@ -581,6 +596,20 @@ extern const struct _mp_obj_module_t sharpdisplay_module;
#define SHARPDISPLAY_MODULE
#endif
+#if CIRCUITPY_SOCKETPOOL
+extern const struct _mp_obj_module_t socketpool_module;
+#define SOCKETPOOL_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_socketpool), (mp_obj_t)&socketpool_module },
+#else
+#define SOCKETPOOL_MODULE
+#endif
+
+#if CIRCUITPY_SSL
+extern const struct _mp_obj_module_t ssl_module;
+#define SSL_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ssl), (mp_obj_t)&ssl_module },
+#else
+#define SSL_MODULE
+#endif
+
#if CIRCUITPY_STAGE
extern const struct _mp_obj_module_t stage_module;
#define STAGE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__stage), (mp_obj_t)&stage_module },
@@ -691,6 +720,13 @@ extern const struct _mp_obj_module_t watchdog_module;
#define WATCHDOG_MODULE
#endif
+#if CIRCUITPY_WIFI
+extern const struct _mp_obj_module_t wifi_module;
+#define WIFI_MODULE { MP_ROM_QSTR(MP_QSTR_wifi), MP_ROM_PTR(&wifi_module) },
+#else
+#define WIFI_MODULE
+#endif
+
// Define certain native modules with weak links so they can be replaced with Python
// implementations. This list may grow over time.
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
@@ -729,12 +765,14 @@ extern const struct _mp_obj_module_t watchdog_module;
TERMINALIO_MODULE \
VECTORIO_MODULE \
ERRNO_MODULE \
+ ESPIDF_MODULE \
FRAMEBUFFERIO_MODULE \
FREQUENCYIO_MODULE \
GAMEPAD_MODULE \
GAMEPADSHIFT_MODULE \
GNSS_MODULE \
I2CPERIPHERAL_MODULE \
+ IPADDRESS_MODULE \
JSON_MODULE \
MATH_MODULE \
_EVE_MODULE \
@@ -758,6 +796,8 @@ extern const struct _mp_obj_module_t watchdog_module;
SDCARDIO_MODULE \
SDIOIO_MODULE \
SHARPDISPLAY_MODULE \
+ SOCKETPOOL_MODULE \
+ SSL_MODULE \
STAGE_MODULE \
STORAGE_MODULE \
STRUCT_MODULE \
@@ -768,6 +808,7 @@ extern const struct _mp_obj_module_t watchdog_module;
USB_MIDI_MODULE \
USTACK_MODULE \
WATCHDOG_MODULE \
+ WIFI_MODULE \
// If weak links are enabled, just include strong links in the main list of modules,
// and also include the underscore alternate names.
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index 90e8b5fde..a2da9c42f 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -99,6 +99,12 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
+# CIRCUITPY_ESPIDF is handled in the esp32s2 tree.
+# Only for ESP32S chips.
+# Assume not a ESP build.
+CIRCUITPY_ESPIDF ?= 0
+CFLAGS += -DCIRCUITPY_ESPIDF=$(CIRCUITPY_ESPIDF)
+
ifeq ($(CIRCUITPY_DISPLAYIO),1)
CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD)
else
@@ -124,6 +130,9 @@ CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS)
CIRCUITPY_I2CPERIPHERAL ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_I2CPERIPHERAL=$(CIRCUITPY_I2CPERIPHERAL)
+CIRCUITPY_IPADDRESS ?= $(CIRCUITPY_WIFI)
+CFLAGS += -DCIRCUITPY_IPADDRESS=$(CIRCUITPY_IPADDRESS)
+
CIRCUITPY_MATH ?= 1
CFLAGS += -DCIRCUITPY_MATH=$(CIRCUITPY_MATH)
@@ -191,6 +200,12 @@ CFLAGS += -DCIRCUITPY_SDIOIO=$(CIRCUITPY_SDIOIO)
CIRCUITPY_SHARPDISPLAY ?= $(CIRCUITPY_FRAMEBUFFERIO)
CFLAGS += -DCIRCUITPY_SHARPDISPLAY=$(CIRCUITPY_SHARPDISPLAY)
+CIRCUITPY_SOCKETPOOL ?= $(CIRCUITPY_WIFI)
+CFLAGS += -DCIRCUITPY_SOCKETPOOL=$(CIRCUITPY_SOCKETPOOL)
+
+CIRCUITPY_SSL ?= $(CIRCUITPY_WIFI)
+CFLAGS += -DCIRCUITPY_SSL=$(CIRCUITPY_SSL)
+
# Currently always off.
CIRCUITPY_STAGE ?= 0
CFLAGS += -DCIRCUITPY_STAGE=$(CIRCUITPY_STAGE)
@@ -263,6 +278,9 @@ CFLAGS += -DCIRCUITPY_ULAB=$(CIRCUITPY_ULAB)
CIRCUITPY_WATCHDOG ?= 0
CFLAGS += -DCIRCUITPY_WATCHDOG=$(CIRCUITPY_WATCHDOG)
+CIRCUITPY_WIFI ?= 0
+CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
+
# Enabled micropython.native decorator (experimental)
CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index 04c893876..721fa8320 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -100,9 +100,30 @@ def translate(translation_file, i18ns):
translations.append((original, translation))
return translations
+def frequent_ngrams(corpus, sz, n):
+ return collections.Counter(corpus[i:i+sz] for i in range(len(corpus)-sz)).most_common(n)
+
+def encode_ngrams(translation, ngrams):
+ if len(ngrams) > 32:
+ start = 0xe000
+ else:
+ start = 0x80
+ for i, g in enumerate(ngrams):
+ translation = translation.replace(g, chr(start + i))
+ return translation
+
+def decode_ngrams(compressed, ngrams):
+ if len(ngrams) > 32:
+ start, end = 0xe000, 0xf8ff
+ else:
+ start, end = 0x80, 0x9f
+ return "".join(ngrams[ord(c) - start] if (start <= ord(c) <= end) else c for c in compressed)
+
def compute_huffman_coding(translations, qstrs, compression_filename):
all_strings = [x[1] for x in translations]
all_strings_concat = "".join(all_strings)
+ ngrams = [i[0] for i in frequent_ngrams(all_strings_concat, 2, 32)]
+ all_strings_concat = encode_ngrams(all_strings_concat, ngrams)
counts = collections.Counter(all_strings_concat)
cb = huffman.codebook(counts.items())
values = []
@@ -125,10 +146,12 @@ def compute_huffman_coding(translations, qstrs, compression_filename):
last_l = l
lengths = bytearray()
print("// length count", length_count)
+ print("// bigrams", ngrams)
for i in range(1, max(length_count) + 2):
lengths.append(length_count.get(i, 0))
print("// values", values, "lengths", len(lengths), lengths)
- print("// estimated total memory size", len(lengths) + 2*len(values) + sum(len(cb[u]) for u in all_strings_concat))
+ ngramdata = [ord(ni) for i in ngrams for ni in i]
+ print("// estimated total memory size", len(lengths) + 2*len(values) + 2 * len(ngramdata) + sum((len(cb[u]) + 7)//8 for u in all_strings_concat))
print("//", values, lengths)
values_type = "uint16_t" if max(ord(u) for u in values) > 255 else "uint8_t"
max_translation_encoded_length = max(len(translation.encode("utf-8")) for original,translation in translations)
@@ -136,10 +159,18 @@ def compute_huffman_coding(translations, qstrs, compression_filename):
f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths))))
f.write("const {} values[] = {{ {} }};\n".format(values_type, ", ".join(str(ord(u)) for u in values)))
f.write("#define compress_max_length_bits ({})\n".format(max_translation_encoded_length.bit_length()))
- return values, lengths
+ f.write("const {} bigrams[] = {{ {} }};\n".format(values_type, ", ".join(str(u) for u in ngramdata)))
+ if len(ngrams) > 32:
+ bigram_start = 0xe000
+ else:
+ bigram_start = 0x80
+ bigram_end = bigram_start + len(ngrams) - 1 # End is inclusive
+ f.write("#define bigram_start {}\n".format(bigram_start))
+ f.write("#define bigram_end {}\n".format(bigram_end))
+ return values, lengths, ngrams
def decompress(encoding_table, encoded, encoded_length_bits):
- values, lengths = encoding_table
+ values, lengths, ngrams = encoding_table
dec = []
this_byte = 0
this_bit = 7
@@ -187,6 +218,7 @@ def decompress(encoding_table, encoded, encoded_length_bits):
searched_length += lengths[bit_length]
v = values[searched_length + bits - max_code]
+ v = decode_ngrams(v, ngrams)
i += len(v.encode('utf-8'))
dec.append(v)
return ''.join(dec)
@@ -194,7 +226,8 @@ def decompress(encoding_table, encoded, encoded_length_bits):
def compress(encoding_table, decompressed, encoded_length_bits, len_translation_encoded):
if not isinstance(decompressed, str):
raise TypeError()
- values, lengths = encoding_table
+ values, lengths, ngrams = encoding_table
+ decompressed = encode_ngrams(decompressed, ngrams)
enc = bytearray(len(decompressed) * 3)
#print(decompressed)
#print(lengths)
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index 905c3471f..41e1d4e48 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -726,6 +726,9 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_NameError), MP_ROM_PTR(&mp_type_NameError) },
{ MP_ROM_QSTR(MP_QSTR_NotImplementedError), MP_ROM_PTR(&mp_type_NotImplementedError) },
{ MP_ROM_QSTR(MP_QSTR_OSError), MP_ROM_PTR(&mp_type_OSError) },
+ { MP_ROM_QSTR(MP_QSTR_TimeoutError), MP_ROM_PTR(&mp_type_TimeoutError) },
+ { MP_ROM_QSTR(MP_QSTR_ConnectionError), MP_ROM_PTR(&mp_type_ConnectionError) },
+ { MP_ROM_QSTR(MP_QSTR_BrokenPipeError), MP_ROM_PTR(&mp_type_BrokenPipeError) },
{ MP_ROM_QSTR(MP_QSTR_OverflowError), MP_ROM_PTR(&mp_type_OverflowError) },
{ MP_ROM_QSTR(MP_QSTR_RuntimeError), MP_ROM_PTR(&mp_type_RuntimeError) },
#if MICROPY_PY_ASYNC_AWAIT
diff --git a/py/modstruct.c b/py/modstruct.c
index fe766a4de..7675de275 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -183,16 +183,21 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_from_obj, 2, 3, struct_unpack_
// This function assumes there is enough room in p to store all the values
STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, const mp_obj_t *args) {
+ size_t size;
+ size_t count = calc_size_items(mp_obj_str_get_str(fmt_in), &size);
+ if (count != n_args) {
+#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
+ mp_raise_ValueError(NULL);
+#else
+ mp_raise_ValueError_varg(translate("pack expected %d items for packing (got %d)"), count, n_args);
+#endif
+ }
const char *fmt = mp_obj_str_get_str(fmt_in);
char fmt_type = get_fmt_type(&fmt);
size_t i;
for (i = 0; i < n_args;) {
mp_uint_t cnt = 1;
- if (*fmt == '\0') {
- // more arguments given than used by format string; CPython raises struct.error here
- break;
- }
if (unichar_isdigit(*fmt)) {
cnt = get_fmt_num(&fmt);
}
@@ -208,8 +213,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c
memset(p + to_copy, 0, cnt - to_copy);
p += cnt;
} else {
- // If we run out of args then we just finish; CPython would raise struct.error
- while (cnt-- && i < n_args) {
+ while (cnt--) {
mp_binary_set_val(fmt_type, *fmt, args[i], &p);
// Pad bytes don't have a corresponding argument.
if (*fmt != 'x') {
@@ -222,7 +226,6 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c
}
STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) {
- // TODO: "The arguments must match the values required by the format exactly."
mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
vstr_t vstr;
vstr_init_len(&vstr, size);
diff --git a/py/obj.h b/py/obj.h
index 943e1a389..805b26e48 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -627,6 +627,8 @@ extern const mp_obj_type_t mp_type_NameError;
extern const mp_obj_type_t mp_type_NotImplementedError;
extern const mp_obj_type_t mp_type_OSError;
extern const mp_obj_type_t mp_type_TimeoutError;
+extern const mp_obj_type_t mp_type_ConnectionError;
+extern const mp_obj_type_t mp_type_BrokenPipeError;
extern const mp_obj_type_t mp_type_OverflowError;
extern const mp_obj_type_t mp_type_RuntimeError;
extern const mp_obj_type_t mp_type_StopAsyncIteration;
diff --git a/py/objarray.c b/py/objarray.c
index 5d83f0697..e0b4cbd55 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -97,6 +97,9 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC mp_obj_array_t *array_new(char typecode, size_t n) {
+ if (typecode == 'x') {
+ mp_raise_ValueError(translate("bad typecode"));
+ }
int typecode_size = mp_binary_get_size('@', typecode, NULL);
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
@@ -126,8 +129,10 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
|| (MICROPY_PY_BUILTINS_BYTEARRAY && MP_OBJ_IS_TYPE(initializer, &mp_type_bytearray)))))
&& mp_get_buffer(initializer, &bufinfo, MP_BUFFER_READ)) {
// construct array from raw bytes
- // we round-down the len to make it a multiple of sz (CPython raises error)
size_t sz = mp_binary_get_size('@', typecode, NULL);
+ if (bufinfo.len % sz) {
+ mp_raise_ValueError(translate("bytes length not a multiple of item size"));
+ }
size_t len = bufinfo.len / sz;
mp_obj_array_t *o = array_new(typecode, len);
memcpy(o->items, bufinfo.buf, len * sz);
diff --git a/py/objexcept.c b/py/objexcept.c
index e3b953543..01ba6da9c 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -282,15 +282,17 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
*/
MP_DEFINE_EXCEPTION(OSError, Exception)
- MP_DEFINE_EXCEPTION(TimeoutError, OSError)
- /*
- MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
- MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
+ MP_DEFINE_EXCEPTION(TimeoutError, OSError)
MP_DEFINE_EXCEPTION(ConnectionError, OSError)
MP_DEFINE_EXCEPTION(BrokenPipeError, ConnectionError)
+ /*
MP_DEFINE_EXCEPTION(ConnectionAbortedError, ConnectionError)
MP_DEFINE_EXCEPTION(ConnectionRefusedError, ConnectionError)
MP_DEFINE_EXCEPTION(ConnectionResetError, ConnectionError)
+ */
+ /*
+ MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
+ MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
MP_DEFINE_EXCEPTION(InterruptedError, OSError)
MP_DEFINE_EXCEPTION(IsADirectoryError, OSError)
MP_DEFINE_EXCEPTION(NotADirectoryError, OSError)
diff --git a/py/objset.c b/py/objset.c
index b8f0f07ed..45b5c1260 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -450,6 +450,7 @@ STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
return MP_OBJ_NEW_SMALL_INT(hash);
}
#endif
+ /* FALLTHROUGH */
default: return MP_OBJ_NULL; // op not supported
}
}
diff --git a/py/runtime.c b/py/runtime.c
index f9ef7819d..e63e2337d 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -1602,6 +1602,14 @@ NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...) {
va_end(argptr);
}
+NORETURN void mp_raise_ConnectionError(const compressed_string_t *msg) {
+ mp_raise_msg(&mp_type_ConnectionError, msg);
+}
+
+NORETURN void mp_raise_BrokenPipeError(void) {
+ nlr_raise(mp_obj_new_exception_arg1(&mp_type_BrokenPipeError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE)));
+}
+
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_NotImplementedError, msg);
}
diff --git a/py/runtime.h b/py/runtime.h
index dbc04b94e..ad7d0feab 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -166,6 +166,8 @@ NORETURN void mp_raise_OSError(int errno_);
NORETURN void mp_raise_OSError_errno_str(int errno_, mp_obj_t str);
NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
+NORETURN void mp_raise_ConnectionError(const compressed_string_t *msg);
+NORETURN void mp_raise_BrokenPipeError(void);
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);