From 049d3c309bfb0c04946c3c8fcf033df8e2fec8ef Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 17 Sep 2022 15:30:31 +0200 Subject: [PATCH] Fix handling of const object parameters and return types Simply ignore the const on them, to avoid ending up with an extra and invalid "const" in the generated code. This fixes director_pass_by_value and typemap_out_optimal unit tests after the latest merge. --- Source/Modules/c.cxx | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index 90df1852d..f8aed2a02 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -702,16 +702,34 @@ private: } else { String* classname; if (Node* const class_node = Language::instance()->classLookup(type)) { - // Special case: if this is a pointer passed by (const) reference, we return just the pointer directly because we don't have any pointer-valued variable - // to give out a reference to. - if (typeKind == Type_Ptr && strncmp(Char(resolved_type), "r.q(const).", 11) == 0) { - scoped_dohptr deref_type(Copy(resolved_type)); - Delslice(deref_type, 0, 11); - typestr = SwigType_str(deref_type, 0); - } else { - typestr = SwigType_str(resolved_type, 0); + // Deal with some special cases: + switch (typeKind) { + case Type_Ptr: + // If this is a pointer passed by const reference, we return just the pointer directly because we don't have any pointer-valued variable to give out + // a reference to. + if (strncmp(Char(resolved_type), "r.q(const).", 11) == 0) { + scoped_dohptr deref_type(Copy(resolved_type)); + Delslice(deref_type, 0, 11); + typestr = SwigType_str(deref_type, 0); + } + break; + + case Type_Obj: + // Const objects are just objects for our purposes here, remove the const from them to avoid having "const const" in the output. + if (SwigType_isconst(resolved_type)) + SwigType_del_qualifier(resolved_type); + break; + + case Type_Ref: + case Type_Enm: + case Type_Max: + // Nothing special to do. + break; } + if (!typestr) + typestr = SwigType_str(resolved_type, 0); + classname = Getattr(class_node, "sym:name"); // We don't use namespaces, but the type may contain them, so get rid of them by replacing the base type name, which is fully qualified, with just the