This is a repost from an improperly worded email.
That previous email thread divulged into things it shouldn't have to which
I'm partially to blame.
This isn't Windows specific - the problem occurs across platforms.

This is simply about the proper way to define an *inline* array of items in
a Raku CStruct definition.  It's also about the retrieval of those stored
values.
The type of items aren't relevant. char[n], int[n], int16[n], etc ... it
doesn't matter one bit.

Given the following C structure:

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

and given the following C function body:

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

 I presumed this would be defined as follows in Raku[1]:

class T is repr('CStruct') {
>         HAS int8 @.a[260] is CArray;
>         has int32 $.b;
> };
>
> sub setTest(T) is native('./test.so') { * };
>

and invoked as such:

my T $t .= new;
> setTest($t);
>

While the value of the member 'b' gets set to 1 as expected, I cannot
inspect the values that should be stored at the memory location referenced
by member 'a[0]..a[n]'.

Conversely, the following C program snippet that utilizes the same C
function provides the output one would expect:

extern void setTest(T *);
>
> T t;
>
> int main(void)
> {
>         setTest(&t);
>         printf("%c\n%d\n", t.a[0], t.b);
>         _exit(0);
> }
>

So the questions are:

1) How does one define an *inline* array of whatever size in Raku (size
doesn't matter)
2) How does one retrieve the values stored in that defined array after the
callee populates it.

Thanks,
~Paul

[1] - test.so is the shared object that I created for testing.
-- 
__________________

:(){ :|:& };:

Reply via email to