From 70f33cde48524f12f2110c7daa4a874a6828314a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 2 Apr 2014 17:06:05 +0100 Subject: [PATCH] py: Fix up so that it can compile without float. --- py/gc.c | 1 - py/malloc.c | 1 - py/objstr.c | 8 ++++++-- py/runtime.c | 6 ++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/py/gc.c b/py/gc.c index 67f1e810e0..3a3fdb00a5 100644 --- a/py/gc.c +++ b/py/gc.c @@ -1,5 +1,4 @@ #include -#include #include #include "mpconfig.h" diff --git a/py/malloc.c b/py/malloc.c index 504db4b1b9..27eaac1088 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/py/objstr.c b/py/objstr.c index 8389bb0bdf..f22c6b1bae 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -788,9 +788,9 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Unknown format code '%c' for object of type '%s'", type, mp_obj_get_type_str(arg))); } - } + #if MICROPY_ENABLE_FLOAT - if (arg_looks_numeric(arg)) { + } else if (arg_looks_numeric(arg)) { if (!type) { // Even though the docs say that an unspecified type is the same @@ -848,10 +848,14 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { type, mp_obj_get_type_str(arg))); } #endif + } else { + // arg doesn't look like a number + if (align == '=') { nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "'=' alignment not allowed in string format specifier")); } + switch (type) { case '\0': mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, vstr, arg, PRINT_STR); diff --git a/py/runtime.c b/py/runtime.c index 0c75d4cd31..e2e3495648 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -346,8 +346,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { case MP_BINARY_OP_TRUE_DIVIDE: case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: if (rhs_val == 0) { -zero_division: - nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero")); + goto zero_division; } return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val); #endif @@ -451,6 +450,9 @@ generic_binary_op: "unsupported operand types for binary operator: '%s', '%s'", mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs))); return mp_const_none; + +zero_division: + nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero")); } mp_obj_t mp_call_function_0(mp_obj_t fun) {