From 599bbc111cbd83329e9418cefd1ed62ca2ed984c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 18 Apr 2014 04:11:19 +0300 Subject: [PATCH 1/4] py: from import * should not import symbols starting with underscore. I skipped implementing this initially, but then it causes __name__ of current module be overwritten and relative imports fail. --- py/runtime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/py/runtime.c b/py/runtime.c index 7830301c77..30db01cd53 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1060,10 +1060,14 @@ import_error: void mp_import_all(mp_obj_t module) { DEBUG_printf("import all %p\n", module); + // TODO: Support __all__ mp_map_t *map = mp_obj_dict_get_map(mp_obj_module_get_globals(module)); for (uint i = 0; i < map->alloc; i++) { if (MP_MAP_SLOT_IS_FILLED(map, i)) { - mp_store_name(MP_OBJ_QSTR_VALUE(map->table[i].key), map->table[i].value); + qstr name = MP_OBJ_QSTR_VALUE(map->table[i].key); + if (*qstr_str(name) != '_') { + mp_store_name(name, map->table[i].value); + } } } } From 7de5377ca7eeb7828031f83be417cda3a188069b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 18 Apr 2014 21:12:52 +0300 Subject: [PATCH 2/4] objfloat: Try to achieve the same float printing format as CPython does. Test usecase I used is print(time.time()) and print(time.time() - time.time()). On Linux/Glibc they now give the same output as CPython 3.3. Specifically, time.time() gives non-exponential output with 7 decimal digits, and subtraction gives exponential output e-06/e-07. --- py/objfloat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/objfloat.c b/py/objfloat.c index 804101978e..9249160579 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -30,7 +30,7 @@ STATIC void float_print(void (*print)(void *env, const char *fmt, ...), void *en } #else char buf[32]; - sprintf(buf, "%.8g", (double) o->value); + sprintf(buf, "%.17g", (double) o->value); print(env, buf); if (strchr(buf, '.') == NULL) { // Python floats always have decimal point From 83eba5dec5b8ed7134a2a27a8824d271acee5711 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 18 Apr 2014 21:42:54 +0300 Subject: [PATCH 3/4] sequence: Fix glaring bug in sequence comparison. --- py/sequence.c | 19 +++++++++++++------ tests/basics/tuple_compare.py | 5 +++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/py/sequence.c b/py/sequence.c index 3a4d65d53b..7ea3f708f1 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -1,3 +1,4 @@ +#include #include #include @@ -109,18 +110,24 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t * int len = len1 < len2 ? len1 : len2; bool eq_status = true; // empty lists are equal - bool rel_status; for (int i = 0; i < len; i++) { eq_status = mp_obj_equal(items1[i], items2[i]); - if (op == MP_BINARY_OP_EQUAL && !eq_status) { - return false; - } - rel_status = (mp_binary_op(op, items1[i], items2[i]) == mp_const_true); - if (!eq_status && !rel_status) { + // If current elements equal, can't decide anything - go on + if (eq_status) { + continue; + } + + // Othewise, if they are not equal, we can have final decision based on them + if (op == MP_BINARY_OP_EQUAL) { + // In particular, if we are checking for equality, here're the answer return false; } + + // Otherwise, application of relation op gives the answer + return (mp_binary_op(op, items1[i], items2[i]) == mp_const_true); } + assert(eq_status); // If we had tie in the last element... if (eq_status) { // ... and we have lists of different lengths... diff --git a/tests/basics/tuple_compare.py b/tests/basics/tuple_compare.py index 8bdb2bcf98..ad813f7029 100644 --- a/tests/basics/tuple_compare.py +++ b/tests/basics/tuple_compare.py @@ -48,3 +48,8 @@ print((1,) <= (1, 0,)) print((1,) <= (1, -1,)) print((1, 0,) <= (1,)) print((1, -1,) <= (1,)) + +print((10, 0) > (1, 1)) +print((10, 0) < (1, 1)) +print((0, 0, 10, 0) > (0, 0, 1, 1)) +print((0, 0, 10, 0) < (0, 0, 1, 1)) From 0fc4775cd6e13360bfd622602b50de900dac6617 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 18 Apr 2014 21:47:58 +0300 Subject: [PATCH 4/4] sequence: Further simplify sequence comparison. --- py/sequence.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/py/sequence.c b/py/sequence.c index 7ea3f708f1..f91bf43c74 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -109,11 +109,9 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t * } int len = len1 < len2 ? len1 : len2; - bool eq_status = true; // empty lists are equal for (int i = 0; i < len; i++) { - eq_status = mp_obj_equal(items1[i], items2[i]); // If current elements equal, can't decide anything - go on - if (eq_status) { + if (mp_obj_equal(items1[i], items2[i])) { continue; } @@ -127,19 +125,16 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t * return (mp_binary_op(op, items1[i], items2[i]) == mp_const_true); } - assert(eq_status); // If we had tie in the last element... - if (eq_status) { - // ... and we have lists of different lengths... - if (len1 != len2) { - if (len1 < len2) { - // ... then longer list length wins (we deal only with >) - return false; - } - } else if (op == MP_BINARY_OP_MORE) { - // Otherwise, if we have strict relation, equality means failure + // ... and we have lists of different lengths... + if (len1 != len2) { + if (len1 < len2) { + // ... then longer list length wins (we deal only with >) return false; } + } else if (op == MP_BINARY_OP_MORE) { + // Otherwise, if we have strict relation, sequence equality means failure + return false; } return true;