Skip to content

Commit 8753a42

Browse files
authored
Merge pull request #157 from lymzzyh/master
修复了64位模式下类型问题造成的waring和可能存在的整形溢出
2 parents 0ca9dab + c6df805 commit 8753a42

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

port/modules/machine/modmachine.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
#if MICROPY_PY_MACHINE
5151

52-
STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
52+
STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
5353
#ifdef RT_USING_FINSH
5454
extern long list_thread(void);
5555
#endif
@@ -147,7 +147,7 @@ STATIC mp_obj_t pyb_disable_irq(void) {
147147
}
148148
MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq);
149149

150-
STATIC mp_obj_t pyb_enable_irq(uint n_args, const mp_obj_t *arg) {
150+
STATIC mp_obj_t pyb_enable_irq(size_t n_args, const mp_obj_t *arg) {
151151
if (n_args == 0) {
152152
rt_hw_interrupt_enable(int_lvl);
153153
} else {

port/modules/modutime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "py/mphal.h"
3636
#include "extmod/utime_mphal.h"
3737
#include "lib/timeutils/timeutils.h"
38+
#include <math.h>
3839

3940
STATIC mp_obj_t mod_time_time(void) {
4041
#if MICROPY_PY_BUILTINS_FLOAT

port/mpconfigport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@
319319
// to print such value. So, we avoid int32_t and use int directly.
320320
#define UINT_FMT "%u"
321321
#define INT_FMT "%d"
322-
typedef int mp_int_t; // must be pointer size
323-
typedef unsigned mp_uint_t; // must be pointer size
322+
typedef intptr_t mp_int_t; // must be pointer size
323+
typedef uintptr_t mp_uint_t; // must be pointer size
324324

325325
typedef long mp_off_t;
326326

port/mpy_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ NORETURN void nlr_jump_fail(void *val) {
253253
}
254254

255255
#ifndef NDEBUG
256-
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
256+
NORETURN void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
257257
mp_printf(MICROPY_ERROR_PRINTER, "Assertion '%s' failed, at file %s:%d\n", expr, file, line);
258-
RT_ASSERT(0);
258+
while (1);
259259
}
260260
#endif
261261

py/objtype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
372372

373373
// Qstrs for special methods are guaranteed to have a small value, so we use byte
374374
// type to represent them.
375-
const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
375+
const qstr mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
376376
[MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
377377
[MP_UNARY_OP_LEN] = MP_QSTR___len__,
378378
[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) {
464464
// fail). They can be added at the expense of code size for the qstr.
465465
// Qstrs for special methods are guaranteed to have a small value, so we use byte
466466
// type to represent them.
467-
const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
467+
const qstr mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
468468
[MP_BINARY_OP_LESS] = MP_QSTR___lt__,
469469
[MP_BINARY_OP_MORE] = MP_QSTR___gt__,
470470
[MP_BINARY_OP_EQUAL] = MP_QSTR___eq__,

py/runtime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ typedef struct _mp_arg_t {
5858
} mp_arg_t;
5959

6060
// Tables mapping operator enums to qstrs, defined in objtype.c
61-
extern const byte mp_unary_op_method_name[];
62-
extern const byte mp_binary_op_method_name[];
61+
extern const qstr mp_unary_op_method_name[];
62+
extern const qstr mp_binary_op_method_name[];
6363

6464
void mp_init(void);
6565
void mp_deinit(void);

0 commit comments

Comments
 (0)