Description
Feature
When registering native functions, allow registering array types other than byte arrays for automatic length checking.
Benefit
Currently, functions that take arrays of 16-64 bit types must implement manual validity checking for their memory. Adding support for these types would make embedding easier in many cases.
Implementation
I suggest that the ~
marker be allowed to be prefixed with a number indicating the length is the number of elements of a type with that many bits (or bytes) - with 8
(or 1) being assumed if not given. For a bits example, where you would currently export unsigned char* buffer, size_t length
as *~
, for uint32_t* items, size_t num_items
, you would export this as *32~
.
When checking the memory, the size of the memory range check is then set to count_parameter * (num_bits / 8)
Alternatives
One alternative is for apps to perform this checking themselves in each wrapper function. This is inconvenient, because it involves writing repetitive code that may be buggy. It also may be inefficient - if the wrapper wants to use *~
for byte buffers, and currently uses *i
plus manual checks for other arrays, then the length must be checked twice (once automatically, and once in the wrapper to check the actual length). To avoid the inefficiency, wrapper functions must mix *
and i
wrapping for pointers/arrays, which is again, bug prone and messy.