Skip to content

Commit e04a44e

Browse files
committed
py: Small comments, name changes, use of machine_int_t.
1 parent b3a50f0 commit e04a44e

6 files changed

Lines changed: 16 additions & 15 deletions

File tree

py/builtin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
173173

174174
STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
175175
#if MICROPY_PY_BUILTINS_STR_UNICODE
176-
int c = mp_obj_get_int(o_in);
176+
machine_int_t c = mp_obj_get_int(o_in);
177177
char str[4];
178178
int len = 0;
179179
if (c < 0x80) {
@@ -198,7 +198,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
198198
}
199199
return mp_obj_new_str(str, len, true);
200200
#else
201-
int ord = mp_obj_get_int(o_in);
201+
machine_int_t ord = mp_obj_get_int(o_in);
202202
if (0 <= ord && ord <= 0x10ffff) {
203203
char str[1] = {ord};
204204
return mp_obj_new_str(str, 1, true);

py/misc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool unichar_isupper(unichar c);
100100
bool unichar_islower(unichar c);
101101
unichar unichar_tolower(unichar c);
102102
unichar unichar_toupper(unichar c);
103-
uint unichar_charlen(const char *str, uint len);
103+
uint unichar_charlen(const char *str, uint len); // TODO this should return machine_uint_t
104104
#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
105105
#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)
106106

@@ -169,6 +169,7 @@ extern uint mp_verbose_flag;
169169
// This is useful for unicode handling. Some CPU archs has
170170
// special instructions for efficient implentation of this
171171
// function (e.g. CLZ on ARM).
172+
// NOTE: this function is unused at the moment
172173
#ifndef count_lead_ones
173174
static inline uint count_lead_ones(byte val) {
174175
uint c = 0;

py/objstr.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ STATIC const byte *find_subbytes(const byte *haystack, machine_uint_t hlen, cons
251251
return NULL;
252252
}
253253

254-
mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
254+
mp_obj_t mp_obj_str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
255255
GET_STR_DATA_LEN(lhs_in, lhs_data, lhs_len);
256256
mp_obj_type_t *lhs_type = mp_obj_get_type(lhs_in);
257257
mp_obj_type_t *rhs_type = mp_obj_get_type(rhs_in);
@@ -566,7 +566,6 @@ STATIC mp_obj_t str_rsplit(uint n_args, const mp_obj_t *args) {
566566
return res;
567567
}
568568

569-
570569
STATIC mp_obj_t str_finder(uint n_args, const mp_obj_t *args, machine_int_t direction, bool is_index) {
571570
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
572571
assert(2 <= n_args && n_args <= 4);
@@ -1610,7 +1609,7 @@ STATIC mp_obj_t str_encode(uint n_args, const mp_obj_t *args) {
16101609
}
16111610
#endif
16121611

1613-
machine_int_t str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) {
1612+
machine_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) {
16141613
if (flags == MP_BUFFER_READ) {
16151614
GET_STR_DATA_LEN(self_in, str_data, str_len);
16161615
bufinfo->buf = (void*)str_data;
@@ -1701,10 +1700,10 @@ const mp_obj_type_t mp_type_str = {
17011700
.name = MP_QSTR_str,
17021701
.print = str_print,
17031702
.make_new = str_make_new,
1704-
.binary_op = str_binary_op,
1703+
.binary_op = mp_obj_str_binary_op,
17051704
.subscr = str_subscr,
17061705
.getiter = mp_obj_new_str_iterator,
1707-
.buffer_p = { .get_buffer = str_get_buffer },
1706+
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
17081707
.locals_dict = (mp_obj_t)&str_locals_dict,
17091708
};
17101709
#endif
@@ -1715,10 +1714,10 @@ const mp_obj_type_t mp_type_bytes = {
17151714
.name = MP_QSTR_bytes,
17161715
.print = str_print,
17171716
.make_new = bytes_make_new,
1718-
.binary_op = str_binary_op,
1717+
.binary_op = mp_obj_str_binary_op,
17191718
.subscr = str_subscr,
17201719
.getiter = mp_obj_new_bytes_iterator,
1721-
.buffer_p = { .get_buffer = str_get_buffer },
1720+
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
17221721
.locals_dict = (mp_obj_t)&str_locals_dict,
17231722
};
17241723

py/objstr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ typedef struct _mp_obj_str_t {
5454
mp_obj_t mp_obj_str_format(uint n_args, const mp_obj_t *args);
5555
mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, uint len);
5656

57-
mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in);
58-
machine_int_t str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags);
57+
mp_obj_t mp_obj_str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in);
58+
machine_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags);
5959

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

py/objstrunicode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ STATIC mp_obj_t uni_unary_op(int op, mp_obj_t self_in) {
106106
case MP_UNARY_OP_BOOL:
107107
return MP_BOOL(str_len != 0);
108108
case MP_UNARY_OP_LEN:
109-
return MP_OBJ_NEW_SMALL_INT(unichar_charlen((const char *)str_data, str_len));
109+
return MP_OBJ_NEW_SMALL_INT((machine_int_t)unichar_charlen((const char *)str_data, str_len));
110110
default:
111111
return MP_OBJ_NULL; // op not supported
112112
}
@@ -311,10 +311,10 @@ const mp_obj_type_t mp_type_str = {
311311
.print = uni_print,
312312
.make_new = str_make_new,
313313
.unary_op = uni_unary_op,
314-
.binary_op = str_binary_op,
314+
.binary_op = mp_obj_str_binary_op,
315315
.subscr = str_subscr,
316316
.getiter = mp_obj_new_str_iterator,
317-
.buffer_p = { .get_buffer = str_get_buffer },
317+
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
318318
.locals_dict = (mp_obj_t)&str_locals_dict,
319319
};
320320

py/unicode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) {
107107
return i;
108108
}
109109

110+
// TODO: Rename to str_charlen; return machine_uint_t
110111
uint unichar_charlen(const char *str, uint len)
111112
{
112113
#if MICROPY_PY_BUILTINS_STR_UNICODE

0 commit comments

Comments
 (0)