aboutsummaryrefslogtreecommitdiff
path: root/py/objarray.h
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2018-09-16 13:41:30 +0300
committerDamien George <damien.p.george@gmail.com>2018-12-20 17:40:48 +1100
commita261d8b615298a7ade5c2aebf50e97d089c56667 (patch)
treead3ace3e3e0a53203c9490028139e8cab828704c /py/objarray.h
parent39eef270831323b77445e0458c9357d38e23658a (diff)
py/objarray: Introduce "memview_offset" alias for "free" field of object
Both mp_type_array and mp_type_memoryview use the same object structure, mp_obj_array_t, but for the case of memoryview, some fields, e.g. "free", have different meaning. As the "free" field is also a bitfield, assume that (anonymous) union can't be used here (for the concerns of possible compatibility issues with wide array of toolchains), and just add a field alias using a #define. As it's a define, it should be a selective identifier, so use verbose "memview_offset" to avoid any clashes.
Diffstat (limited to 'py/objarray.h')
-rw-r--r--py/objarray.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/objarray.h b/py/objarray.h
index 0dad70571..2fb6e2c91 100644
--- a/py/objarray.h
+++ b/py/objarray.h
@@ -32,11 +32,18 @@
// Used only for memoryview types, set in "typecode" to indicate a writable memoryview
#define MP_OBJ_ARRAY_TYPECODE_FLAG_RW (0x80)
+// This structure is used for all of bytearray, array.array, memoryview
+// objects. Note that memoryview has different meaning for some fields,
+// see comment at the beginning of objarray.c.
typedef struct _mp_obj_array_t {
mp_obj_base_t base;
size_t typecode : 8;
// free is number of unused elements after len used elements
// alloc size = len + free
+ // But for memoryview, 'free' is reused as offset (in elements) into the
+ // parent object. (Union is not used to not go into a complication of
+ // union-of-bitfields with different toolchains). See comments in
+ // objarray.c.
size_t free : (8 * sizeof(size_t) - 8);
size_t len; // in elements
void *items;