Skip Menu |
Report information
Id: 131399
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: ben-goldberg [at]

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)

Date: Mon, 29 May 2017 17:37:54 +0000
From: Benjamin Goldberg <ben-goldberg [...]>
To: "rakudobug [...]" <rakudobug [...]>
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.
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.

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at