Skip to content

Commit 507119f

Browse files
committed
py/sequence: Convert mp_uint_t to size_t where appropriate.
1 parent c88cfe1 commit 507119f

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

py/obj.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,17 +819,17 @@ typedef struct {
819819
mp_int_t step;
820820
} mp_bound_slice_t;
821821

822-
void mp_seq_multiply(const void *items, mp_uint_t item_sz, mp_uint_t len, mp_uint_t times, void *dest);
822+
void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest);
823823
#if MICROPY_PY_BUILTINS_SLICE
824824
bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
825825
#endif
826826
#define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
827827
#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)); }
828-
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2);
829-
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);
830-
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);
831-
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, mp_uint_t len, mp_obj_t value);
832-
mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);
828+
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *data2, size_t len2);
829+
bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, size_t len1, const mp_obj_t *items2, size_t len2);
830+
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args);
831+
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value);
832+
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);
833833
// Helper to clear stale pointers from allocated, but unused memory, to preclude GC problems
834834
#define mp_seq_clear(start, len, alloc_len, item_sz) memset((byte*)(start) + (len) * (item_sz), 0, ((alloc_len) - (len)) * (item_sz))
835835
#define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_sz) \

py/sequence.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838

3939
// Implements backend of sequence * integer operation. Assumes elements are
4040
// memory-adjacent in sequence.
41-
void mp_seq_multiply(const void *items, mp_uint_t item_sz, mp_uint_t len, mp_uint_t times, void *dest) {
42-
for (mp_uint_t i = 0; i < times; i++) {
43-
uint copy_sz = item_sz * len;
41+
void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest) {
42+
for (size_t i = 0; i < times; i++) {
43+
size_t copy_sz = item_sz * len;
4444
memcpy(dest, items, copy_sz);
4545
dest = (char*)dest + copy_sz;
4646
}
@@ -119,7 +119,7 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
119119

120120
#endif
121121

122-
mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes) {
122+
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes) {
123123
(void)len; // TODO can we remove len from the arg list?
124124

125125
mp_int_t start = indexes->start, stop = indexes->stop;
@@ -143,22 +143,22 @@ mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice
143143

144144
// Special-case comparison function for sequences of bytes
145145
// Don't pass MP_BINARY_OP_NOT_EQUAL here
146-
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2) {
146+
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *data2, size_t len2) {
147147
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
148148
return false;
149149
}
150150

151151
// Let's deal only with > & >=
152152
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
153153
SWAP(const byte*, data1, data2);
154-
SWAP(uint, len1, len2);
154+
SWAP(size_t, len1, len2);
155155
if (op == MP_BINARY_OP_LESS) {
156156
op = MP_BINARY_OP_MORE;
157157
} else {
158158
op = MP_BINARY_OP_MORE_EQUAL;
159159
}
160160
}
161-
uint min_len = len1 < len2 ? len1 : len2;
161+
size_t min_len = len1 < len2 ? len1 : len2;
162162
int res = memcmp(data1, data2, min_len);
163163
if (op == MP_BINARY_OP_EQUAL) {
164164
// If we are checking for equality, here're the answer
@@ -187,24 +187,24 @@ bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byt
187187

188188
// Special-case comparison function for sequences of mp_obj_t
189189
// Don't pass MP_BINARY_OP_NOT_EQUAL here
190-
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) {
190+
bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, size_t len1, const mp_obj_t *items2, size_t len2) {
191191
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
192192
return false;
193193
}
194194

195195
// Let's deal only with > & >=
196196
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
197197
SWAP(const mp_obj_t *, items1, items2);
198-
SWAP(uint, len1, len2);
198+
SWAP(size_t, len1, len2);
199199
if (op == MP_BINARY_OP_LESS) {
200200
op = MP_BINARY_OP_MORE;
201201
} else {
202202
op = MP_BINARY_OP_MORE_EQUAL;
203203
}
204204
}
205205

206-
mp_uint_t len = len1 < len2 ? len1 : len2;
207-
for (mp_uint_t i = 0; i < len; i++) {
206+
size_t len = len1 < len2 ? len1 : len2;
207+
for (size_t i = 0; i < len; i++) {
208208
// If current elements equal, can't decide anything - go on
209209
if (mp_obj_equal(items1[i], items2[i])) {
210210
continue;
@@ -236,7 +236,7 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, mp_uint_t len1, const
236236
}
237237

238238
// Special-case of index() which searches for mp_obj_t
239-
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) {
239+
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args) {
240240
mp_obj_type_t *type = mp_obj_get_type(args[0]);
241241
mp_obj_t value = args[1];
242242
size_t start = 0;
@@ -259,9 +259,9 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, mp_uint_t len, mp_uint_t n_args
259259
mp_raise_msg(&mp_type_ValueError, "object not in sequence");
260260
}
261261

262-
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, mp_uint_t len, mp_obj_t value) {
263-
mp_uint_t count = 0;
264-
for (uint i = 0; i < len; i++) {
262+
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value) {
263+
size_t count = 0;
264+
for (size_t i = 0; i < len; i++) {
265265
if (mp_obj_equal(items[i], value)) {
266266
count++;
267267
}

0 commit comments

Comments
 (0)