To expand further on the problem I'm running into, take the following C
function:

--------------------
#include <string.h>

typedef struct T {
        char a[260];
        int32_t  b;
} T;

void setTest(T *t)
{
        (void)memset(t->a, 'T', 260);
        t->b = 1;
}
---------------------

gcc -c -O3 -Wextra -Wall -Wno-unused-parameter -Wno-unused-function
-Wno-missing-braces -Werror=pointer-arith -O3 -DNDEBUG -D_REENTRANT
-D_FILE_OFFSET_BITS=64 -DMVM_HEAPSNAPSHOT_FORMAT=2 -o test.o test.c
gcc -shared -fPIC -O3 -DNDEBUG -Wl,-rpath,"//opt/rakudo-pkg/lib" -o test.so
test.o

... and the following raku program:

---------------------
#!/usr/bin/env raku

use NativeCall;

class T is repr('CStruct') {
        HAS int8 @.a[260] is CArray;
        has int32 $.b;
};

sub setTest(T) is native('./test.so') { * };

my T $t .= new;
setTest($t);
say $t.a[0];
say $t.b;
---------------------

Running this yields:

# ./test.raku
0
1

What's expected is:

# ./test.raku
T
1

On Sun, Jan 3, 2021 at 1:29 AM Paul Procacci <pproca...@gmail.com> wrote:

> A follow-up to my initial message.
>
> I think the following is relevant:
>
> https://github.com/rakudo/rakudo/issues/3633
>
> I think my inlined array is actually being filled with zero's.
>
> say $a.a[0];
> say $a.a[1];
>
> Yields:
>
> 0
> 0
>
> I'm using the comma ide:
>
> >raku -v
> Welcome to Rakudo(tm) v2020.12.
> Implementing the Raku(tm) programming language v6.d.
> Built on MoarVM version 2020.12.
>
> ~Paul
>
> On Sat, Jan 2, 2021 at 11:13 PM Paul Procacci <pproca...@gmail.com> wrote:
>
>> Hey gents (again),
>>
>> I'm having on awful time with decoding UTF16LE character sequences that
>> are placed into a Nativecall CArray that I've defined as an interface
>> between Raku and a windows library call.
>>
>> The structure used by the windows function includes a static wchar_t
>> field that's PATH_MAX in
>> length (260 wchar_t's).  It would look like the following in C:
>>
>> struct Something {
>>   int32_t dwSize;
>>   wchar_t a[260];
>> };
>>
>> I've written the following as the Raku counterpart to the above:
>>
>> class Something is repr('CStruct') {
>>    has int32 $.dwsize;
>>    HAS int16 @.a[260] is CArray;
>> };
>>
>> Given the following definition for the windows library call:
>>
>> bool Test(Something *x);
>>
>> .. I've defined the following on the raku side of things:
>>
>> sub Test(Pointer --> Bool) is native('Kernel32') { * };
>>
>> ----------------------------------------------------------
>>
>> The function is supposed to write characters into the space allotted,
>> namely a.
>> The only required set member prior to calling the subroutine is that the
>> size of the structure.
>> It gets set in dwSize like so:
>>
>> my Something $a .= new(:dwSize(nativesizeof(Something)));
>>
>> Then the actual function call from the raku side of things:
>>
>> Test(nativecast(Pointer, $a));
>>
>> ----------------------------------------------------------
>>
>> All the above is working.  What I'm trying to attempt to do now is
>> display the contents of that
>> CArray (raku member a).  In my mind, this is an "array of utf16LE byte
>> sequences terminated by 0".
>>
>> What's the cleanest way of doing this in raku?  I've tried variations of
>> "join" and "encode", simple printf's, say's, etc., and even tried
>> manipulating this data with Buf's, but I can't seem to get it quite right.
>>
>> Any help is appreciated.
>> ~Paul
>> --
>> __________________
>>
>> :(){ :|:& };:
>>
>
>
> --
> __________________
>
> :(){ :|:& };:
>


-- 
__________________

:(){ :|:& };:

Reply via email to