Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Better NativeCall Array termination #6292

Open
p6rt opened this issue May 30, 2017 · 1 comment
Open

Feature Request: Better NativeCall Array termination #6292

p6rt opened this issue May 30, 2017 · 1 comment

Comments

@p6rt
Copy link

p6rt commented May 30, 2017

Migrated from rt.perl.org#131399 (status was 'new')

Searchable as RT131399$

@p6rt
Copy link
Author

p6rt commented May 30, 2017

From @BenGoldberg1

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant