summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-27 09:13:15 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-27 09:13:15 +0100
commitad4c014d461cf325712d961c547f461746f52408 (patch)
treec898437b7c2a717d74699c4ca305963a9e056879 /py
parentf3c3010ffccc6cee0795c0491e2a686994bd0b34 (diff)
parentb7f7c655ed4b54d9ff8ec04908199d04d38b7528 (diff)
downloadmicropython-ad4c014d461cf325712d961c547f461746f52408.tar.gz
micropython-ad4c014d461cf325712d961c547f461746f52408.zip
Merge branch 'int-bytes' of https://github.com/dhylands/micropython into dhylands-int-bytes
Diffstat (limited to 'py')
-rw-r--r--py/obj.h1
-rw-r--r--py/objint.c2
-rw-r--r--py/objstr.c12
3 files changed, 6 insertions, 9 deletions
diff --git a/py/obj.h b/py/obj.h
index 26a387a2f9..4f32a808f3 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -74,6 +74,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#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
#define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int))
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
+#define MP_OBJ_IS_STR_OR_BYTES(o) (MP_OBJ_IS_STR(o) || MP_OBJ_IS_TYPE(o, &mp_type_bytes))
#define MP_OBJ_IS_FUN(o) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type->binary_op == mp_obj_fun_binary_op))
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
diff --git a/py/objint.c b/py/objint.c
index d088ae1a80..a771383502 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -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
if (MP_OBJ_IS_INT(args[0])) {
// already an int (small or long), just return it
return args[0];
- } else if (MP_OBJ_IS_STR(args[0])) {
+ } else if (MP_OBJ_IS_STR_OR_BYTES(args[0])) {
// a string, parse it
uint l;
const char *s = mp_obj_str_get_data(args[0], &l);
diff --git a/py/objstr.c b/py/objstr.c
index e884794591..f38532963c 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -49,10 +49,6 @@ STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str);
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in);
STATIC NORETURN void arg_type_mixup();
-STATIC bool is_str_or_bytes(mp_obj_t o) {
- return MP_OBJ_IS_STR(o) || MP_OBJ_IS_TYPE(o, &mp_type_bytes);
-}
-
/******************************************************************************/
/* str */
@@ -388,7 +384,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
}
STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
- assert(is_str_or_bytes(self_in));
+ assert(MP_OBJ_IS_STR_OR_BYTES(self_in));
const mp_obj_type_t *self_type = mp_obj_get_type(self_in);
// get separation string
@@ -660,7 +656,7 @@ enum { LSTRIP, RSTRIP, STRIP };
STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) {
assert(1 <= n_args && n_args <= 2);
- assert(is_str_or_bytes(args[0]));
+ assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
const byte *chars_to_del;
@@ -1477,7 +1473,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) {
}
STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t direction) {
- if (!is_str_or_bytes(self_in)) {
+ if (!MP_OBJ_IS_STR_OR_BYTES(self_in)) {
assert(0);
}
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) {
}
const char *mp_obj_str_get_data(mp_obj_t self_in, uint *len) {
- if (is_str_or_bytes(self_in)) {
+ if (MP_OBJ_IS_STR_OR_BYTES(self_in)) {
GET_STR_DATA_LEN(self_in, s, l);
*len = l;
return (const char*)s;