|Date:||Mon, 29 May 2017 17:37:54 +0000|
|From:||Benjamin Goldberg <ben-goldberg [...] hotmail.com>|
|To:||"rakudobug [...] perl.org" <rakudobug [...] perl.org>|
|Subject:||Feature Request: Better NativeCall Array termination|
There are lots of C APIs where a data structure has an array of pointers, with a NULL value indicating where that array ends.
It would be nice if I could tell NativeCall that some CArray returned by some C function is such an array, and prevent the user from reading the NULL, or anything beyond it.
This could also automatically append a NULL if necessary when a NativeCall managed CArray is passed to some C function.
my $environ = cglobal( Str, ‘environ’, CArray[Str] is NULL-terminated );
my %e = map split( ‘=’, *, 2 ), @$environ;
There are also C functions where the length is passed as a separate integer. It would be nice if, for this type of API, a CArray could be given an explicit length, which would then prevent the user from accidentally reading beyond the end of the array.
Perhaps something like:
sub poll( CArray[pollfd] $fds, int32 $nfds, int32 timeout –> int32 is CArray-elems(‘$fds’) ) is native;
It would also be nice if CArray did the role Iterable, though obviously only if it’s NULL terminated or the length has been assigned to.