From ab7bf28489fde83c73da2a3a20b9eadb08e8cc81 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 17 May 2014 11:08:33 +0300 Subject: [PATCH] py: More const usage. --- py/obj.c | 4 ++-- py/obj.h | 12 ++++++------ py/objfun.c | 4 ++-- py/objint.c | 2 +- py/objint.h | 4 ++-- py/objint_longlong.c | 2 +- py/objint_mpz.c | 8 ++++---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/py/obj.c b/py/obj.c index 437346b62d..3617ff6761 100644 --- a/py/obj.c +++ b/py/obj.c @@ -222,7 +222,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { return false; } -machine_int_t mp_obj_get_int(mp_obj_t arg) { +machine_int_t mp_obj_get_int(mp_const_obj_t arg) { // This function essentially performs implicit type conversion to int // Note that Python does NOT provide implicit type conversion from // float to int in the core expression language, try some_list[1.0]. @@ -242,7 +242,7 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) { // returns false if arg is not of integral type // returns true and sets *value if it is of integral type // can throw OverflowError if arg is of integral type, but doesn't fit in a machine_int_t -bool mp_obj_get_int_maybe(mp_obj_t arg, machine_int_t *value) { +bool mp_obj_get_int_maybe(mp_const_obj_t arg, machine_int_t *value) { if (arg == mp_const_false) { *value = 0; } else if (arg == mp_const_true) { diff --git a/py/obj.h b/py/obj.h index e29f3efeab..14ced0691a 100644 --- a/py/obj.h +++ b/py/obj.h @@ -158,7 +158,7 @@ typedef enum _mp_map_lookup_kind_t { MP_MAP_LOOKUP_REMOVE_IF_FOUND, // 2 } mp_map_lookup_kind_t; -static inline bool MP_MAP_SLOT_IS_FILLED(mp_map_t *map, machine_uint_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); } +static inline bool MP_MAP_SLOT_IS_FILLED(const mp_map_t *map, machine_uint_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); } void mp_map_init(mp_map_t *map, int n); void mp_map_init_fixed_table(mp_map_t *map, int n, const mp_obj_t *table); @@ -177,7 +177,7 @@ typedef struct _mp_set_t { mp_obj_t *table; } mp_set_t; -static inline bool MP_SET_SLOT_IS_FILLED(mp_set_t *set, machine_uint_t pos) { return ((set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL); } +static inline bool MP_SET_SLOT_IS_FILLED(const mp_set_t *set, machine_uint_t pos) { return ((set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL); } void mp_set_init(mp_set_t *set, int n); mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind); @@ -424,8 +424,8 @@ bool mp_obj_is_callable(mp_obj_t o_in); machine_int_t mp_obj_hash(mp_obj_t o_in); bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2); -machine_int_t mp_obj_get_int(mp_obj_t arg); -bool mp_obj_get_int_maybe(mp_obj_t arg, machine_int_t *value); +machine_int_t mp_obj_get_int(mp_const_obj_t arg); +bool mp_obj_get_int_maybe(mp_const_obj_t arg, machine_int_t *value); #if MICROPY_ENABLE_FLOAT mp_float_t mp_obj_get_float(mp_obj_t self_in); void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); @@ -452,7 +452,7 @@ machine_int_t mp_obj_int_get(mp_obj_t self_in); mp_float_t mp_obj_int_as_float(mp_obj_t self_in); #endif // Will raise exception if value doesn't fit into machine_int_t -machine_int_t mp_obj_int_get_checked(mp_obj_t self_in); +machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in); // exception #define mp_obj_is_native_exception_instance(o) (mp_obj_get_type(o)->make_new == mp_obj_exception_make_new) @@ -540,7 +540,7 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args, uint *out_args1_len, const mp_obj_t **out_args1, uint *out_args2_len, const mp_obj_t **out_args2); -const char *mp_obj_fun_get_name(mp_obj_t fun); +const char *mp_obj_fun_get_name(mp_const_obj_t fun); const char *mp_obj_code_get_name(const byte *code_info); mp_obj_t mp_identity(mp_obj_t self); diff --git a/py/objfun.c b/py/objfun.c index 7915ddad0f..27cba3abe3 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -154,8 +154,8 @@ const char *mp_obj_code_get_name(const byte *code_info) { return qstr_str(block_name); } -const char *mp_obj_fun_get_name(mp_obj_t fun_in) { - mp_obj_fun_bc_t *fun = fun_in; +const char *mp_obj_fun_get_name(mp_const_obj_t fun_in) { + const mp_obj_fun_bc_t *fun = fun_in; const byte *code_info = fun->bytecode; return mp_obj_code_get_name(code_info); } diff --git a/py/objint.c b/py/objint.c index d1d99a253f..34447b3a12 100644 --- a/py/objint.c +++ b/py/objint.c @@ -129,7 +129,7 @@ STATIC uint int_as_str_size_formatted(uint base, const char *prefix, char comma) // // The resulting formatted string will be returned from this function and the // formatted size will be in *fmt_size. -char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in, +char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in, int base, const char *prefix, char base_char, char comma) { fmt_int_t num; if (MP_OBJ_IS_SMALL_INT(self_in)) { diff --git a/py/objint.h b/py/objint.h index 0ea19d0ddb..1d12cffae0 100644 --- a/py/objint.h +++ b/py/objint.h @@ -34,9 +34,9 @@ typedef struct _mp_obj_int_t { } mp_obj_int_t; void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind); -char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in, +char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in, int base, const char *prefix, char base_char, char comma); -char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in, +char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in, int base, const char *prefix, char base_char, char comma); bool mp_obj_int_is_positive(mp_obj_t self_in); mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in); diff --git a/py/objint_longlong.c b/py/objint_longlong.c index fe35d54a48..a9aea39312 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -186,7 +186,7 @@ machine_int_t mp_obj_int_get(mp_obj_t self_in) { } } -machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) { +machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { // TODO: Check overflow return mp_obj_int_get(self_in); } diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 8e72782d66..32c8595f53 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -58,10 +58,10 @@ STATIC mp_obj_int_t *mp_obj_int_new_mpz(void) { // formatted size will be in *fmt_size. // // This particular routine should only be called for the mpz representation of the int. -char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in, +char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in, int base, const char *prefix, char base_char, char comma) { assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int)); - mp_obj_int_t *self = self_in; + const mp_obj_int_t *self = self_in; uint needed_size = mpz_as_str_size_formatted(&self->mpz, base, prefix, comma); if (needed_size > *buf_size) { @@ -284,11 +284,11 @@ machine_int_t mp_obj_int_get(mp_obj_t self_in) { } } -machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) { +machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in); } else { - mp_obj_int_t *self = self_in; + const mp_obj_int_t *self = self_in; machine_int_t value; if (mpz_as_int_checked(&self->mpz, &value)) { return value;