summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/asmbase.c2
-rw-r--r--py/binary.c2
-rw-r--r--py/modio.c9
-rw-r--r--py/mpprint.c2
-rw-r--r--py/mpprint.h11
-rw-r--r--py/mpz.c12
-rw-r--r--py/objfloat.c12
-rw-r--r--py/objlist.c101
-rw-r--r--py/parsenum.c4
-rw-r--r--py/persistentcode.c4
10 files changed, 73 insertions, 86 deletions
diff --git a/py/asmbase.c b/py/asmbase.c
index 3fce543a7f..f1b823fa36 100644
--- a/py/asmbase.c
+++ b/py/asmbase.c
@@ -53,7 +53,7 @@ void mp_asm_base_start_pass(mp_asm_base_t *as, int pass) {
} else {
// allocating executable RAM is platform specific
MP_PLAT_ALLOC_EXEC(as->code_offset, (void **)&as->code_base, &as->code_size);
- assert(as->code_base != NULL);
+ assert(as->code_size == 0 || as->code_base != NULL);
}
as->pass = pass;
as->suppress = false;
diff --git a/py/binary.c b/py/binary.c
index 4fc8f751ad..48d3421bca 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -196,7 +196,7 @@ static float mp_decode_half_float(uint16_t hf) {
++e;
}
- fpu.i = ((hf & 0x8000) << 16) | (e << 23) | (m << 13);
+ fpu.i = ((hf & 0x8000u) << 16) | (e << 23) | (m << 13);
return fpu.f;
}
diff --git a/py/modio.c b/py/modio.c
index d3e563dbcf..9aeb42d30a 100644
--- a/py/modio.c
+++ b/py/modio.c
@@ -169,12 +169,13 @@ static mp_obj_t bufwriter_flush(mp_obj_t self_in) {
int err;
mp_uint_t out_sz = mp_stream_write_exactly(self->stream, self->buf, self->len, &err);
(void)out_sz;
- // TODO: try to recover from a case of non-blocking stream, e.g. move
- // remaining chunk to the beginning of buffer.
- assert(out_sz == self->len);
- self->len = 0;
if (err != 0) {
mp_raise_OSError(err);
+ } else {
+ // TODO: try to recover from a case of non-blocking stream, e.g. move
+ // remaining chunk to the beginning of buffer.
+ assert(out_sz == self->len);
+ self->len = 0;
}
}
diff --git a/py/mpprint.c b/py/mpprint.c
index 00a5f944c6..86dbfad05e 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -413,8 +413,6 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
flags |= PF_FLAG_SHOW_SIGN;
} else if (*fmt == ' ') {
flags |= PF_FLAG_SPACE_SIGN;
- } else if (*fmt == '!') {
- flags |= PF_FLAG_NO_TRAILZ;
} else if (*fmt == '0') {
flags |= PF_FLAG_PAD_AFTER_SIGN;
fill = '0';
diff --git a/py/mpprint.h b/py/mpprint.h
index 511af329ba..583f00bda8 100644
--- a/py/mpprint.h
+++ b/py/mpprint.h
@@ -31,12 +31,11 @@
#define PF_FLAG_LEFT_ADJUST (0x001)
#define PF_FLAG_SHOW_SIGN (0x002)
#define PF_FLAG_SPACE_SIGN (0x004)
-#define PF_FLAG_NO_TRAILZ (0x008)
-#define PF_FLAG_SHOW_PREFIX (0x010)
-#define PF_FLAG_PAD_AFTER_SIGN (0x020)
-#define PF_FLAG_CENTER_ADJUST (0x040)
-#define PF_FLAG_ADD_PERCENT (0x080)
-#define PF_FLAG_SHOW_OCTAL_LETTER (0x100)
+#define PF_FLAG_SHOW_PREFIX (0x008)
+#define PF_FLAG_PAD_AFTER_SIGN (0x010)
+#define PF_FLAG_CENTER_ADJUST (0x020)
+#define PF_FLAG_ADD_PERCENT (0x040)
+#define PF_FLAG_SHOW_OCTAL_LETTER (0x080)
#define PF_FLAG_SEP_POS (9) // must be above all the above PF_FLAGs
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
diff --git a/py/mpz.c b/py/mpz.c
index 471bd15981..5a4d7d27d9 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -1537,7 +1537,8 @@ mp_int_t mpz_hash(const mpz_t *z) {
mp_uint_t val = 0;
mpz_dig_t *d = z->dig + z->len;
- while (d-- > z->dig) {
+ while (d > z->dig) {
+ d--;
val = (val << DIG_SIZE) | *d;
}
@@ -1552,11 +1553,12 @@ bool mpz_as_int_checked(const mpz_t *i, mp_int_t *value) {
mp_uint_t val = 0;
mpz_dig_t *d = i->dig + i->len;
- while (d-- > i->dig) {
+ while (d > i->dig) {
if (val > (~(MP_OBJ_WORD_MSBIT_HIGH) >> DIG_SIZE)) {
// will overflow
return false;
}
+ d--;
val = (val << DIG_SIZE) | *d;
}
@@ -1577,11 +1579,12 @@ bool mpz_as_uint_checked(const mpz_t *i, mp_uint_t *value) {
mp_uint_t val = 0;
mpz_dig_t *d = i->dig + i->len;
- while (d-- > i->dig) {
+ while (d > i->dig) {
if (val > (~(MP_OBJ_WORD_MSBIT_HIGH) >> (DIG_SIZE - 1))) {
// will overflow
return false;
}
+ d--;
val = (val << DIG_SIZE) | *d;
}
@@ -1642,7 +1645,8 @@ mp_float_t mpz_as_float(const mpz_t *i) {
mp_float_t val = 0;
mpz_dig_t *d = i->dig + i->len;
- while (d-- > i->dig) {
+ while (d > i->dig) {
+ d--;
val = val * DIG_BASE + *d;
}
diff --git a/py/objfloat.c b/py/objfloat.c
index 0728fce315..81b0daa620 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -34,6 +34,11 @@
#if MICROPY_PY_BUILTINS_FLOAT
+// Workaround a bug in Windows SDK version 10.0.26100.0, where NAN is no longer constant.
+#if defined(_MSC_VER) && !defined(_UCRT_NOISY_NAN)
+#define _UCRT_NOISY_NAN
+#endif
+
#include <math.h>
#include "py/formatfloat.h"
@@ -47,13 +52,6 @@
#define M_PI (3.14159265358979323846)
#endif
-// Workaround a bug in recent MSVC where NAN is no longer constant.
-// (By redefining back to the previous MSVC definition of NAN)
-#if defined(_MSC_VER) && _MSC_VER >= 1942
-#undef NAN
-#define NAN (-(float)(((float)(1e+300 * 1e+300)) * 0.0F))
-#endif
-
typedef struct _mp_obj_float_t {
mp_obj_base_t base;
mp_float_t value;
diff --git a/py/objlist.c b/py/objlist.c
index 9a88de3892..71414a849f 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -159,76 +159,63 @@ 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) {
- 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);
+ #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;
+ bool fast = mp_seq_get_fast_slice_indexes(self->len, index, &slice);
+ if (value == MP_OBJ_SENTINEL) {
+ // load
+ if (!fast) {
+ return mp_seq_extract_slice(self->items, &slice);
}
-
- mp_int_t len_adj = slice.start - slice.stop;
- assert(len_adj <= 0);
- mp_seq_replace_slice_no_grow(self->items, self->len, slice.start, slice.stop, self->items /*NULL*/, 0, sizeof(*self->items));
+ mp_obj_list_t *res = list_new(slice.stop - slice.start);
+ mp_seq_copy(res->items, self->items + slice.start, res->len, mp_obj_t);
+ return MP_OBJ_FROM_PTR(res);
+ }
+ // assign/delete
+ if (value == MP_OBJ_NULL) {
+ // delete is equivalent to slice assignment of an empty sequence
+ value = mp_const_empty_tuple;
+ }
+ if (!fast) {
+ mp_raise_NotImplementedError(NULL);
+ }
+ size_t value_len;
+ mp_obj_t *value_items;
+ mp_obj_get_array(value, &value_len, &value_items);
+ mp_int_t len_adj = value_len - (slice.stop - slice.start);
+ if (len_adj > 0) {
+ if (self->len + len_adj > self->alloc) {
+ // TODO: Might optimize memory copies here by checking if block can
+ // be grown inplace or not
+ self->items = m_renew(mp_obj_t, self->items, self->alloc, self->len + len_adj);
+ self->alloc = self->len + len_adj;
+ }
+ mp_seq_replace_slice_grow_inplace(self->items, self->len,
+ slice.start, slice.stop, value_items, value_len, len_adj, sizeof(*self->items));
+ } else {
+ mp_seq_replace_slice_no_grow(self->items, self->len,
+ slice.start, slice.stop, value_items, value_len, sizeof(*self->items));
// Clear "freed" elements at the end of list
mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items));
- self->len += len_adj;
- return mp_const_none;
+ // TODO: apply allocation policy re: alloc_size
}
- #endif
+ self->len += len_adj;
+ return mp_const_none;
+ }
+ #endif
+ if (value == MP_OBJ_NULL) {
+ // delete
mp_obj_t args[2] = {self_in, 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;
- if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
- return mp_seq_extract_slice(self->items, &slice);
- }
- mp_obj_list_t *res = list_new(slice.stop - slice.start);
- mp_seq_copy(res->items, self->items + slice.start, res->len, mp_obj_t);
- return MP_OBJ_FROM_PTR(res);
- }
- #endif
size_t index_val = mp_get_index(self->base.type, self->len, index, false);
return self->items[index_val];
} 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;
- if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
- mp_raise_NotImplementedError(NULL);
- }
- mp_int_t len_adj = value_len - (slice_out.stop - slice_out.start);
- if (len_adj > 0) {
- if (self->len + len_adj > self->alloc) {
- // TODO: Might optimize memory copies here by checking if block can
- // be grown inplace or not
- self->items = m_renew(mp_obj_t, self->items, self->alloc, self->len + len_adj);
- self->alloc = self->len + len_adj;
- }
- mp_seq_replace_slice_grow_inplace(self->items, self->len,
- slice_out.start, slice_out.stop, value_items, value_len, len_adj, sizeof(*self->items));
- } else {
- mp_seq_replace_slice_no_grow(self->items, self->len,
- slice_out.start, slice_out.stop, value_items, value_len, sizeof(*self->items));
- // Clear "freed" elements at the end of list
- mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items));
- // TODO: apply allocation policy re: alloc_size
- }
- self->len += len_adj;
- return mp_const_none;
- }
- #endif
mp_obj_list_store(self_in, index, value);
return mp_const_none;
}
diff --git a/py/parsenum.c b/py/parsenum.c
index 300b5f28de..7e6695fbfc 100644
--- a/py/parsenum.c
+++ b/py/parsenum.c
@@ -227,13 +227,13 @@ mp_obj_t mp_parse_num_float(const char *str, size_t len, bool allow_imag, mp_lex
const char *top = str + len;
mp_float_t dec_val = 0;
- bool dec_neg = false;
#if MICROPY_PY_BUILTINS_COMPLEX
unsigned int real_imag_state = REAL_IMAG_STATE_START;
mp_float_t dec_real = 0;
-parse_start:
+parse_start:;
#endif
+ bool dec_neg = false;
// skip leading space
for (; str < top && unichar_isspace(*str); str++) {
diff --git a/py/persistentcode.c b/py/persistentcode.c
index 43207a0cc8..6ec0717f94 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -759,7 +759,7 @@ static void bit_vector_clear(bit_vector_t *self) {
static bool bit_vector_is_set(bit_vector_t *self, size_t index) {
const size_t bits_size = sizeof(*self->bits) * MP_BITS_PER_BYTE;
return index / bits_size < self->alloc
- && (self->bits[index / bits_size] & (1 << (index % bits_size))) != 0;
+ && (self->bits[index / bits_size] & ((uintptr_t)1 << (index % bits_size))) != 0;
}
static void bit_vector_set(bit_vector_t *self, size_t index) {
@@ -770,7 +770,7 @@ static void bit_vector_set(bit_vector_t *self, size_t index) {
self->bits = m_renew(uintptr_t, self->bits, self->alloc, new_alloc);
self->alloc = new_alloc;
}
- self->bits[index / bits_size] |= 1 << (index % bits_size);
+ self->bits[index / bits_size] |= (uintptr_t)1 << (index % bits_size);
}
typedef struct _mp_opcode_t {