# New Ticket Created by Benjamin Goldberg
# Please include the string: [perl #131399]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=131399 >
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.
For example:
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.