From 4e7107a572b55321f3f483f0293dd19b4f752c9b Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Nov 2015 12:19:25 +0000 Subject: [PATCH] py: Change mp_print_strn_t func type to use size_t for the str length. --- lib/utils/printf.c | 2 +- py/emitglue.c | 4 ++-- py/mpprint.c | 6 +++--- py/mpprint.h | 4 ++-- py/stream.c | 2 +- py/stream.h | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/utils/printf.c b/lib/utils/printf.c index b868d974c2..34bf3eb0fc 100644 --- a/lib/utils/printf.c +++ b/lib/utils/printf.c @@ -92,7 +92,7 @@ typedef struct _strn_print_env_t { size_t remain; } strn_print_env_t; -STATIC void strn_print_strn(void *data, const char *str, mp_uint_t len) { +STATIC void strn_print_strn(void *data, const char *str, size_t len) { strn_print_env_t *strn_print_env = data; if (len > strn_print_env->remain) { len = strn_print_env->remain; diff --git a/py/emitglue.c b/py/emitglue.c index 344a3d96d7..4eb9b76aa4 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -606,8 +606,8 @@ void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print) { #include #include -STATIC void fd_print_strn(void *env, const char *str, mp_uint_t len) { - int fd = (mp_int_t)env; +STATIC void fd_print_strn(void *env, const char *str, size_t len) { + int fd = (intptr_t)env; ssize_t ret = write(fd, str, len); (void)ret; } diff --git a/py/mpprint.c b/py/mpprint.c index 0aecf5c56d..6b1f8b9134 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -43,7 +43,7 @@ static const char pad_spaces[] = " "; static const char pad_zeroes[] = "0000000000000000"; -STATIC void plat_print_strn(void *env, const char *str, mp_uint_t len) { +STATIC void plat_print_strn(void *env, const char *str, size_t len) { (void)env; MP_PLAT_PRINT_STRN(str, len); } @@ -51,14 +51,14 @@ STATIC void plat_print_strn(void *env, const char *str, mp_uint_t len) { const mp_print_t mp_plat_print = {NULL, plat_print_strn}; int mp_print_str(const mp_print_t *print, const char *str) { - mp_uint_t len = strlen(str); + size_t len = strlen(str); if (len) { print->print_strn(print->data, str, len); } return len; } -int mp_print_strn(const mp_print_t *print, const char *str, mp_uint_t len, int flags, char fill, int width) { +int mp_print_strn(const mp_print_t *print, const char *str, size_t len, int flags, char fill, int width) { int left_pad = 0; int right_pad = 0; int pad = width - len; diff --git a/py/mpprint.h b/py/mpprint.h index 1770fcffe3..6e47409ecc 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -39,7 +39,7 @@ #define PF_FLAG_ADD_PERCENT (0x100) #define PF_FLAG_SHOW_OCTAL_LETTER (0x200) -typedef void (*mp_print_strn_t)(void *data, const char *str, mp_uint_t len); +typedef void (*mp_print_strn_t)(void *data, const char *str, size_t len); typedef struct _mp_print_t { void *data; @@ -55,7 +55,7 @@ extern const mp_print_t mp_sys_stdout_print; #endif int mp_print_str(const mp_print_t *print, const char *str); -int mp_print_strn(const mp_print_t *print, const char *str, mp_uint_t len, int flags, char fill, int width); +int mp_print_strn(const mp_print_t *print, const char *str, size_t len, int flags, char fill, int width); #if MICROPY_PY_BUILTINS_FLOAT int mp_print_float(const mp_print_t *print, mp_float_t f, char fmt, int flags, char fill, int width, int prec); #endif diff --git a/py/stream.c b/py/stream.c index 6be2c4f3eb..5c161ec2dc 100644 --- a/py/stream.c +++ b/py/stream.c @@ -174,7 +174,7 @@ STATIC mp_obj_t stream_read(mp_uint_t n_args, const mp_obj_t *args) { } } -mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, mp_uint_t len) { +mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len) { struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)self_in; if (o->type->stream_p == NULL || o->type->stream_p->write == NULL) { // CPython: io.UnsupportedOperation, OSError subclass diff --git a/py/stream.h b/py/stream.h index 5eace916fe..16761217aa 100644 --- a/py/stream.h +++ b/py/stream.h @@ -40,7 +40,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_stream_tell_obj); // Iterator which uses mp_stream_unbuffered_readline_obj mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self); -mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, mp_uint_t len); +mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len); #if MICROPY_STREAMS_NON_BLOCK // TODO: This is POSIX-specific (but then POSIX is the only real thing,