Skip to content

Commit 4d91723

Browse files
committed
py: Remove use of int type in obj.h.
Part of code cleanup, working towards resolving issue adafruit#50.
1 parent d182b98 commit 4d91723

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

py/obj.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void mp_obj_print_exception(mp_obj_t exc) {
111111
printf("\n");
112112
}
113113

114-
int mp_obj_is_true(mp_obj_t arg) {
114+
bool mp_obj_is_true(mp_obj_t arg) {
115115
if (arg == mp_const_false) {
116116
return 0;
117117
} else if (arg == mp_const_true) {
@@ -414,7 +414,7 @@ mp_obj_t mp_identity(mp_obj_t self) {
414414
}
415415
MP_DEFINE_CONST_FUN_OBJ_1(mp_identity_obj, mp_identity);
416416

417-
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags) {
417+
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
418418
mp_obj_type_t *type = mp_obj_get_type(obj);
419419
if (type->buffer_p.get_buffer == NULL) {
420420
return false;
@@ -426,7 +426,7 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags) {
426426
return true;
427427
}
428428

429-
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags) {
429+
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
430430
if (!mp_get_buffer(obj, bufinfo, flags)) {
431431
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "object with buffer protocol required"));
432432
}

py/obj.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ typedef struct _mp_buffer_info_t {
212212
//int ver; // ?
213213

214214
void *buf; // can be NULL if len == 0
215-
mp_int_t len; // in bytes
216-
int typecode; // as per binary.h
215+
mp_int_t len; // in bytes; TODO should it be mp_uint_t?
216+
int typecode; // as per binary.h; TODO what is the correct type to use?
217217

218218
// Rationale: to load arbitrary-sized sprites directly to LCD
219219
// Cons: a bit adhoc usecase
@@ -223,10 +223,10 @@ typedef struct _mp_buffer_info_t {
223223
#define MP_BUFFER_WRITE (2)
224224
#define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE)
225225
typedef struct _mp_buffer_p_t {
226-
mp_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags);
226+
mp_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
227227
} mp_buffer_p_t;
228-
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags);
229-
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags);
228+
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
229+
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
230230

231231
// Stream protocol
232232
#define MP_STREAM_ERROR (-1)
@@ -236,7 +236,7 @@ typedef struct _mp_stream_p_t {
236236
mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
237237
mp_uint_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode);
238238
// add seek() ?
239-
int is_text : 1; // default is bytes, set this for text stream
239+
mp_uint_t is_text : 1; // default is bytes, set this for text stream
240240
} mp_stream_p_t;
241241

242242
struct _mp_obj_type_t {
@@ -403,7 +403,7 @@ void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *e
403403
void mp_obj_print(mp_obj_t o, mp_print_kind_t kind);
404404
void mp_obj_print_exception(mp_obj_t exc);
405405

406-
int mp_obj_is_true(mp_obj_t arg);
406+
bool mp_obj_is_true(mp_obj_t arg);
407407

408408
// TODO make these all lower case when they have proven themselves
409409
static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o) { return ((((mp_int_t)(o)) & 3) == 0); }
@@ -575,8 +575,8 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
575575
#endif
576576
#define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
577577
#define mp_seq_cat(dest, src1, len1, src2, len2, item_t) { memcpy(dest, src1, (len1) * sizeof(item_t)); memcpy(dest + (len1), src2, (len2) * sizeof(item_t)); }
578-
bool mp_seq_cmp_bytes(int op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2);
579-
bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, mp_uint_t len1, const mp_obj_t *items2, mp_uint_t len2);
578+
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2);
579+
bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, mp_uint_t len1, const mp_obj_t *items2, mp_uint_t len2);
580580
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, mp_uint_t len, mp_uint_t n_args, const mp_obj_t *args);
581581
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, mp_uint_t len, mp_obj_t value);
582582
mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);

py/objarray.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef struct _mp_obj_array_t {
5252
STATIC mp_obj_t array_iterator_new(mp_obj_t array_in);
5353
STATIC mp_obj_array_t *array_new(char typecode, uint n);
5454
STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg);
55-
STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, int flags);
55+
STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags);
5656

5757
/******************************************************************************/
5858
/* array */
@@ -223,7 +223,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
223223
}
224224
}
225225

226-
STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, int flags) {
226+
STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
227227
mp_obj_array_t *o = o_in;
228228
bufinfo->buf = o->items;
229229
bufinfo->len = o->len * mp_binary_get_size('@', o->typecode, NULL);

py/objstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ STATIC mp_obj_t str_encode(mp_uint_t n_args, const mp_obj_t *args) {
16181618
}
16191619
#endif
16201620

1621-
mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) {
1621+
mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
16221622
if (flags == MP_BUFFER_READ) {
16231623
GET_STR_DATA_LEN(self_in, str_data, str_len);
16241624
bufinfo->buf = (void*)str_data;

py/objstr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args);
5454
mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, uint len);
5555

5656
mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
57-
mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags);
57+
mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags);
5858

5959
const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, uint self_len,
6060
mp_obj_t index, bool is_slice);

py/sequence.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice
125125

126126
// Special-case comparison function for sequences of bytes
127127
// Don't pass MP_BINARY_OP_NOT_EQUAL here
128-
bool mp_seq_cmp_bytes(int op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2) {
128+
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2) {
129129
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
130130
return false;
131131
}
@@ -169,7 +169,7 @@ bool mp_seq_cmp_bytes(int op, const byte *data1, mp_uint_t len1, const byte *dat
169169

170170
// Special-case comparison function for sequences of mp_obj_t
171171
// Don't pass MP_BINARY_OP_NOT_EQUAL here
172-
bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, mp_uint_t len1, const mp_obj_t *items2, mp_uint_t len2) {
172+
bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, mp_uint_t len1, const mp_obj_t *items2, mp_uint_t len2) {
173173
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
174174
return false;
175175
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy