Skip to content

Commit ab7bf28

Browse files
committed
py: More const usage.
1 parent c18ef2a commit ab7bf28

7 files changed

Lines changed: 18 additions & 18 deletions

File tree

py/obj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
222222
return false;
223223
}
224224

225-
machine_int_t mp_obj_get_int(mp_obj_t arg) {
225+
machine_int_t mp_obj_get_int(mp_const_obj_t arg) {
226226
// This function essentially performs implicit type conversion to int
227227
// Note that Python does NOT provide implicit type conversion from
228228
// 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) {
242242
// returns false if arg is not of integral type
243243
// returns true and sets *value if it is of integral type
244244
// can throw OverflowError if arg is of integral type, but doesn't fit in a machine_int_t
245-
bool mp_obj_get_int_maybe(mp_obj_t arg, machine_int_t *value) {
245+
bool mp_obj_get_int_maybe(mp_const_obj_t arg, machine_int_t *value) {
246246
if (arg == mp_const_false) {
247247
*value = 0;
248248
} else if (arg == mp_const_true) {

py/obj.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ typedef enum _mp_map_lookup_kind_t {
158158
MP_MAP_LOOKUP_REMOVE_IF_FOUND, // 2
159159
} mp_map_lookup_kind_t;
160160

161-
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); }
161+
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); }
162162

163163
void mp_map_init(mp_map_t *map, int n);
164164
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 {
177177
mp_obj_t *table;
178178
} mp_set_t;
179179

180-
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); }
180+
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); }
181181

182182
void mp_set_init(mp_set_t *set, int n);
183183
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);
424424
machine_int_t mp_obj_hash(mp_obj_t o_in);
425425
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2);
426426

427-
machine_int_t mp_obj_get_int(mp_obj_t arg);
428-
bool mp_obj_get_int_maybe(mp_obj_t arg, machine_int_t *value);
427+
machine_int_t mp_obj_get_int(mp_const_obj_t arg);
428+
bool mp_obj_get_int_maybe(mp_const_obj_t arg, machine_int_t *value);
429429
#if MICROPY_ENABLE_FLOAT
430430
mp_float_t mp_obj_get_float(mp_obj_t self_in);
431431
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);
452452
mp_float_t mp_obj_int_as_float(mp_obj_t self_in);
453453
#endif
454454
// Will raise exception if value doesn't fit into machine_int_t
455-
machine_int_t mp_obj_int_get_checked(mp_obj_t self_in);
455+
machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in);
456456

457457
// exception
458458
#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
540540

541541
bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args,
542542
uint *out_args1_len, const mp_obj_t **out_args1, uint *out_args2_len, const mp_obj_t **out_args2);
543-
const char *mp_obj_fun_get_name(mp_obj_t fun);
543+
const char *mp_obj_fun_get_name(mp_const_obj_t fun);
544544
const char *mp_obj_code_get_name(const byte *code_info);
545545

546546
mp_obj_t mp_identity(mp_obj_t self);

py/objfun.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ const char *mp_obj_code_get_name(const byte *code_info) {
154154
return qstr_str(block_name);
155155
}
156156

157-
const char *mp_obj_fun_get_name(mp_obj_t fun_in) {
158-
mp_obj_fun_bc_t *fun = fun_in;
157+
const char *mp_obj_fun_get_name(mp_const_obj_t fun_in) {
158+
const mp_obj_fun_bc_t *fun = fun_in;
159159
const byte *code_info = fun->bytecode;
160160
return mp_obj_code_get_name(code_info);
161161
}

py/objint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ STATIC uint int_as_str_size_formatted(uint base, const char *prefix, char comma)
129129
//
130130
// The resulting formatted string will be returned from this function and the
131131
// formatted size will be in *fmt_size.
132-
char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in,
132+
char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
133133
int base, const char *prefix, char base_char, char comma) {
134134
fmt_int_t num;
135135
if (MP_OBJ_IS_SMALL_INT(self_in)) {

py/objint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ typedef struct _mp_obj_int_t {
3434
} mp_obj_int_t;
3535

3636
void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind);
37-
char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in,
37+
char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
3838
int base, const char *prefix, char base_char, char comma);
39-
char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in,
39+
char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
4040
int base, const char *prefix, char base_char, char comma);
4141
bool mp_obj_int_is_positive(mp_obj_t self_in);
4242
mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in);

py/objint_longlong.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ machine_int_t mp_obj_int_get(mp_obj_t self_in) {
186186
}
187187
}
188188

189-
machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
189+
machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
190190
// TODO: Check overflow
191191
return mp_obj_int_get(self_in);
192192
}

py/objint_mpz.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ STATIC mp_obj_int_t *mp_obj_int_new_mpz(void) {
5858
// formatted size will be in *fmt_size.
5959
//
6060
// This particular routine should only be called for the mpz representation of the int.
61-
char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_obj_t self_in,
61+
char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
6262
int base, const char *prefix, char base_char, char comma) {
6363
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
64-
mp_obj_int_t *self = self_in;
64+
const mp_obj_int_t *self = self_in;
6565

6666
uint needed_size = mpz_as_str_size_formatted(&self->mpz, base, prefix, comma);
6767
if (needed_size > *buf_size) {
@@ -284,11 +284,11 @@ machine_int_t mp_obj_int_get(mp_obj_t self_in) {
284284
}
285285
}
286286

287-
machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
287+
machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
288288
if (MP_OBJ_IS_SMALL_INT(self_in)) {
289289
return MP_OBJ_SMALL_INT_VALUE(self_in);
290290
} else {
291-
mp_obj_int_t *self = self_in;
291+
const mp_obj_int_t *self = self_in;
292292
machine_int_t value;
293293
if (mpz_as_int_checked(&self->mpz, &value)) {
294294
return value;

0 commit comments

Comments
 (0)