Skip to content

Commit 9dd4cef

Browse files
committed
py/objarray: Add MP_DEFINE_MEMORYVIEW_OBJ convenience macro.
This allows defining a `memoryview` instance, either statically or on the C stack. Signed-off-by: Damien George <[email protected]>
1 parent 6be7570 commit 9dd4cef

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

py/objarray.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,18 @@ typedef struct _mp_obj_array_t {
5353
} mp_obj_array_t;
5454

5555
#if MICROPY_PY_BUILTINS_MEMORYVIEW
56+
57+
#define MP_DEFINE_MEMORYVIEW_OBJ(obj_name, typecode, offset, len, ptr) \
58+
mp_obj_array_t obj_name = {{&mp_type_memoryview}, (typecode), (offset), (len), (ptr)}
59+
5660
static inline void mp_obj_memoryview_init(mp_obj_array_t *self, size_t typecode, size_t offset, size_t len, void *items) {
5761
self->base.type = &mp_type_memoryview;
5862
self->typecode = typecode;
5963
self->free = offset;
6064
self->len = len;
6165
self->items = items;
6266
}
67+
6368
#endif
6469

6570
#if MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY

0 commit comments

Comments
 (0)