--000000000000b4d4dc05b8092eb4 Content-Type: text/plain; charset="UTF-8" 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. -- __________________ :(){ :|:& };: --000000000000b4d4dc05b8092eb4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>This is a repost from an improperly worded email.<br>= </div><div>That previous email thread divulged into things it shouldn't= have to which I'm partially to blame.</div><div>This isn't Windows= specific - the problem occurs across platforms.<br></div><div><br></div><d= iv>This is simply about the proper way to define an *inline* array of items= in a Raku CStruct definition.=C2=A0 It's also about the retrieval of t= hose stored values.<br></div><div>The type of items aren't relevant. ch= ar[n], int[n], int16[n], etc ... it doesn't matter one bit.<br><br></di= v><div>Given the following C structure:</div><div><br></div><blockquote cla= ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid = rgb(204,204,204);padding-left:1ex"><div>typedef struct T {<br>=C2=A0 =C2=A0= =C2=A0 =C2=A0 char a[260];<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 int32_t=C2=A0 b;= <br>} T;<br></div></blockquote><div><br></div><div>and given the following = C function body:</div><div><br></div><div><blockquote class=3D"gmail_quote"= style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p= adding-left:1ex">void setTest(T *t){<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (void)m= emset(t->a, 'T', 260);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t->b = =3D 1;<br>}<br></blockquote><div><br></div><div>=C2=A0I presumed this would= be defined as follows in Raku[1]:<br><br><blockquote class=3D"gmail_quote"= style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p= adding-left:1ex">class T is repr('CStruct') {<br>=C2=A0 =C2=A0 =C2= =A0 =C2=A0 HAS int8 @.a[260] is CArray;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 has = int32 $.b;<br>};<br><br>sub setTest(T) is native('./test.so') { * }= ;<br></blockquote></div>=C2=A0 <br></div><div>and invoked as such:<br><br><= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">my T $t .=3D new;<br>setTe= st($t);<br></blockquote></div><div><br></div><div>While the value of the me= mber 'b' gets set to 1 as expected, I cannot inspect the values tha= t should be stored at the memory location referenced by member 'a[0]..a= [n]'.<br><br></div><div>Conversely, the following C program snippet tha= t utilizes the same C function provides the output one would expect:<br><br= ></div><div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0= ..8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">extern void s= etTest(T *);<br><br>T t;<br><br>int main(void)<br>{<br>=C2=A0 =C2=A0 =C2=A0= =C2=A0 setTest(&t);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("%c\n%d= \n", t.a[0], t.b);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 _exit(0);<br>}<br></= blockquote><br></div><div>So the questions are:<br><br></div><div>1) How do= es one define an *inline* array of whatever size in Raku (size doesn't = matter)<br></div><div>2) How does one retrieve the values stored in that de= fined array after the callee populates it.<br></div><div><br></div><div>Tha= nks,</div><div>~Paul<br></div><div><br></div><div>[1] - test.so is the shar= ed object that I created for testing.<br></div><div>-- <br><div dir=3D"ltr"= class=3D"gmail_signature" data-smartmail=3D"gmail_signature">_____________= _____<br><br>:(){ :|:& };:</div></div></div> --000000000000b4d4dc05b8092eb4--
![]() |
0 |
![]() |
--0000000000008d026305b80e1b65 Content-Type: text/plain; charset="UTF-8" Hello, Maybe the behavior you're seeing is related to this bug: https://github.com/rakudo/rakudo/issues/3633 For what I was concerned, Raku 2020.10 solved the problem, but since the issue was reopened right after I closed it, I imagine the problem is still lingering. Perhaps you can add some remarks to that issue; your example code might help to clarify the problem. On Mon, Jan 4, 2021 at 2:41 AM Paul Procacci <pprocacci@gmail.com> wrote: > 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. > -- > __________________ > > :(){ :|:& };: > -- Fernando Santagata --0000000000008d026305b80e1b65 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_default" style=3D"color:#000000">Hello= ,</div><div class=3D"gmail_default" style=3D"color:#000000"><br></div><div = class=3D"gmail_default" style=3D"color:#000000">Maybe the behavior you'= re seeing is related to this bug:<br></div><div class=3D"gmail_default" sty= le=3D"color:#000000"><br></div><div class=3D"gmail_default" style=3D"color:= #000000"><a href=3D"https://github.com/rakudo/rakudo/issues/3633">https://g= ithub.com/rakudo/rakudo/issues/3633</a></div><div class=3D"gmail_default" s= tyle=3D"color:#000000"><br></div><div class=3D"gmail_default" style=3D"colo= r:#000000">For what I was concerned, Raku 2020.10 solved the problem, but s= ince the issue was reopened right after I closed it, I imagine the problem = is still lingering.</div><div class=3D"gmail_default" style=3D"color:#00000= 0">Perhaps you can add some remarks to that issue; your example code might = help to clarify the problem.<br></div></div><br><div class=3D"gmail_quote">= <div dir=3D"ltr" class=3D"gmail_attr">On Mon, Jan 4, 2021 at 2:41 AM Paul P= rocacci <<a href=3D"mailto:pprocacci@gmail.com">pprocacci@gmail.com</a>&= gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0= px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div = dir=3D"ltr"><div>This is a repost from an improperly worded email.<br></div= ><div>That previous email thread divulged into things it shouldn't have= to which I'm partially to blame.</div><div>This isn't Windows spec= ific - the problem occurs across platforms.<br></div><div><br></div><div>Th= is is simply about the proper way to define an *inline* array of items in a= Raku CStruct definition.=C2=A0 It's also about the retrieval of those = stored values.<br></div><div>The type of items aren't relevant. char[n]= , int[n], int16[n], etc ... it doesn't matter one bit.<br><br></div><di= v>Given the following C structure:</div><div><br></div><blockquote class=3D= "gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2= 04,204,204);padding-left:1ex"><div>typedef struct T {<br>=C2=A0 =C2=A0 =C2= =A0 =C2=A0 char a[260];<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 int32_t=C2=A0 b;<br>= } T;<br></div></blockquote><div><br></div><div>and given the following C fu= nction body:</div><div><br></div><div><blockquote class=3D"gmail_quote" sty= le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi= ng-left:1ex">void setTest(T *t){<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (void)memse= t(t->a, 'T', 260);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t->b =3D 1;= <br>}<br></blockquote><div><br></div><div>=C2=A0I presumed this would be de= fined as follows in Raku[1]:<br><br><blockquote class=3D"gmail_quote" style= =3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding= -left:1ex">class T is repr('CStruct') {<br>=C2=A0 =C2=A0 =C2=A0 =C2= =A0 HAS int8 @.a[260] is CArray;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 has int32 $= ..b;<br>};<br><br>sub setTest(T) is native('./test.so') { * };<br></= blockquote></div>=C2=A0 <br></div><div>and invoked as such:<br><br><blockqu= ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px= solid rgb(204,204,204);padding-left:1ex">my T $t .=3D new;<br>setTest($t);= <br></blockquote></div><div><br></div><div>While the value of the member &#= 39;b' gets set to 1 as expected, I cannot inspect the values that shoul= d be stored at the memory location referenced by member 'a[0]..a[n]'= ;.<br><br></div><div>Conversely, the following C program snippet that utili= zes the same C function provides the output one would expect:<br><br></div>= <div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo= rder-left:1px solid rgb(204,204,204);padding-left:1ex">extern void setTest(= T *);<br><br>T t;<br><br>int main(void)<br>{<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0= setTest(&t);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("%c\n%d\n"= ;, t.a[0], t.b);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 _exit(0);<br>}<br></blockqu= ote><br></div><div>So the questions are:<br><br></div><div>1) How does one = define an *inline* array of whatever size in Raku (size doesn't matter)= <br></div><div>2) How does one retrieve the values stored in that defined a= rray after the callee populates it.<br></div><div><br></div><div>Thanks,</d= iv><div>~Paul<br></div><div><br></div><div>[1] - test.so is the shared obje= ct that I created for testing.<br></div><div>-- <br><div dir=3D"ltr">______= ____________<br><br>:(){ :|:& };:</div></div></div> </blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g= mail_signature">Fernando Santagata</div> --0000000000008d026305b80e1b65--
![]() |
0 |
![]() |
--000000000000c48ae305b80e6741 Content-Type: text/plain; charset="UTF-8" Thanks for that. I did see that but neglected to add my 2 cents. I just have though. ~Paul On Sun, Jan 3, 2021 at 8:40 PM Paul Procacci <pprocacci@gmail.com> wrote: > 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. > -- > __________________ > > :(){ :|:& };: > -- __________________ :(){ :|:& };: --000000000000c48ae305b80e6741 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>Thanks for that.</div><div>I did see that but neglect= ed to add my 2 cents.</div><div>I just have though.</div><div><br></div><di= v>~Paul<br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" clas= s=3D"gmail_attr">On Sun, Jan 3, 2021 at 8:40 PM Paul Procacci <<a href= =3D"mailto:pprocacci@gmail.com">pprocacci@gmail.com</a>> wrote:<br></div= ><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border= -left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>Th= is is a repost from an improperly worded email.<br></div><div>That previous= email thread divulged into things it shouldn't have to which I'm p= artially to blame.</div><div>This isn't Windows specific - the problem = occurs across platforms.<br></div><div><br></div><div>This is simply about = the proper way to define an *inline* array of items in a Raku CStruct defin= ition.=C2=A0 It's also about the retrieval of those stored values.<br><= /div><div>The type of items aren't relevant. char[n], int[n], int16[n],= etc ... it doesn't matter one bit.<br><br></div><div>Given the followi= ng C structure:</div><div><br></div><blockquote class=3D"gmail_quote" style= =3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding= -left:1ex"><div>typedef struct T {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 char a[26= 0];<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 int32_t=C2=A0 b;<br>} T;<br></div></bloc= kquote><div><br></div><div>and given the following C function body:</div><d= iv><br></div><div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px= 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">void se= tTest(T *t){<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (void)memset(t->a, 'T= 9;, 260);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t->b =3D 1;<br>}<br></blockquot= e><div><br></div><div>=C2=A0I presumed this would be defined as follows in = Raku[1]:<br><br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0= px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">class T i= s repr('CStruct') {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 HAS int8 @.a[260= ] is CArray;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 has int32 $.b;<br>};<br><br>sub= setTest(T) is native('./test.so') { * };<br></blockquote></div>=C2= =A0 <br></div><div>and invoked as such:<br><br><blockquote class=3D"gmail_q= uote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,2= 04);padding-left:1ex">my T $t .=3D new;<br>setTest($t);<br></blockquote></d= iv><div><br></div><div>While the value of the member 'b' gets set t= o 1 as expected, I cannot inspect the values that should be stored at the m= emory location referenced by member 'a[0]..a[n]'.<br><br></div><div= >Conversely, the following C program snippet that utilizes the same C funct= ion provides the output one would expect:<br><br></div><div><blockquote cla= ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid = rgb(204,204,204);padding-left:1ex">extern void setTest(T *);<br><br>T t;<br= ><br>int main(void)<br>{<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 setTest(&t);<br= >=C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("%c\n%d\n", t.a[0], t.b);<br>= =C2=A0 =C2=A0 =C2=A0 =C2=A0 _exit(0);<br>}<br></blockquote><br></div><div>S= o the questions are:<br><br></div><div>1) How does one define an *inline* a= rray of whatever size in Raku (size doesn't matter)<br></div><div>2) Ho= w does one retrieve the values stored in that defined array after the calle= e populates it.<br></div><div><br></div><div>Thanks,</div><div>~Paul<br></d= iv><div><br></div><div>[1] - test.so is the shared object that I created fo= r testing.<br></div><div>-- <br><div dir=3D"ltr">__________________<br><br>= :(){ :|:& };:</div></div></div> </blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g= mail_signature">__________________<br><br>:(){ :|:& };:</div> --000000000000c48ae305b80e6741--
![]() |
0 |
![]() |