Skip to content

Commit ad4c014

Browse files
committed
Merge branch 'int-bytes' of https://github.com/dhylands/micropython into dhylands-int-bytes
2 parents f3c3010 + b7f7c65 commit ad4c014

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

py/obj.h

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
7474
#define MP_OBJ_IS_TYPE(o, t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))) // this does not work for checking int, str or fun; use below macros for that
7575
#define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int))
7676
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
77+
#define MP_OBJ_IS_STR_OR_BYTES(o) (MP_OBJ_IS_STR(o) || MP_OBJ_IS_TYPE(o, &mp_type_bytes))
7778
#define MP_OBJ_IS_FUN(o) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type->binary_op == mp_obj_fun_binary_op))
7879

7980
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)

py/objint.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co
5757
if (MP_OBJ_IS_INT(args[0])) {
5858
// already an int (small or long), just return it
5959
return args[0];
60-
} else if (MP_OBJ_IS_STR(args[0])) {
60+
} else if (MP_OBJ_IS_STR_OR_BYTES(args[0])) {
6161
// a string, parse it
6262
uint l;
6363
const char *s = mp_obj_str_get_data(args[0], &l);

py/objstr.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str);
4949
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in);
5050
STATIC NORETURN void arg_type_mixup();
5151

52-
STATIC bool is_str_or_bytes(mp_obj_t o) {
53-
return MP_OBJ_IS_STR(o) || MP_OBJ_IS_TYPE(o, &mp_type_bytes);
54-
}
55-
5652
/******************************************************************************/
5753
/* str */
5854

@@ -388,7 +384,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
388384
}
389385

390386
STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
391-
assert(is_str_or_bytes(self_in));
387+
assert(MP_OBJ_IS_STR_OR_BYTES(self_in));
392388
const mp_obj_type_t *self_type = mp_obj_get_type(self_in);
393389

394390
// get separation string
@@ -660,7 +656,7 @@ enum { LSTRIP, RSTRIP, STRIP };
660656

661657
STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) {
662658
assert(1 <= n_args && n_args <= 2);
663-
assert(is_str_or_bytes(args[0]));
659+
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
664660
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
665661

666662
const byte *chars_to_del;
@@ -1477,7 +1473,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) {
14771473
}
14781474

14791475
STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t direction) {
1480-
if (!is_str_or_bytes(self_in)) {
1476+
if (!MP_OBJ_IS_STR_OR_BYTES(self_in)) {
14811477
assert(0);
14821478
}
14831479
mp_obj_type_t *self_type = mp_obj_get_type(self_in);
@@ -1877,7 +1873,7 @@ const char *mp_obj_str_get_str(mp_obj_t self_in) {
18771873
}
18781874

18791875
const char *mp_obj_str_get_data(mp_obj_t self_in, uint *len) {
1880-
if (is_str_or_bytes(self_in)) {
1876+
if (MP_OBJ_IS_STR_OR_BYTES(self_in)) {
18811877
GET_STR_DATA_LEN(self_in, s, l);
18821878
*len = l;
18831879
return (const char*)s;

tests/basics/int1.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
print(int(' \t 0o12', 8))
4848
print(int('0o12 \t ', 8))
4949
print(int(b"12", 10))
50+
print(int(b"12"))
5051

5152

5253
def test(value, base):

0 commit comments

Comments
 (0)