我尝试用 perl6 包装 sd-bus,但是函数调用三重指针有问题。
来自 sd-bus.h
int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable); /* free the results */
尝试本地调用
sub sd_bus_list_names(Pointer, Pointer[CArray[Str]] , Pointer[CArray[Str]] ) returns int32 is native('systemd') {*}
我打电话,但我不知道如何取消对 array(@) 获取和可激活变量的引用。
谢谢,对不起我的英语
[编辑]
dwarring 回复解决了我对 derefencies Pointer[CArray[Str]] 的问题
这是一个测试代码:
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);