develooper Front page | perl.perl6.users | Postings from May 2020

Re: NativeCall questions

Thread Previous | Thread Next
From:
Curt Tilmes
Date:
May 8, 2020 12:56
Subject:
Re: NativeCall questions
Message ID:
CAMv20O9a7Ht6kSh_jVxRTXBDsG8hkU44JcAGbbQ2Hbv_W4wAEg@mail.gmail.com
On Fri, May 8, 2020 at 8:49 AM David Santiago <demanuel@gmail.com> wrote:

> EncodedData* ed = malloc(sizeof(EncodedData));
> ed->data = encbuffer;
> ed->crc32 = crc32;
> return ed;

You're returning a pointer to encbuffer -- make sure the storage for
that is kept around
somewhere.  If it is passed in from Raku, you'll be fine as long as
you hold on to the
object on that side.  Otherwise you might need to allocate/copy it to make sure.

> class EncodedData is repr('CStruct') {
>     has CArray[uint8] $.data;
>     has uint32 $.crc32;
> }

That's fine, but CArray[uint8] is just a pointer -- it doesn't know
how long the array
it is pointing to is.  It either needs a sentinel at the end (like the
Nul at the end of a
C string), or a separate field with a size to figure that out.

> Don't know how many elements a C array returned from a library

yep

Curt

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About