Skip to content

Commit 70f33cd

Browse files
committed
py: Fix up so that it can compile without float.
1 parent af6edc6 commit 70f33cd

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

py/gc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <stdio.h>
2-
#include <stdlib.h>
32
#include <string.h>
43

54
#include "mpconfig.h"

py/malloc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <unistd.h>
21
#include <stdio.h>
32
#include <stdlib.h>
43
#include <string.h>

py/objstr.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,9 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
788788
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
789789
"Unknown format code '%c' for object of type '%s'", type, mp_obj_get_type_str(arg)));
790790
}
791-
}
791+
792792
#if MICROPY_ENABLE_FLOAT
793-
if (arg_looks_numeric(arg)) {
793+
} else if (arg_looks_numeric(arg)) {
794794
if (!type) {
795795

796796
// 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) {
848848
type, mp_obj_get_type_str(arg)));
849849
}
850850
#endif
851+
851852
} else {
853+
// arg doesn't look like a number
854+
852855
if (align == '=') {
853856
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "'=' alignment not allowed in string format specifier"));
854857
}
858+
855859
switch (type) {
856860
case '\0':
857861
mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, vstr, arg, PRINT_STR);

py/runtime.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
346346
case MP_BINARY_OP_TRUE_DIVIDE:
347347
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
348348
if (rhs_val == 0) {
349-
zero_division:
350-
nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero"));
349+
goto zero_division;
351350
}
352351
return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val);
353352
#endif
@@ -451,6 +450,9 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
451450
"unsupported operand types for binary operator: '%s', '%s'",
452451
mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs)));
453452
return mp_const_none;
453+
454+
zero_division:
455+
nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero"));
454456
}
455457

456458
mp_obj_t mp_call_function_0(mp_obj_t fun) {

0 commit comments

Comments
 (0)