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
SEGV with "output" CArray[Cstruct] in NativeCall #5182
Comments
From @jonathanstoweI found this trying to make a binding for portmidi. If one has library function that takes an argument of an array of structs that has been allocated by the caller and populated by the function like: #include <stdint.h> typedef struct { int Pm_Read(Event *buffer, int length) { And then attempt to use it in a Perl 6 progran like: use NativeCall; class Event is repr('CStruct') { sub Pm_Read(CArray[Event] $e, int32 $l) returns int32 is native('./test') { * } my $a = CArray[Event].new; Pm_Read($a, 1); say $a[0]; It will segfault trying to print the populated struct with: Program received signal SIGSEGV, Segmentation fault. (The backtrace is basically the same in the "real" code.) If the Perl code is altered so that it is passing an array of int64 instead then it gets the "right" response: use NativeCall; sub Pm_Read(CArray[int64] $e, int32 $l) returns int32 is native('./test') { * } my $a = CArray[int64].new; Pm_Read($a, 1); say $a[0]; it would seem that the CStruct case is doing something like de-referencing the value. This case doesn't appear to be tested for in the NC tests. |
From @jonathanstoweI've realised that this is because it is actually expecting Event **buffer Rather than Event *buffer Which is a flat array of structs rather than pointers to the structs. So it's still a bug, it's just the bug is that it can only deal with arrays of pointers to structs and not the structs themselves. In this particular case it can be worked round (as demonstrated,) however this would be a problem if the struct was larger than 64bits. |
Migrated from rt.perl.org#127730 (status was 'new')
Searchable as RT127730$
The text was updated successfully, but these errors were encountered: