Add support for const references to pointers

They're used in some unit tests and we can support them by handling them
just as pointers in C++ wrappers (this was already the case for C
wrappers).
This commit is contained in:
Vadim Zeitlin 2021-12-08 03:26:44 +01:00
commit 1fd4c647b8
3 changed files with 11 additions and 4 deletions

View file

@ -107,14 +107,11 @@ cpp11_default_delete.cpptest: SWIG_NOCXX = -nocxx # Assignment operator and r-va
cpp11_explicit_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
cpp11_noexcept.cpptest: SWIG_NOCXX = -nocxx # Assignment operator.
default_constructor.cpptest: SWIG_NOCXX = -nocxx # Something weird with OSRSpatialReferenceShadow.
director_classes.cpptest: SWIG_NOCXX = -nocxx # Ref to pointer
director_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
director_frob.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
extend_template_method.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
features.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type not handled specially.
global_namespace.cpptest: SWIG_NOCXX = -nocxx # Const const reference type.
li_boost_shared_ptr_director.cpptest: SWIG_NOCXX = -nocxx # Ref to pointer
li_std_vector_ptr.cpptest: SWIG_NOCXX = -nocxx # Ref to pointer
member_template.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
multiple_inheritance_abstract.cpptest: SWIG_NOCXX = -nocxx # Multiple inheritance not supported.
multiple_inheritance_interfaces.cpptest: SWIG_NOCXX = -nocxx

View file

@ -119,6 +119,7 @@ same_macro_all_primitive_types_but_void(cref_as_value,ctype);
// objects
%typemap(ctype) SWIGTYPE "$&resolved_type*"
%typemap(ctype) SWIGTYPE * "$resolved_type*"
%typemap(ctype) SWIGTYPE * const & "$resolved_type*"
%typemap(ctype) SWIGTYPE & "$*resolved_type*"
%typemap(ctype) SWIGTYPE [ANY] "$resolved_type*"
%typemap(ctype) SWIGTYPE * [ANY] "$resolved_type**"

View file

@ -719,7 +719,16 @@ private:
} else {
String* classname;
if (Node* const class_node = Language::instance()->classLookup(type)) {
typestr = SwigType_str(resolved_type, 0);
// 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);
}
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