From 91fc075a33a6f0bf8e1a07b797f6fd01207a5e17 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 12 Oct 2015 10:10:39 +0300 Subject: [PATCH] py/objarray: Allow to create array of void pointers, as extension to CPython. Using 'P' format specifier (matches struct module). This is another shortcut for FFI, just as previously introduced "array of objects" ('O'). --- py/binary.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/py/binary.c b/py/binary.c index d8f865ebe5..71ef3f04d5 100644 --- a/py/binary.c +++ b/py/binary.c @@ -145,6 +145,9 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) { // Extension to CPython: array of objects case 'O': return ((mp_obj_t*)p)[index]; + // Extension to CPython: array of pointers + case 'P': + return mp_obj_new_int((mp_int_t)((void**)p)[index]); } return MP_OBJ_NEW_SMALL_INT(val); } @@ -369,5 +372,8 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m ((double*)p)[index] = val; break; #endif + // Extension to CPython: array of pointers + case 'P': + ((void**)p)[index] = (void*)val; } }