py/sequence: Convert mp_uint_t to size_t where appropriate.
This commit is contained in:
parent
c88cfe165b
commit
507119f4d8
12
py/obj.h
12
py/obj.h
@ -819,17 +819,17 @@ typedef struct {
|
||||
mp_int_t step;
|
||||
} mp_bound_slice_t;
|
||||
|
||||
void mp_seq_multiply(const void *items, mp_uint_t item_sz, mp_uint_t len, mp_uint_t times, void *dest);
|
||||
void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest);
|
||||
#if MICROPY_PY_BUILTINS_SLICE
|
||||
bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
|
||||
#endif
|
||||
#define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
|
||||
#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)); }
|
||||
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2);
|
||||
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);
|
||||
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);
|
||||
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, mp_uint_t len, mp_obj_t value);
|
||||
mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);
|
||||
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *data2, size_t len2);
|
||||
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);
|
||||
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args);
|
||||
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value);
|
||||
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);
|
||||
// Helper to clear stale pointers from allocated, but unused memory, to preclude GC problems
|
||||
#define mp_seq_clear(start, len, alloc_len, item_sz) memset((byte*)(start) + (len) * (item_sz), 0, ((alloc_len) - (len)) * (item_sz))
|
||||
#define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_sz) \
|
||||
|
@ -38,9 +38,9 @@
|
||||
|
||||
// Implements backend of sequence * integer operation. Assumes elements are
|
||||
// memory-adjacent in sequence.
|
||||
void mp_seq_multiply(const void *items, mp_uint_t item_sz, mp_uint_t len, mp_uint_t times, void *dest) {
|
||||
for (mp_uint_t i = 0; i < times; i++) {
|
||||
uint copy_sz = item_sz * len;
|
||||
void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest) {
|
||||
for (size_t i = 0; i < times; i++) {
|
||||
size_t copy_sz = item_sz * len;
|
||||
memcpy(dest, items, copy_sz);
|
||||
dest = (char*)dest + copy_sz;
|
||||
}
|
||||
@ -119,7 +119,7 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
|
||||
|
||||
#endif
|
||||
|
||||
mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes) {
|
||||
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes) {
|
||||
(void)len; // TODO can we remove len from the arg list?
|
||||
|
||||
mp_int_t start = indexes->start, stop = indexes->stop;
|
||||
@ -143,7 +143,7 @@ mp_obj_t mp_seq_extract_slice(mp_uint_t len, const mp_obj_t *seq, mp_bound_slice
|
||||
|
||||
// Special-case comparison function for sequences of bytes
|
||||
// Don't pass MP_BINARY_OP_NOT_EQUAL here
|
||||
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byte *data2, mp_uint_t len2) {
|
||||
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *data2, size_t len2) {
|
||||
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
|
||||
return false;
|
||||
}
|
||||
@ -151,14 +151,14 @@ bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byt
|
||||
// Let's deal only with > & >=
|
||||
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
|
||||
SWAP(const byte*, data1, data2);
|
||||
SWAP(uint, len1, len2);
|
||||
SWAP(size_t, len1, len2);
|
||||
if (op == MP_BINARY_OP_LESS) {
|
||||
op = MP_BINARY_OP_MORE;
|
||||
} else {
|
||||
op = MP_BINARY_OP_MORE_EQUAL;
|
||||
}
|
||||
}
|
||||
uint min_len = len1 < len2 ? len1 : len2;
|
||||
size_t min_len = len1 < len2 ? len1 : len2;
|
||||
int res = memcmp(data1, data2, min_len);
|
||||
if (op == MP_BINARY_OP_EQUAL) {
|
||||
// If we are checking for equality, here're the answer
|
||||
@ -187,7 +187,7 @@ bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, mp_uint_t len1, const byt
|
||||
|
||||
// Special-case comparison function for sequences of mp_obj_t
|
||||
// Don't pass MP_BINARY_OP_NOT_EQUAL here
|
||||
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) {
|
||||
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) {
|
||||
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
|
||||
return false;
|
||||
}
|
||||
@ -195,7 +195,7 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, mp_uint_t len1, const
|
||||
// Let's deal only with > & >=
|
||||
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
|
||||
SWAP(const mp_obj_t *, items1, items2);
|
||||
SWAP(uint, len1, len2);
|
||||
SWAP(size_t, len1, len2);
|
||||
if (op == MP_BINARY_OP_LESS) {
|
||||
op = MP_BINARY_OP_MORE;
|
||||
} else {
|
||||
@ -203,8 +203,8 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, mp_uint_t len1, const
|
||||
}
|
||||
}
|
||||
|
||||
mp_uint_t len = len1 < len2 ? len1 : len2;
|
||||
for (mp_uint_t i = 0; i < len; i++) {
|
||||
size_t len = len1 < len2 ? len1 : len2;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
// If current elements equal, can't decide anything - go on
|
||||
if (mp_obj_equal(items1[i], items2[i])) {
|
||||
continue;
|
||||
@ -236,7 +236,7 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, mp_uint_t len1, const
|
||||
}
|
||||
|
||||
// Special-case of index() which searches for mp_obj_t
|
||||
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) {
|
||||
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_type_t *type = mp_obj_get_type(args[0]);
|
||||
mp_obj_t value = args[1];
|
||||
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
|
||||
mp_raise_msg(&mp_type_ValueError, "object not in sequence");
|
||||
}
|
||||
|
||||
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, mp_uint_t len, mp_obj_t value) {
|
||||
mp_uint_t count = 0;
|
||||
for (uint i = 0; i < len; i++) {
|
||||
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value) {
|
||||
size_t count = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (mp_obj_equal(items[i], value)) {
|
||||
count++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user