summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-01-13 18:15:32 -0500
committerDan Halbert <halbert@halwitz.org>2020-01-13 18:15:32 -0500
commit2a75196aa3598b3daf4c6fcebdc47dcad597b332 (patch)
tree7c615930405baea093ec7c61e29dcf91c3b6c01b /py
parent4ad004f24eb79a382f1e6230f8ff02784d469d87 (diff)
parent2eb26a6d0b48fb82932190f67475ec101969d3ac (diff)
merge from adafruit/circuitpython
Diffstat (limited to 'py')
-rw-r--r--py/circuitpy_defns.mk3
-rw-r--r--py/circuitpy_mpconfig.h9
-rw-r--r--py/circuitpy_mpconfig.mk7
-rw-r--r--py/obj.c2
-rw-r--r--py/objlist.c8
-rw-r--r--py/objnamedtuple.c12
-rw-r--r--py/objnamedtuple.h1
-rw-r--r--py/objtuple.c1
-rw-r--r--py/objtype.c10
-rw-r--r--py/py.mk2
-rw-r--r--py/vstr.c3
11 files changed, 46 insertions, 12 deletions
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index 8dd4fc6b1..1f2d6c73e 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -236,6 +236,7 @@ SRC_COMMON_HAL_ALL = \
_bleio/CharacteristicBuffer.c \
_bleio/Connection.c \
_bleio/Descriptor.c \
+ _bleio/PacketBuffer.c \
_bleio/Service.c \
_bleio/UUID.c \
analogio/AnalogIn.c \
@@ -322,7 +323,7 @@ SRC_SHARED_MODULE_ALL = \
audiomixer/Mixer.c \
audiomixer/MixerVoice.c \
audiomp3/__init__.c \
- audiomp3/MP3File.c \
+ audiomp3/MP3Decoder.c \
bitbangio/I2C.c \
bitbangio/OneWire.c \
bitbangio/SPI.c \
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index 3161938c4..5b705a088 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -182,7 +182,10 @@ typedef long mp_off_t;
// Remove some lesser-used functionality to make small builds fit.
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (CIRCUITPY_FULL_BUILD)
-#define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD)
+//TODO: replace this with a rework of the FULL_BUILD system
+#if !defined(MICROPY_CPYTHON_COMPAT)
+ #define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD)
+#endif
#define MICROPY_MODULE_WEAK_LINKS (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_BUILTINS_COMPLEX (CIRCUITPY_FULL_BUILD)
@@ -193,7 +196,9 @@ typedef long mp_off_t;
#define MICROPY_PY_UERRNO (CIRCUITPY_FULL_BUILD)
// Opposite setting is deliberate.
#define MICROPY_PY_UERRNO_ERRORCODE (!CIRCUITPY_FULL_BUILD)
+#ifndef MICROPY_PY_URE
#define MICROPY_PY_URE (CIRCUITPY_FULL_BUILD)
+#endif
#define MICROPY_PY_URE_MATCH_GROUPS (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_URE_MATCH_SPAN_START_END (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_URE_SUB (CIRCUITPY_FULL_BUILD)
@@ -326,7 +331,9 @@ extern const struct _mp_obj_module_t terminalio_module;
#define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module },
#define FONTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_fontio), (mp_obj_t)&fontio_module },
#define TERMINALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_terminalio), (mp_obj_t)&terminalio_module },
+#ifndef CIRCUITPY_DISPLAY_LIMIT
#define CIRCUITPY_DISPLAY_LIMIT (1)
+#endif
#else
#define DISPLAYIO_MODULE
#define FONTIO_MODULE
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index a464583f3..93175e136 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -310,6 +310,13 @@ CIRCUITPY_BITBANG_APA102 = 0
endif
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
+# Should busio.I2C() check for pullups?
+# Some boards in combination with certain peripherals may not want this.
+ifndef CIRCUITPY_REQUIRE_I2C_PULLUPS
+CIRCUITPY_REQUIRE_I2C_PULLUPS = 1
+endif
+CFLAGS += -DCIRCUITPY_REQUIRE_I2C_PULLUPS=$(CIRCUITPY_REQUIRE_I2C_PULLUPS)
+
# REPL over BLE
ifndef CIRCUITPY_SERIAL_BLE
CIRCUITPY_SERIAL_BLE = 0
diff --git a/py/obj.c b/py/obj.c
index bd2aaf9d2..09e71be4d 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -489,6 +489,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
mp_obj_type_t *type = mp_obj_get_type(base);
+
if (type->subscr != NULL) {
mp_obj_t ret = type->subscr(base, index, value);
// May have called port specific C code. Make sure it didn't mess up the heap.
@@ -496,7 +497,6 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
if (ret != MP_OBJ_NULL) {
return ret;
}
- // TODO: call base classes here?
}
if (value == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
diff --git a/py/objlist.c b/py/objlist.c
index ea38e64e5..b32f82085 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -159,11 +159,11 @@ STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
}
STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
+ mp_obj_list_t *self = mp_instance_cast_to_native_base(self_in, &mp_type_list);
if (value == MP_OBJ_NULL) {
// delete
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
- mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
mp_raise_NotImplementedError(NULL);
@@ -179,12 +179,11 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
return mp_const_none;
}
#endif
- mp_obj_t args[2] = {self_in, index};
+ mp_obj_t args[2] = {self, index};
list_pop(2, args);
return mp_const_none;
} else if (value == MP_OBJ_SENTINEL) {
// load
- mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
mp_bound_slice_t slice;
@@ -201,7 +200,6 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
} else {
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
- mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
size_t value_len; mp_obj_t *value_items;
mp_obj_get_array(value, &value_len, &value_items);
mp_bound_slice_t slice_out;
@@ -230,7 +228,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
return mp_const_none;
}
#endif
- mp_obj_list_store(self_in, index, value);
+ mp_obj_list_store(self, index, value);
return mp_const_none;
}
}
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c
index a044fe3ff..a0a64f9b2 100644
--- a/py/objnamedtuple.c
+++ b/py/objnamedtuple.c
@@ -31,6 +31,7 @@
#include "py/runtime.h"
#include "py/objstr.h"
#include "py/objnamedtuple.h"
+#include "py/objtype.h"
#include "supervisor/shared/translate.h"
@@ -70,6 +71,15 @@ void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t ki
mp_obj_attrtuple_print_helper(print, fields, &o->tuple);
}
+mp_obj_t namedtuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
+ mp_obj_type_t *type = mp_obj_get_type(self_in);
+ // Check for subclasses of namedtuple and unpack if needed.
+ if (type->parent != &mp_type_tuple) {
+ self_in = ((mp_obj_instance_t*) self_in)->subobj[0];
+ }
+ return mp_obj_tuple_subscr(self_in, index, value);
+}
+
void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
if (dest[0] == MP_OBJ_NULL) {
// load attribute
@@ -167,7 +177,7 @@ STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t
o->base.unary_op = mp_obj_tuple_unary_op;
o->base.binary_op = mp_obj_tuple_binary_op;
o->base.attr = namedtuple_attr;
- o->base.subscr = mp_obj_tuple_subscr;
+ o->base.subscr = namedtuple_subscr;
o->base.getiter = mp_obj_tuple_getiter;
o->base.parent = &mp_type_tuple;
return MP_OBJ_FROM_PTR(o);
diff --git a/py/objnamedtuple.h b/py/objnamedtuple.h
index 0ea0d2862..5a7512e3a 100644
--- a/py/objnamedtuple.h
+++ b/py/objnamedtuple.h
@@ -49,6 +49,7 @@ typedef struct _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);
+mp_obj_t namedtuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
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, const mp_obj_t *args, mp_map_t *kw_args);
diff --git a/py/objtuple.c b/py/objtuple.c
index ed13cdcef..2b483f8b8 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -178,6 +178,7 @@ mp_obj_t mp_obj_tuple_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
}
mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
+
if (value == MP_OBJ_SENTINEL) {
// load
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
diff --git a/py/objtype.c b/py/objtype.c
index 0212a78da..a5e733208 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -34,6 +34,7 @@
#include "py/objtype.h"
#include "py/runtime.h"
+#include "supervisor/shared/stack.h"
#include "supervisor/shared/translate.h"
#if MICROPY_DEBUG_VERBOSE // print debugging info
@@ -851,8 +852,13 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
mp_obj_class_lookup(&lookup, self->base.type);
meth_args = 3;
}
- if (member[0] == MP_OBJ_SENTINEL) {
- return mp_obj_subscr(self->subobj[0], index, value);
+ if (member[0] == MP_OBJ_SENTINEL) { // native base subscr exists
+ mp_obj_type_t *subobj_type = mp_obj_get_type(self->subobj[0]);
+ // return mp_obj_subscr(self->subobj[0], index, value, instance);
+ mp_obj_t ret = subobj_type->subscr(self_in, index, value);
+ // May have called port specific C code. Make sure it didn't mess up the heap.
+ assert_heap_ok();
+ return ret;
} else if (member[0] != MP_OBJ_NULL) {
mp_obj_t args[3] = {self_in, index, value};
// TODO probably need to call mp_convert_member_lookup, and use mp_call_method_n_kw
diff --git a/py/py.mk b/py/py.mk
index 0c68e9af1..9031c009f 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -317,7 +317,7 @@ SRC_QSTR += $(HEADER_BUILD)/moduledefs.h
# overall config, so they need to be caught
MPCONFIGPORT_MK = $(wildcard mpconfigport.mk)
-$(HEADER_BUILD)/$(TRANSLATION).mo: $(TOP)/locale/$(TRANSLATION).po
+$(HEADER_BUILD)/$(TRANSLATION).mo: $(TOP)/locale/$(TRANSLATION).po | $(HEADER_BUILD)
$(Q)msgfmt -o $@ $^
$(HEADER_BUILD)/qstrdefs.preprocessed.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEFS_COLLECTED) mpconfigport.h $(MPCONFIGPORT_MK) $(PY_SRC)/mpconfig.h | $(HEADER_BUILD)
diff --git a/py/vstr.c b/py/vstr.c
index 869b27805..91cd7f584 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -50,6 +50,9 @@ void vstr_init(vstr_t *vstr, size_t alloc) {
// Init the vstr so it allocs exactly enough ram to hold a null-terminated
// string of the given length, and set the length.
void vstr_init_len(vstr_t *vstr, size_t len) {
+ if(len == SIZE_MAX) {
+ m_malloc_fail(len);
+ }
vstr_init(vstr, len + 1);
vstr->len = len;
}