Skip to content

Commit

Permalink
py/objarray: Allow to create array of void pointers, as extension to …
Browse files Browse the repository at this point in the history
…CPython.

Using 'P' format specifier (matches struct module). This is another shortcut
for FFI, just as previously introduced "array of objects" ('O').
  • Loading branch information
pfalcon committed Oct 12, 2015
1 parent 3aa7dd2 commit 91fc075
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions py/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 91fc075

Please sign in to comment.