Last active
January 9, 2016 10:41
-
-
Save Altai-man/d2fb78521fe2eb62ae73 to your computer and use it in GitHub Desktop.
Native call expected return type with CArray representation, but got a VMArray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use NativeCall; | |
# Needed bindings. | |
our sub fopen(Str $filename, Str $mode) returns OpaquePointer is | |
native() { ... } | |
our sub close(OpaquePointer $handle) is native() { ... } | |
# Bingings to bzip2(only needed parts). | |
our sub BZ2_bzWriteOpen(Pointer[int32], OpaquePointer, int32, int32, int32) returns OpaquePointer is native("/lib/libbz2.so.1") is export { * } | |
our sub BZ2_bzWrite(Pointer[int32], OpaquePointer, CArray[uint8], int32) is native("/lib/libbz2.so.1") is export { * } | |
# Code for testing. | |
my $text = CArray[uint8].new; | |
$text = "Test string.\n".encode; | |
my $filename = fopen("/tmp/test.bz2", "wb"); | |
my $bzerror = Pointer[int32]; | |
my $bz = BZ2_bzWriteOpen($bzerror, $filename, 1, 1, 0); | |
BZ2_bzWrite($bzerror, $bz, $text, 15); # Obviously error is here. | |
close($filename); | |
# C headers: | |
#BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( // It'll be just "BZ2_bzWriteOpen" | |
# int* bzerror, | |
# FILE* f, | |
# int blockSize100k, | |
# int verbosity, | |
# int workFactor | |
# ); | |
#BZ_EXTERN void BZ_API(BZ2_bzWrite) ( | |
# int* bzerror, | |
# BZFILE* b, | |
# void* buf, | |
# int len | |
# ); |
jonathanstowe
commented
Jan 9, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment