I try to wrap sd-bus with perl6, but have problem with a function call triple pointer.
from sd-bus.h
int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable); /* free the results */
try with native call
sub sd_bus_list_names(Pointer, Pointer[CArray[Str]] , Pointer[CArray[Str]] ) returns int32 is native('systemd') {*}
I call but I don't know how to dereferencies to array(@) the acquired and activable variable.
thank's, and sorry for my english
[EDIT]
dwarring reply solve my problem to derefencies Pointer[CArray[Str]]
this is a test code:
use v6;
use NativeCall;
sub strerror(int32) returns Str is native {*}
sub sd_bus_default_system(Pointer is rw) returns int32 is native('systemd') {*}
sub sd_bus_unref(Pointer) returns Pointer is native('systemd') {*}
sub sd_bus_list_names(Pointer,Pointer[CArray[Str]] is rw, Pointer[CArray[Str]] is rw ) returns int32 is native('systemd') {*}
my Pointer $bus .= new;
my int32 $error;
$error=sd_bus_default_system($bus);
if $error < 0 {
my Str $ser = strerror(-$error);
die "fail, can't test triple pointer, dbus return error $error $ser";
}
my Pointer[CArray[Str]] $acq .= new;
my Pointer[CArray[Str]] $act .= new;
$error=sd_bus_list_names($bus,$acq,$act);
my @love6acq;
loop (my $i = 0; $acq.deref[$i]; $i++){
@love6acq.push: $acq.deref[$i];
}
@love6acq.say;
my @love6act;
loop (my $i = 0; $act.deref[$i]; $i++){
@love6act.push: $act.deref[$i];
}
@love6act.say;
sd_bus_unref($bus);
The following stand-alone experiment, works for me:
C code:
Raku code:
Using this approach (but untested), you need to add
is rw
to the signature and create the pointers before calling: