From: David P. <dpi...@me...> - 2007-09-24 18:39:46
|
> I'm tinkering with a patch to Swig_wrapped_member_var_type(). Basically, > the patch is that if we're using C++, and the member variable is due to > %extend, and is a %naturalvar, use a value type instead of a const > reference type. Hmm, I notice there is no problem when SWIG is wrapping a function that returns a string. Do you happen to know why that is? I'm not sure your proposal would be acceptable in all cases. Consider cases like this (basically, the following is what %attribute_ref is for): %ignore Foo::X() %extend Foo { string x; } #define Foo_x_get(obj) obj->X() #define Foo_x_set(obj, value) obj->X() =3D value class Foo {=20 string _x; public: int& X() { return _x; } } Although "x" is added by %extend, it actually does refer to a variable inside the class (_x). =20 > It may be more interesting to have a variation on %naturalvar that > states a preference to use values instead of references. To generalize the solution, I suspect there should be a typemap to control $1_ltype (as explained in the manual section 26.7.3: "All arguments and local variables in wrapper functions are declared using this type so that their values can be properly assigned.") |