I am trying to get this example of NativeCall
running:
use NativeCall;
class p_timespec is repr('CPointer') {
has uint32 $.tv_sec;
has long $.tv_nanosecs;
}
sub clock_gettime(uint32 $clock-id, p_timespec $tspec --> uint32) is native(Str) { * };
my p_timespec $this-time;
my $result = clock_gettime( 0, $this-time);
say "$result, $this-time";
It simply segfaults, which is what happens when you use pointers and you should not. In this case, it's probably due to the declaration of p_timespec
; I have actually declared it as a CPointer
, although the struct should be OK. However, from the segmentation fault I can't fathom what's really wrong. Can someone help?
CStruct
insetad ofCPointer
? Atributes on aCPointer
make no sense and probably should be made to throw a compiler error... – Christoph Apr 24 '18 at 9:28p_timespec.tv_sec
for your system? On my system it should be anint64
, notuint32
– Kaiepi Apr 24 '18 at 10:25Time::HiRes
by any chance? – Elizabeth Mattijsen Apr 24 '18 at 12:38