On 2019-12-31 09:17, JJ Merelo wrote:
Hi,

El mar., 31 dic. 2019 a las 5:54, Todd Chester via perl6-users (<perl6-us...@perl.org <mailto:perl6-us...@perl.org>>) escribió:

    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.



I don't always read this list, but I do read issues. If you put it there, it will be definitely get addressed when possible.

--
JJ


Hi JJ,

I have a rule about not posting to that list, so maybe
you or someone else will pick it up.

-T

Reply via email to