Re: Ignoring default arguments in wrapper generation

Arnaud Diederen via Swig-user <[email protected]> Wed, 19 Feb 2025 11:10:57 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <CABSUo4M50hB6PFauLxAa1knPq5Y5-Y5cCYV04rNW-DYedO_+EQ@mail.gmail.com>
--===============6457481749133894379==
Content-Type: multipart/alternative; boundary="000000000000e81e42062e7bf9d9"

--000000000000e81e42062e7bf9d9
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

....aaaaaaand,

On Wed, Feb 19, 2025 at 10:42=E2=80=AFAM Arnaud Diederen <[email protected]=
om>
wrote:

> [...]the problem arises because of
> `SOME_DEFINE_COMING_FROM_ANOTHER_HEADER`.
>

Wrong again.

The problem is that the define has syntax that SWiG dislikes:

`#define SOME_DEFINE_COMING_FROM_ANOTHER_HEADER thread_id_t(-1)`

However, that is pretty good news, as I have full control over this.
Looks like I can proceed with my rube-goldbergery!
Best regards,
   A.


>
> That other header, will be converted to another Python module, so I canno=
t
> just `%include` it (it'll duplicate functionality in both the current, an=
d
> that other module.)
> I tried `%import`'ing it, but no luck.
>
> If you happen to have suggestions, I'm all ears!
>
> Best regards,
>     A.
>
>
>
> On Wed, Feb 19, 2025 at 9:49=E2=80=AFAM Arnaud Diederen <arnaud@hex-rays.=
com>
> wrote:
>
>> Hi,
>>
>> we have a relatively complex system that builds Python bindings on top o=
f
>> a SDK, and SWiG plays an important role early in the chain.
>>
>> An issue that has arisen, is the fact that from the following declaratio=
n:
>> ```
>> int something(int foo, int bar=3D10);
>> ```
>>
>> SWiG will generate a Python function with the following signature:
>> ```
>> def something(*args):
>>      return _module.something(*args)
>> ```
>> =E2=80=A6and leave it up to `_module` to perform the dispatch between
>> `_wrap_something__SWIG_0` and `_wrap_something__SWIG_1` (or
>> `_wrap_something` if `compactdefaultargs` is used.)
>>
>> However, this is not really playing nice with the rest of our bindings
>> "build system", because of the presence of `*args`.
>>
>> Something that would work much better for me, is if I could tell SWiG
>> (ideally w/o `%ignore`'ing that function and then re-defining it myself)=
,
>> to simply "drop" the default value.
>> In other words, I'd love it if I could tell SWiG to consider that
>> declaration as if  it were:
>>
>> ```
>> int something(int foo, int bar);
>> ```
>> =E2=80=A6and our bindings build system would take it up from here.
>>
>> I realize this is perhaps not the canonical use-case for SWiG, but is
>> there any chance I can achieve that, in a hopefully rather elegant manne=
r?
>>
>> Note: `compactdefaultargs` does not work in this case, because while the
>> default args values are assigned in the generated CPP wrapper code
>> (great!), the Python wrapper itself still has only `*args` (ouch.)
>>
>> Any pointer welcome!
>>
>> Best regards,
>>        A.
>>
>>
>>
>> --
>>
>> Arnaud Diederen
>>
>> Head of Engineering
>>
>> [email protected] <[email protected]>
>>
>> +32 472 940 315
>>
>>
>>
>
> --
>
> Arnaud Diederen
>
> Head of Engineering
>
> [email protected] <[email protected]>
>
> +32 472 940 315
>
>
>

--=20

Arnaud Diederen

Head of Engineering

[email protected] <[email protected]>

+32 472 940 315

--000000000000e81e42062e7bf9d9
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><div>....aaaaaaand,<br></div><b=
r><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=
=3D"gmail_attr">On Wed, Feb 19, 2025 at 10:42=E2=80=AFAM Arnaud Diederen &l=
t;<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8=
ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr=
"><div><div>[...]the problem arises because of `SOME_DEFINE_COMING_FROM_ANO=
THER_HEADER`.</div></div></div></blockquote><div><br></div><div>Wrong again=
.<br><br></div><div>The problem is that the define has syntax that SWiG dis=
likes:</div><div><br></div><div>`#define SOME_DEFINE_COMING_FROM_ANOTHER_HE=
ADER thread_id_t(-1)`</div><div><br></div><div>However, that is pretty good=
 news, as I have full control over this.</div><div>Looks like I can proceed=
 with my rube-goldbergery!<br></div><div></div><div>Best regards,</div><div=
>=C2=A0=C2=A0 A.<br></div><div>=C2=A0</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><div><br></div><div>That other head=
er, will be converted to another Python module, so I cannot just `%include`=
 it (it&#39;ll duplicate functionality in both the current, and that other =
module.)</div><div>I tried `%import`&#39;ing it, but no luck.</div><div><br=
></div><div>If you happen to have suggestions, I&#39;m all ears!</div><div>=
<br></div><div>Best regards,</div><div>=C2=A0=C2=A0=C2=A0 A.<br></div><div>=
<br></div><div><br></div></div></div><br><div class=3D"gmail_quote"><div di=
r=3D"ltr" class=3D"gmail_attr">On Wed, Feb 19, 2025 at 9:49=E2=80=AFAM Arna=
ud Diederen &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">ar=
[email protected]</a>&gt; wrote:<br></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"><div dir=3D"ltr"><div><div>Hi,</div><div><br></div><div>we=
 have a relatively complex system=20
that builds Python bindings on top of a SDK, and SWiG plays an important
 role early in the chain.</div><div><br></div><div>An issue that has arisen=
, is the fact that from the following declaration:<br>```</div><div>int som=
ething(int foo, int bar=3D10);</div><div>```</div><div><br></div><div>SWiG =
will generate a Python function with the following signature:</div><div>```=
</div><div>def something(*args):</div><div>=C2=A0 =C2=A0 =C2=A0return _modu=
le.something(*args)</div><div>```</div><div>=E2=80=A6and
 leave it up to `_module` to perform the dispatch between=20
`_wrap_something__SWIG_0` and `_wrap_something__SWIG_1` (or=20
`_wrap_something` if `compactdefaultargs` is used.)</div><div><br></div><di=
v>However, this is not really playing nice with the rest of our bindings &q=
uot;build system&quot;, because of the presence of `*args`.</div><div><br><=
/div><div>Something
 that would work much better for me, is if I could tell SWiG (ideally=20
w/o `%ignore`&#39;ing that function and then re-defining it myself), to=20
simply &quot;drop&quot; the default value.</div><div>In other words, I&#39;=
d love it if I could tell SWiG to consider that declaration as if=C2=A0 it =
were:</div><div><br></div><div>```</div><div>int something(int foo, int bar=
);</div><div>```</div><div>=E2=80=A6and our bindings build system would tak=
e it up from here.</div><div><br></div><div>I
 realize this is perhaps not the canonical use-case for SWiG, but is=20
there any chance I can achieve that, in a hopefully rather elegant=20
manner?</div><div><br></div><div>Note: `compactdefaultargs` does not=20
work in this case, because while the default args values are assigned in
 the generated CPP wrapper code (great!), the Python wrapper itself=20
still has only `*args` (ouch.)</div><div><br></div><div>Any pointer welcome=
!</div><div><br></div><div>Best regards,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0A.</div><div></div><div><br><br></div></div><br><span class=3D"gmail_sig=
nature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_signature"><di=
v dir=3D"ltr"><span><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:11pt;font-family:Arial,sans-se=
rif;color:rgb(0,0,0);background-color:transparent;font-weight:700;vertical-=
align:baseline">Arnaud Diederen</span></p><p dir=3D"ltr" style=3D"line-heig=
ht:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;fon=
t-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;ver=
tical-align:baseline">Head of Engineering</span></p><p dir=3D"ltr" style=3D=
"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href=3D"mailto:steph=
[email protected]" target=3D"_blank"><span style=3D"font-size:11pt;font-fami=
ly:Arial,sans-serif;color:rgb(17,85,204);background-color:transparent;verti=
cal-align:baseline">[email protected]</span></a></p><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:tr=
ansparent;vertical-align:baseline">+32 472 940 315</span></p><br><p dir=3D"=
ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span styl=
e=3D"font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);backgroun=
d-color:transparent;vertical-align:baseline"><span style=3D"border:medium;d=
isplay:inline-block;overflow:hidden;width:184px;height:49px"><img src=3D"ht=
tps://lh7-qw.googleusercontent.com/docsz/AD_4nXfzrRvtusEVQJYD8PML22x2ERSV2I=
tmaIzerZffxCjn4QggrPJhJ5b66qTEghBg621as8N536556Ajm_R3z-fyZ0MLJ0JEmp9g7wksw1=
zhrzsUBleawmAvTC4FULARENXG1pq0v2uVaNDcNlFceRAAa2Q?key=3DjodrV0E24pQyx0W124G=
eOQ" width=3D"184" height=3D"49" style=3D"margin-left: 0px; margin-top: 0px=
;"></span></span></p><div><span style=3D"font-size:11pt;font-family:Arial,s=
ans-serif;color:rgb(0,0,0);background-color:transparent;vertical-align:base=
line"><span style=3D"border:medium;display:inline-block;overflow:hidden;wid=
th:184px;height:49px"><br></span></span></div></span></div></div></div>
</blockquote></div><div><br clear=3D"all"></div><br><span class=3D"gmail_si=
gnature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_signature"><d=
iv dir=3D"ltr"><span><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0p=
t;margin-bottom:0pt"><span style=3D"font-size:11pt;font-family:Arial,sans-s=
erif;color:rgb(0,0,0);background-color:transparent;font-weight:700;vertical=
-align:baseline">Arnaud Diederen</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;fo=
nt-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;ve=
rtical-align:baseline">Head of Engineering</span></p><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href=3D"mailto:st=
[email protected]" target=3D"_blank"><span style=3D"font-size:11pt;font-f=
amily:Arial,sans-serif;color:rgb(17,85,204);background-color:transparent;ve=
rtical-align:baseline">[email protected]</span></a></p><p dir=3D"ltr" sty=
le=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:=
transparent;vertical-align:baseline">+32 472 940 315</span></p><br><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);backg=
round-color:transparent;vertical-align:baseline"><span style=3D"border:medi=
um;display:inline-block;overflow:hidden;width:184px;height:49px"><img src=
=3D"https://lh7-qw.googleusercontent.com/docsz/AD_4nXfzrRvtusEVQJYD8PML22x2=
ERSV2ItmaIzerZffxCjn4QggrPJhJ5b66qTEghBg621as8N536556Ajm_R3z-fyZ0MLJ0JEmp9g=
7wksw1zhrzsUBleawmAvTC4FULARENXG1pq0v2uVaNDcNlFceRAAa2Q?key=3DjodrV0E24pQyx=
0W124GeOQ" width=3D"184" height=3D"49" style=3D"margin-left: 0px; margin-to=
p: 0px;"></span></span></p><div><span style=3D"font-size:11pt;font-family:A=
rial,sans-serif;color:rgb(0,0,0);background-color:transparent;vertical-alig=
n:baseline"><span style=3D"border:medium;display:inline-block;overflow:hidd=
en;width:184px;height:49px"><br></span></span></div></span></div></div>
</blockquote></div><div><br clear=3D"all"></div><br><span class=3D"gmail_si=
gnature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_signature"><d=
iv dir=3D"ltr"><span><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0p=
t;margin-bottom:0pt"><span style=3D"font-size:11pt;font-family:Arial,sans-s=
erif;color:rgb(0,0,0);background-color:transparent;font-weight:700;vertical=
-align:baseline">Arnaud Diederen</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;fo=
nt-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;ve=
rtical-align:baseline">Head of Engineering</span></p><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href=3D"mailto:st=
[email protected]" target=3D"_blank"><span style=3D"font-size:11pt;font-f=
amily:Arial,sans-serif;color:rgb(17,85,204);background-color:transparent;ve=
rtical-align:baseline">[email protected]</span></a></p><p dir=3D"ltr" sty=
le=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:=
transparent;vertical-align:baseline">+32 472 940 315</span></p><br><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);backg=
round-color:transparent;vertical-align:baseline"><span style=3D"border:medi=
um;display:inline-block;overflow:hidden;width:184px;height:49px"><img src=
=3D"https://lh7-qw.googleusercontent.com/docsz/AD_4nXfzrRvtusEVQJYD8PML22x2=
ERSV2ItmaIzerZffxCjn4QggrPJhJ5b66qTEghBg621as8N536556Ajm_R3z-fyZ0MLJ0JEmp9g=
7wksw1zhrzsUBleawmAvTC4FULARENXG1pq0v2uVaNDcNlFceRAAa2Q?key=3DjodrV0E24pQyx=
0W124GeOQ" width=3D"184" height=3D"49" style=3D"margin-left: 0px; margin-to=
p: 0px;"></span></span></p><div><span style=3D"font-size:11pt;font-family:A=
rial,sans-serif;color:rgb(0,0,0);background-color:transparent;vertical-alig=
n:baseline"><span style=3D"border:medium;display:inline-block;overflow:hidd=
en;width:184px;height:49px"><br></span></span></div></span></div></div></di=
v>

--000000000000e81e42062e7bf9d9--


--===============6457481749133894379==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============6457481749133894379==
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

--===============6457481749133894379==--