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

Re: NativeCall questions

Thread Previous | Thread Next
David Santiago
May 8, 2020 12:49
Re: NativeCall questions
Message ID:
Thanks for the help.

> EncodedData *encode(unsigned char* data, size_t data_size)
> and return &ed.
> Also your struct and CStruct are defining the contents in the reverse
> order.  They must
> match up exactly.

I did those two changes:
EncodedData* ed = malloc(sizeof(EncodedData));
ed->data = encbuffer;
ed->crc32 = crc32;
return ed;

And i also changed the CStruct [1] to:

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

I'm not getting a SIGSEGV anymore, however i'm now getting the
following error when trying to "say $_ for $":

Don't know how many elements a C array returned from a library
  in method elems at
(NativeCall::Types) line 223
  in method list at
(NativeCall::Types) line 226
  in sub MAIN at bin/uints.p6 line 15
  in block <unit> at bin/uints.p6 line 3

I can access without problems $ed.crc32

[1] - if i change the data type to str i get the error: "String
corruption detected: bad storage type"

Best regards,
David Santiago

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About