Regression fix when using -keyword, kwargs or compactdefaultargs option

Restore generating a non-const cast to the default value when
wrapping const pointer default arguments.

Fixes #3075.
This commit is contained in:
William S Fulton 2025-02-05 08:09:44 +00:00
parent 892be2b802
commit e8787615a7
3 changed files with 26 additions and 0 deletions

View File

@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.4.0 (in progress)
===========================
2025-02-05: wsfulton
#3075 Regression fix when using -keyword, kwargs or compactdefaultargs
option. Restore generating a non-const cast to the default value when
wrapping const pointer default arguments.
2025-01-27: StefanBattmer
[Python] #2889 Fix regression when using directors and threads
but not using limited API.

View File

@ -15,6 +15,8 @@ public:
%{
const double Defaults1::PUBLIC_DEFAULT = -1.0;
const int abc = 1234;
int def = 1234;
%}
// compactdefaultargs now on by default
@ -35,6 +37,9 @@ public:
typedef const Defaults1& ConstDefaults1;
void references(const Defaults1& d10 = Defaults1(10), ConstDefaults1 d20 = Defaults1(20)) {}
};
void string_function(const char *str = "") {}
void ptr_function(const int *p1 = &abc, int *p2 = &def) {}
%}
%{

View File

@ -1011,6 +1011,8 @@ String *SwigType_lcaststr(const SwigType *s, const_String_or_char_ptr name) {
String *result;
result = NewStringEmpty();
if (name && Len(name) == 0)
name = 0;
if (SwigType_isarray(s)) {
String *lstr = SwigType_lstr(s, 0);
@ -1032,6 +1034,20 @@ String *SwigType_lcaststr(const SwigType *s, const_String_or_char_ptr name) {
String *lstr = SwigType_lstr(s, 0);
Printf(result, "(%s)%s", lstr, name);
Delete(lstr);
} else if (SwigType_ispointer(s)) {
SwigType *sc = Copy(s);
Delete(SwigType_pop(sc));
if (SwigType_isqualifier(sc) && name && !Equal(name, "0")) {
/* Only cast const pointer values (remove const in cast - they are assigned to a non-const pointer type) */
SwigType_add_pointer(sc);
String *lstr = SwigType_lstr(sc, 0);
Printf(result, "(%s)%s", lstr, name);
Delete(lstr);
} else {
if (name)
Append(result, name);
}
Delete(sc);
} else {
if (name)
Append(result, name);