Hi All,

https://docs.raku.org/language/nativecall.html#Passing_and_returning_values

Did anyone else discover the mistake, hopefully not the hard way like I
did.  Anyone get weird gibberish printed out like I did?

   my$string="FOO";
   # The lifetime of this variable must be equal to the required lifetime of
   # the data passed to the C function.
   my$array=CArray[uint8].new($string.encode.list);v

The mistake is that "C" strings are terminated by a chr(0) -- in
"C" terms chr(0) is called a nul or 0x00.

If you don't terminate your C string, the reading functions keep careening
until it finds a chr(0).  You have to tack a chr(0) onto the end.

   my$array=CArray[uint8].new($string.encode.list);
   $array [$array.elems] = 0;

$array should be 70 79 70 0  not  70 79 79
You can test this with `say "$array"` (include the quotes).

Maybe JJ will pick up on this and get it fixed.

-T

Reply via email to