[Python] Fix wrapping of bool const&x=true param

Fix wrapping of a bool const& parameter with a default value.
Regression introduced in SWIG 4.3.0.

Fixes #3162
This commit is contained in:
Olly Betts 2025-06-09 11:31:19 +12:00
parent b5deab76bc
commit f0fb79152e
6 changed files with 33 additions and 2 deletions

View File

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.4.0 (in progress)
===========================
2025-06-09: olly
[Python] #3162 Fix wrapping of a bool const& parameter with a
default value. Regression introduced in SWIG 4.3.0.
2025-06-09: olly
[Tcl] #2887 Fix -external-runtime to generate a header which works
with Tcl 8.x. Regression introduced in SWIG 4.2.1. As a bonus

View File

@ -14,6 +14,7 @@ struct Display {
float draw1(float v = NULL_FOR_FLOAT) { return v; }
float draw2(float *v = NULL_FOR_FLOAT) { return v ? *v : 0; }
int draw3(int index = 0, const bool interpolate = true) { return interpolate ? index : -index; }
int draw4(bool const& interpolate = true) { return interpolate ? 1 : -1; }
bool bool0(bool x = 0) { return x; }
bool bool1(bool x = 1) { return x; }

View File

@ -18,6 +18,12 @@ if d.draw2(p) != 123:
if d.draw3() != 0:
raise RuntimeError
if d.draw4() != 1:
raise RuntimeError
if d.draw4(False) != -1:
raise RuntimeError
if d.bool0() != False or type(d.bool0()) != type(False):
raise RuntimeError

View File

@ -17,6 +17,10 @@ raise RuntimeError if d.draw2(p) != 123
raise RuntimeError if d.draw3() != 0
raise RuntimeError if d.draw4() != 1
raise RuntimeError if d.draw4(false) != -1
raise RuntimeError unless d.bool0() === false
raise RuntimeError unless d.bool1() === true

View File

@ -2150,7 +2150,15 @@ public:
// return NewStringf("'%(escape)s'", stringval);
}
SwigType *resolved_type = SwigType_typedef_resolve_all(type);
SwigType *unqualified_type = SwigType_strip_qualifiers(resolved_type);
SwigType *unqualified_type = NIL;
if (SwigType_isreference(resolved_type)) {
SwigType *t = Copy(resolved_type);
t = SwigType_del_reference(t);
unqualified_type = SwigType_strip_qualifiers(t);
Delete(t);
} else {
unqualified_type = SwigType_strip_qualifiers(resolved_type);
}
if (numval) {
if (Equal(unqualified_type, "bool")) {
Delete(resolved_type);

View File

@ -777,7 +777,15 @@ private:
}
if (numval) {
SwigType *resolved_type = SwigType_typedef_resolve_all(type);
SwigType *unqualified_type = SwigType_strip_qualifiers(resolved_type);
SwigType *unqualified_type = NIL;
if (SwigType_isreference(resolved_type)) {
SwigType *t = Copy(resolved_type);
t = SwigType_del_reference(t);
unqualified_type = SwigType_strip_qualifiers(t);
Delete(t);
} else {
unqualified_type = SwigType_strip_qualifiers(resolved_type);
}
if (Equal(unqualified_type, "bool")) {
Delete(resolved_type);
Delete(unqualified_type);