Skip to content

Commit c00ee20

Browse files
committed
py/objarray: Replace 0x80 with new MP_OBJ_ARRAY_TYPECODE_FLAG_RW macro.
1 parent ca2b1d6 commit c00ee20

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

py/objarray.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args,
222222

223223
// test if the object can be written to
224224
if (mp_get_buffer(args[0], &bufinfo, MP_BUFFER_RW)) {
225-
self->typecode |= 0x80; // used to indicate writable buffer
225+
self->typecode |= MP_OBJ_ARRAY_TYPECODE_FLAG_RW; // indicate writable buffer
226226
}
227227

228228
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
414414
uint8_t* dest_items = o->items;
415415
#if MICROPY_PY_BUILTINS_MEMORYVIEW
416416
if (o->base.type == &mp_type_memoryview) {
417-
if ((o->typecode & 0x80) == 0) {
417+
if (!(o->typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
418418
// store to read-only memoryview not allowed
419419
return MP_OBJ_NULL;
420420
}
@@ -471,7 +471,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
471471
#if MICROPY_PY_BUILTINS_MEMORYVIEW
472472
if (o->base.type == &mp_type_memoryview) {
473473
index += o->free;
474-
if (value != MP_OBJ_SENTINEL && (o->typecode & 0x80) == 0) {
474+
if (value != MP_OBJ_SENTINEL && !(o->typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
475475
// store to read-only memoryview
476476
return MP_OBJ_NULL;
477477
}
@@ -497,7 +497,7 @@ STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_ui
497497
bufinfo->typecode = o->typecode & TYPECODE_MASK;
498498
#if MICROPY_PY_BUILTINS_MEMORYVIEW
499499
if (o->base.type == &mp_type_memoryview) {
500-
if ((o->typecode & 0x80) == 0 && (flags & MP_BUFFER_WRITE)) {
500+
if (!(o->typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW) && (flags & MP_BUFFER_WRITE)) {
501501
// read-only memoryview
502502
return 1;
503503
}

py/objarray.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
#include "py/obj.h"
3131

32+
// Used only for memoryview types, set in "typecode" to indicate a writable memoryview
33+
#define MP_OBJ_ARRAY_TYPECODE_FLAG_RW (0x80)
34+
3235
typedef struct _mp_obj_array_t {
3336
mp_obj_base_t base;
3437
size_t typecode : 8;

0 commit comments

Comments
 (0)