Fwd: Re: how to map 'new' to 'CUSTOM_NEW_T'
Ephraim Yawitz <[email protected]> Sun, 22 Dec 2024 11:22:46 +0200
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CAP-4f0J-V=6qDz-=PydQx+Y4BpPQq3sdhr+qrfCsxbZBEY=sEg@mail.gmail.com> |
--===============4044418284111100758== Content-Type: multipart/alternative; boundary="000000000000effce40629d86c54" --000000000000effce40629d86c54 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ---------- Forwarded message --------- From: Ephraim Yawitz <[email protected]> Date: Sun, Dec 22, 2024 at 11:22=E2=80=AFAM Subject: Re: Re: [Swig-user] how to map 'new' to 'CUSTOM_NEW_T' To: Jim <[email protected]> I'm very surprised that this can't be done with typemaps. Did anyone else on the list confirm this? On Fri, Dec 20, 2024 at 12:05=E2=80=AFPM Jim <[email protected]> wrote: > Yeah, I have read all the code of the 'csharp.swg' and other files, and > looks like can't implent with typemap. So I clone the git repository and > found the below code may affect the 'new' operator: > > String* null_attribute =3D 0; > > // Now write code to make the function call > > if (!native_function_flag) { > > > Swig_director_emit_dynamic_cast(n, f); > > String* actioncode =3D emit_action(n); > > > /* Return value if necessary */ > > if ((tm =3D Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, > actioncode))) { > > canThrow(n, "out", n); > > Replaceall(tm, "$result", "jresult"); > > > if (GetFlag(n, "feature:new")) > > Replaceall(tm, "$owner", "1"); > > else > > Replaceall(tm, "$owner", "0"); > > the 'emit_action' returned string is "result =3D (Bar *)new Bar();". So= I > digged the emit_action but have no idea about how to modify it. > > > > > > At 2024-12-20 00:05:38, "Ephraim Yawitz" <[email protected]> wrote: > > I see no one has followed this up, but in the meantime I have tried a > little example of what I suggested and it didn't work, i.e., it still use= d > "new" instead of "CUSTOM_NEW_T", so I guess the issue is more complicated > than I thought, although it might just need a small tweak in the typemap. > > On Tue, Dec 17, 2024 at 11:58=E2=80=AFAM Ephraim Yawitz <ephraim@excalibu= r.co.il> > wrote: > >> I'm no SWIG expert, but from the little bit I understand, the code for >> this C++ constructor is created based on the following lines in >> Lib/csharp/csharp.swg in the SWIG installation directory: >> >> %typemap(out) SWIGTYPE >> #ifdef __cplusplus >> %{ $result =3D new $1_ltype($1); %} >> #else >> { >> $&1_ltype $1ptr =3D ($&1_ltype) malloc(sizeof($1_ltype)); >> memmove($1ptr, &$1, sizeof($1_type)); >> $result =3D $1ptr; >> } >> #endif >> >> I'm guessing that perhaps creating a %typemap of your own with >> "CUSTOM_NEW_T" instead of "new" might do the trick. >> Again, I'm just posting this to try to get the attention of the guys who >> really know what they're doing. >> >> On Mon, Dec 16, 2024 at 4:53=E2=80=AFAM Jim <[email protected]> wrote= : >> >>> Hi all, >>> I am using swig to generate csharp code, here is the default >>> implementation of the constructor: >>> I want change the 'new' operator to my custom 'CUSTOM_NEW_T'=EF=BC=8Cl= ike >>> 'result=3DCUSTOM_NEW_T(Bar)'. I have read the doc for SWIG, but it se= ems >>> that does not contain any relevant content. >>> >>> Thank you so much, have a nice day! >>> _______________________________________________ >>> Swig-user mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/swig-user >>> >> --000000000000effce40629d86c54 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><br><br><div class=3D"gmail_quote gmail_quote_container"><= div dir=3D"ltr" class=3D"gmail_attr">---------- Forwarded message ---------= <br>From: <b class=3D"gmail_sendername" dir=3D"auto">Ephraim Yawitz</b> <sp= an dir=3D"auto"><<a href=3D"mailto:[email protected]">ephraim@exca= libur.co.il</a>></span><br>Date: Sun, Dec 22, 2024 at 11:22=E2=80=AFAM<b= r>Subject: Re: Re: [Swig-user] how to map 'new' to 'CUSTOM_NEW_= T'<br>To: Jim <<a href=3D"mailto:[email protected]">guyiming2011@= 126.com</a>><br></div><br><br><div dir=3D"ltr">I'm very surprised th= at this can't be done with typemaps. Did anyone else on the list confir= m this?<br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"g= mail_attr">On Fri, Dec 20, 2024 at 12:05=E2=80=AFPM Jim <<a href=3D"mail= to:[email protected]" target=3D"_blank">[email protected]</a>> wro= te:<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 style= =3D"line-height:1.7;color:rgb(0,0,0);font-size:14px;font-family:Arial"><div= id=3D"m_-6177578573782233742m_-7802994937922086891spnEditorContent"><p sty= le=3D"margin:0px">Yeah, I have read all the code of the 'csharp.swg'= ; and other files, and looks like can't implent with typemap. So I clon= e the git repository and found the below code may affect the 'new' = operator:</p><p style=3D"margin:0px"><span style=3D"color:rgb(141,148,64)">= String* null_attribute =3D 0;</span></p><p style=3D"margin:0px"><span style= =3D"color:rgb(141,148,64)">// Now write code to make the function call</spa= n></p><p style=3D"margin:0px"><span style=3D"color:rgb(141,148,64)">if (!na= tive_function_flag) {</span></p><p style=3D"margin:0px"><br></p><p style=3D= "margin:0px"><span style=3D"white-space:normal;color:rgb(141,148,64)"><span= style=3D"color:rgb(141,148,64);white-space:pre-wrap"> </span>Swig_director= _emit_dynamic_cast(n, f);</span></p><p style=3D"margin:0px"><span style=3D"= white-space:normal;color:rgb(141,148,64)"><span style=3D"color:rgb(141,148,= 64);white-space:pre-wrap"> </span>String* actioncode =3D emit_action(n);</s= pan></p><p style=3D"margin:0px"><br></p><p style=3D"margin:0px"><span style= =3D"white-space:normal;color:rgb(141,148,64)"><span style=3D"color:rgb(141,= 148,64);white-space:pre-wrap"> </span>/* Return value if necessary=C2=A0 */= </span></p><p style=3D"margin:0px"><span style=3D"white-space:normal;color:= rgb(141,148,64)"><span style=3D"color:rgb(141,148,64);white-space:pre-wrap"= > </span>if ((tm =3D Swig_typemap_lookup_out("out", n, Swig_cresu= lt_name(), f, actioncode))) {</span></p><p style=3D"margin:0px"><span style= =3D"white-space:normal;color:rgb(141,148,64)"><span style=3D"color:rgb(141,= 148,64);white-space:pre-wrap"> </span>canThrow(n, "out", n);</sp= an></p><p style=3D"margin:0px"><span style=3D"white-space:normal;color:rgb(= 141,148,64)"><span style=3D"color:rgb(141,148,64);white-space:pre-wrap"> <= /span>Replaceall(tm, "$result", "jresult");</span></p><= p style=3D"margin:0px"><br></p><p style=3D"margin:0px"><span style=3D"white= -space:normal;color:rgb(141,148,64)"><span style=3D"color:rgb(141,148,64);w= hite-space:pre-wrap"> </span>if (GetFlag(n, "feature:new"))</spa= n></p><p style=3D"margin:0px"><span style=3D"white-space:normal;color:rgb(1= 41,148,64)"><span style=3D"color:rgb(141,148,64);white-space:pre-wrap"> <= /span>Replaceall(tm, "$owner", "1");</span></p><p style= =3D"margin:0px"><span style=3D"white-space:normal;color:rgb(141,148,64)"><s= pan style=3D"color:rgb(141,148,64);white-space:pre-wrap"> </span>else</spa= n></p><p style=3D"margin:0px"><span style=3D"white-space:normal;color:rgb(1= 41,148,64)"><span style=3D"color:rgb(141,148,64);white-space:pre-wrap"> <= /span>Replaceall(tm, "$owner", "0");</span></p><p style= =3D"margin:0px">the 'emit_action' returned=C2=A0 string is "re= sult =3D (Bar *)new Bar();".=C2=A0 So I digged the emit_action but hav= e no idea about how to modify it.</p><p style=3D"margin:0px"><br></p><p sty= le=3D"margin:0px"><br></p><p style=3D"margin:0px"><br></p></div><div></div>= <div id=3D"m_-6177578573782233742m_-7802994937922086891divNeteaseMailCard">= </div><p style=3D"margin:0px"><br></p><p>At 2024-12-20 00:05:38, "Ephr= aim Yawitz" <<a href=3D"mailto:[email protected]" target=3D"_= blank">[email protected]</a>> wrote:</p><blockquote id=3D"m_-61775= 78573782233742m_-7802994937922086891isReplyContent" style=3D"padding-left:1= ex;margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)"><div di= r=3D"ltr">I see no one has followed this up, but in the meantime I have tri= ed a little example of what I suggested and it didn't work, i.e., it st= ill used "new" instead of "CUSTOM_NEW_T", so I guess th= e issue is more complicated than I thought, although it might just need a s= mall tweak in the typemap.<br></div><br><div class=3D"gmail_quote"><div dir= =3D"ltr" class=3D"gmail_attr">On Tue, Dec 17, 2024 at 11:58=E2=80=AFAM Ephr= aim Yawitz <<a href=3D"mailto:[email protected]" target=3D"_blank"= >[email protected]</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>I'm no SWIG expert, but f= rom the little bit I understand, the code for this C++ constructor is creat= ed based on the following lines in Lib/csharp/csharp.swg in the SWIG instal= lation directory:</div><div><br></div><div>%typemap(out) SWIGTYPE <br>#ifde= f __cplusplus<br>%{ $result =3D new $1_ltype($1); %}<br>#else<br>{<br>=C2= =A0 $&1_ltype $1ptr =3D ($&1_ltype) malloc(sizeof($1_ltype));<br>= =C2=A0 memmove($1ptr, &$1, sizeof($1_type));<br>=C2=A0 $result =3D $1pt= r;<br>}<br>#endif</div><div><br></div><div>I'm guessing that perhaps cr= eating a %typemap of your own with=20 "CUSTOM_NEW_T" instead of "new" might do the trick.</di= v><div>Again, I'm just posting this to try to get the attention of the = guys who really know what they're doing.<br></div><br><div class=3D"gma= il_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Dec 16, 2024 at 4:5= 3=E2=80=AFAM Jim <<a href=3D"mailto:[email protected]" target=3D"_bla= nk">[email protected]</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 style=3D"line-height:1.7;color:rgb(0,0,0);font= -size:14px;font-family:Arial"><div style=3D"margin:0px">Hi all,</div><div s= tyle=3D"margin:0px">=C2=A0 =C2=A0 I am using swig to generate csharp code, = here is the default implementation of the constructor:</div><div style=3D"m= argin:0px"><img style=3D"width:636px;height:182px"></div><div style=3D"marg= in:0px">=C2=A0I want change the 'new' operator to my custom 'CU= STOM_NEW_T'=EF=BC=8Clike 'result=3DCUSTOM_NEW_T(Bar)'.=C2=A0 = =C2=A0I have read the doc for SWIG, but it seems that does not contain any = relevant content.</div><div style=3D"margin:0px"><br></div><div style=3D"ma= rgin:0px">=C2=A0Thank you so much, have a nice day!</div></div><img style= =3D"width:1px;height:1px" src=3D"https://count.mail.163.com/beacon/webmail.= gif?type=3Dwebmail_mailtrace&guid=3Dpre_1c51cbb92865f663cb929be752099ce= a">_______________________________________________<br> Swig-user mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Swig-u= [email protected]</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/swig-user" rel=3D"n= oreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/s= wig-user</a><br> </blockquote></div></div> </blockquote></div> </blockquote></div><img style=3D"width:1px;height:1px" src=3D"https://count= .mail.163.com/beacon/webmail.gif?type=3Dwebmail_mailtrace&guid=3Dpre_26= 39352238bc87af42444a6b0c112d90"></blockquote></div> </div></div> --000000000000effce40629d86c54-- --===============4044418284111100758== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============4044418284111100758== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user --===============4044418284111100758==--