summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-06-18 13:40:53 +1000
committerDamien George <damien.p.george@gmail.com>2018-06-18 13:40:53 +1000
commitc00ee200accb0f79fc2a7829ebe4567258ed40c0 (patch)
tree4cee06ae111ecd9ecc2b00a9ecf9ff3dd6385dcf /py
parentca2b1d6b36b11706b537eba90144469ba28561d2 (diff)
py/objarray: Replace 0x80 with new MP_OBJ_ARRAY_TYPECODE_FLAG_RW macro.
Diffstat (limited to 'py')
-rw-r--r--py/objarray.c8
-rw-r--r--py/objarray.h3
2 files changed, 7 insertions, 4 deletions
diff --git a/py/objarray.c b/py/objarray.c
index a35539484..aa9fa3b73 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -222,7 +222,7 @@ STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args,
// test if the object can be written to
if (mp_get_buffer(args[0], &bufinfo, MP_BUFFER_RW)) {
- self->typecode |= 0x80; // used to indicate writable buffer
+ self->typecode |= MP_OBJ_ARRAY_TYPECODE_FLAG_RW; // indicate writable buffer
}
return MP_OBJ_FROM_PTR(self);
@@ -414,7 +414,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
uint8_t* dest_items = o->items;
#if MICROPY_PY_BUILTINS_MEMORYVIEW
if (o->base.type == &mp_type_memoryview) {
- if ((o->typecode & 0x80) == 0) {
+ if (!(o->typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
// store to read-only memoryview not allowed
return MP_OBJ_NULL;
}
@@ -471,7 +471,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
#if MICROPY_PY_BUILTINS_MEMORYVIEW
if (o->base.type == &mp_type_memoryview) {
index += o->free;
- if (value != MP_OBJ_SENTINEL && (o->typecode & 0x80) == 0) {
+ if (value != MP_OBJ_SENTINEL && !(o->typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
// store to read-only memoryview
return MP_OBJ_NULL;
}
@@ -497,7 +497,7 @@ STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_ui
bufinfo->typecode = o->typecode & TYPECODE_MASK;
#if MICROPY_PY_BUILTINS_MEMORYVIEW
if (o->base.type == &mp_type_memoryview) {
- if ((o->typecode & 0x80) == 0 && (flags & MP_BUFFER_WRITE)) {
+ if (!(o->typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW) && (flags & MP_BUFFER_WRITE)) {
// read-only memoryview
return 1;
}
diff --git a/py/objarray.h b/py/objarray.h
index 038966845..0dad70571 100644
--- a/py/objarray.h
+++ b/py/objarray.h
@@ -29,6 +29,9 @@
#include "py/obj.h"
+// Used only for memoryview types, set in "typecode" to indicate a writable memoryview
+#define MP_OBJ_ARRAY_TYPECODE_FLAG_RW (0x80)
+
typedef struct _mp_obj_array_t {
mp_obj_base_t base;
size_t typecode : 8;