Ignoring default arguments in wrapper generation

Arnaud Diederen via Swig-user <[email protected]> Wed, 19 Feb 2025 09:49:05 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <CABSUo4NQME9rPLYLb24Vx82Q5j6MAHUdL6tumQSRy6tyG6u91A@mail.gmail.com>
--===============4765334399058229819==
Content-Type: multipart/alternative; boundary="00000000000018ab09062e7ad5cc"

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

Hi,

we have a relatively complex system that builds Python bindings on top of a
SDK, and SWiG plays an important role early in the chain.

An issue that has arisen, is the fact that from the following declaration:
```
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 manner?

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.



--=20

Arnaud Diederen

Head of Engineering

[email protected] <[email protected]>

+32 472 940 315

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

<div dir=3D"ltr"><div><div>Hi,</div><div><br></div><div>we have a relativel=
y 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 class=3D"gmail-yj6qo"></div><div class=3D"gmail-adL"><br><b=
r></div></div><br><span class=3D"gmail_signature_prefix">-- </span><br><div=
 dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><=
div dir=3D"ltr"><span><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:11pt;font-family:Arial,sans-=
serif;color:rgb(0,0,0);background-color:transparent;font-weight:700;vertica=
l-align:baseline">Arnaud Diederen</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;f=
ont-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;v=
ertical-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:none=
;display:inline-block;overflow:hidden;width:184px;height:49px"><img src=3D"=
https://lh7-qw.googleusercontent.com/docsz/AD_4nXfzrRvtusEVQJYD8PML22x2ERSV=
2ItmaIzerZffxCjn4QggrPJhJ5b66qTEghBg621as8N536556Ajm_R3z-fyZ0MLJ0JEmp9g7wks=
w1zhrzsUBleawmAvTC4FULARENXG1pq0v2uVaNDcNlFceRAAa2Q?key=3DjodrV0E24pQyx0W12=
4GeOQ" 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,san=
s-serif;color:rgb(0,0,0);background-color:transparent;vertical-align:baseli=
ne"><span style=3D"border:none;display:inline-block;overflow:hidden;width:1=
84px;height:49px"><br></span></span></div></span></div></div></div>

--00000000000018ab09062e7ad5cc--


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


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

--===============4765334399058229819==--