Kai*_*epi 4 c perl6 nativecall raku
我希望能够在REPR CStruct/CPointer的类中使用双指针:
typedef struct CipherContext {
void *cipher;
const uint8_t *key;
size_t key_len;
const uint8_t *path;
size_t path_len;
size_t block_size;
void *handle;
int (*cipher_init)(void **, const uint8_t *, size_t);
int (*cipher_encode)(void *, const uint8_t *, uint8_t *, size_t);
int (*cipher_decode)(void *, const uint8_t *, uint8_t *, size_t);
void (*cipher_free)(void *);
const uint8_t *(*cipher_strerror)(int);
} CipherContext;
int cipher_context_init(CipherContext **, const uint8_t *, size_t, const uint8_t *, size_t, size_t);
int cipher_context_encode(CipherContext *, const uint8_t *, uint8_t *, size_t);
int cipher_context_decode(CipherContext *, const uint8_t *, uint8_t *, size_t);
void cipher_context_free(CipherContext *);
const uint8_t *cipher_context_strerror(int);
Run Code Online (Sandbox Code Playgroud)
Perl 6代码:
method new(Blob :$key!, Str :$path!, Int :$block-size!) {
my Pointer[::?CLASS] $ptr .= new;
my Int $err = cipher_context_init($ptr, $key, $key.elems, $path, $path.codes, $block-size);
return $ptr.deref unless $err;
my Str $errstr = cipher_context_strerror($err) || do {
my &cipher-strerror = nativecast(:(int32 --> Str), $!cipher-strerror);
cipher-strerror($err)
};
die "Failed to initialize cipher context: $errstr";
}
submethod DESTROY() {
cipher_context_free(self)
}
Run Code Online (Sandbox Code Playgroud)
短杆:
use v6.d;
use Nativecall;
class Foo is repr('CPointer') {
my Pointer[::?CLASS] $foo .= nw;
}
Run Code Online (Sandbox Code Playgroud)
由于Rakudo中的一个错误,我无法弄清楚如何做到这一点.有没有更好的方法可以处理代码的C部分中的错误(这就是为什么我这样写它)?
失败的原因与失败相同:
class Foo {...}
BEGIN Foo ~~ Bool; # <------
class Foo{
}
Run Code Online (Sandbox Code Playgroud)
部分问题似乎Foo是Pointer.^parameterize在调用方法时尚未编写.
所以它还不是一个子类型Any.(甚至Mu)
解决方法是.^compose在BEGIN使用之前在移相器中添加呼叫Pointer[::??CLASS].
class Foo is repr('CPointer') {
BEGIN ::?CLASS.^compose;
my Pointer[::?CLASS] $foo .= new;
}
Run Code Online (Sandbox Code Playgroud)
我的猜测是真正的解决方案是将Bool.ACCEPTS(Bool:U: \topic)候选人改为Bool.ACCEPTS(Bool:U: Mu \topic).
我认为这是因为这也失败了基本相同的错误:
Mu ~~ Bool
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76 次 |
| 最近记录: |