Explorar o código

修复了64位模式下类型问题造成的waring和可能存在的整形溢出

ZYH %!s(int64=5) %!d(string=hai) anos
pai
achega
c6df805ea9
Modificáronse 6 ficheiros con 11 adicións e 10 borrados
  1. 2 2
      port/modules/machine/modmachine.c
  2. 1 0
      port/modules/modutime.c
  3. 2 2
      port/mpconfigport.h
  4. 2 2
      port/mpy_main.c
  5. 2 2
      py/objtype.c
  6. 2 2
      py/runtime.h

+ 2 - 2
port/modules/machine/modmachine.c

@@ -49,7 +49,7 @@
 
 #if MICROPY_PY_MACHINE
 
-STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
+STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
 #ifdef RT_USING_FINSH
     extern long list_thread(void);
 #endif
@@ -147,7 +147,7 @@ STATIC mp_obj_t pyb_disable_irq(void) {
 }
 MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq);
 
-STATIC mp_obj_t pyb_enable_irq(uint n_args, const mp_obj_t *arg) {
+STATIC mp_obj_t pyb_enable_irq(size_t n_args, const mp_obj_t *arg) {
     if (n_args == 0) {
         rt_hw_interrupt_enable(int_lvl);
     } else {

+ 1 - 0
port/modules/modutime.c

@@ -35,6 +35,7 @@
 #include "py/mphal.h"
 #include "extmod/utime_mphal.h"
 #include "lib/timeutils/timeutils.h"
+#include <math.h>
 
 STATIC mp_obj_t mod_time_time(void) {
 #if MICROPY_PY_BUILTINS_FLOAT

+ 2 - 2
port/mpconfigport.h

@@ -319,8 +319,8 @@
 // to print such value. So, we avoid int32_t and use int directly.
 #define UINT_FMT "%u"
 #define INT_FMT "%d"
-typedef int mp_int_t; // must be pointer size
-typedef unsigned mp_uint_t; // must be pointer size
+typedef intptr_t mp_int_t; // must be pointer size
+typedef uintptr_t mp_uint_t; // must be pointer size
 
 typedef long mp_off_t;
 

+ 2 - 2
port/mpy_main.c

@@ -253,9 +253,9 @@ NORETURN void nlr_jump_fail(void *val) {
 }
 
 #ifndef NDEBUG
-void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
+NORETURN void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
     mp_printf(MICROPY_ERROR_PRINTER, "Assertion '%s' failed, at file %s:%d\n", expr, file, line);
-    RT_ASSERT(0);
+    while (1);
 }
 #endif
 

+ 2 - 2
py/objtype.c

@@ -372,7 +372,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
 
 // Qstrs for special methods are guaranteed to have a small value, so we use byte
 // type to represent them.
-const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
+const qstr mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
     [MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
     [MP_UNARY_OP_LEN] = MP_QSTR___len__,
     [MP_UNARY_OP_HASH] = MP_QSTR___hash__,
@@ -464,7 +464,7 @@ STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
 // fail).  They can be added at the expense of code size for the qstr.
 // Qstrs for special methods are guaranteed to have a small value, so we use byte
 // type to represent them.
-const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
+const qstr mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
     [MP_BINARY_OP_LESS] = MP_QSTR___lt__,
     [MP_BINARY_OP_MORE] = MP_QSTR___gt__,
     [MP_BINARY_OP_EQUAL] = MP_QSTR___eq__,

+ 2 - 2
py/runtime.h

@@ -58,8 +58,8 @@ typedef struct _mp_arg_t {
 } mp_arg_t;
 
 // Tables mapping operator enums to qstrs, defined in objtype.c
-extern const byte mp_unary_op_method_name[];
-extern const byte mp_binary_op_method_name[];
+extern const qstr mp_unary_op_method_name[];
+extern const qstr mp_binary_op_method_name[];
 
 void mp_init(void);
 void mp_deinit(void);