Skip to content

Commit 91fc075

Browse files
committed
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').
1 parent 3aa7dd2 commit 91fc075

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

py/binary.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
145145
// Extension to CPython: array of objects
146146
case 'O':
147147
return ((mp_obj_t*)p)[index];
148+
// Extension to CPython: array of pointers
149+
case 'P':
150+
return mp_obj_new_int((mp_int_t)((void**)p)[index]);
148151
}
149152
return MP_OBJ_NEW_SMALL_INT(val);
150153
}
@@ -369,5 +372,8 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
369372
((double*)p)[index] = val;
370373
break;
371374
#endif
375+
// Extension to CPython: array of pointers
376+
case 'P':
377+
((void**)p)[index] = (void*)val;
372378
}
373379
}

0 commit comments

Comments
 (0)