mirror of https://github.com/swig/swig
Fix std::map and smart pointers.
Fixes problem with method overloading when some methods are added by %extend and others are real methods and using template default parameters with smart pointers. This is noticeable as a regression since 2.0.12 when using the default smart pointer handling for some languages when the smart pointer wraps std::map and other STL containers. Fixes SF Bug 1363
This commit is contained in:
parent
c99417ab13
commit
dbf44fc181
|
@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release.
|
|||
Version 3.0.0 (in progress)
|
||||
============================
|
||||
|
||||
2014-03-06: wsfulton
|
||||
Fix SF Bug #1363 - Problem with method overloading when some methods are added by %extend
|
||||
and others are real methods and using template default parameters with smart pointers.
|
||||
This is noticeable as a regression since 2.0.12 when using the default smart pointer
|
||||
handling for some languages when the smart pointer wraps std::map and other STL containers.
|
||||
|
||||
2014-03-02: wsfulton
|
||||
[Python] SF Patch #346 from Jens Krueger. Correct exception thrown attempting to
|
||||
access a non-existent C/C++ global variable on the 'cvar' object. The exception thrown
|
||||
|
|
|
@ -347,6 +347,7 @@ CPP_TEST_CASES += \
|
|||
smart_pointer_simple \
|
||||
smart_pointer_static \
|
||||
smart_pointer_template_const_overload \
|
||||
smart_pointer_template_defaults_overload \
|
||||
smart_pointer_templatemethods \
|
||||
smart_pointer_templatevariables \
|
||||
smart_pointer_typedef \
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
%module smart_pointer_template_defaults_overload
|
||||
|
||||
// SF Bug #1363
|
||||
// Problem with method overloading when some methods are added by %extend and others are real methods
|
||||
// and using template default parameters with smart pointers.
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Wrap::operator->;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Container::rubout;
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_map.i>
|
||||
|
||||
%inline %{
|
||||
template <typename T>
|
||||
class Wrap {
|
||||
T *ptr;
|
||||
public:
|
||||
Wrap(T *p) : ptr(p) {}
|
||||
T const* operator->(void) const { return ptr; }
|
||||
T* operator->(void) { return ptr; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template(StringDoubleMap) std::map<std::string, double>; // erase is generated okay
|
||||
%template(WrappedMap) Wrap< std::map<std::string, double> >; // erase wrappers lead to compile error
|
||||
|
||||
// Above only affects some languages depending on how std::map is implemented.
|
||||
// Below is a cutdown language independent demonstration of the bug
|
||||
|
||||
%extend Container {
|
||||
void rubout(int, int) {}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
template<typename T, typename X = T> class Container {
|
||||
public:
|
||||
int rubout() { return 0; }
|
||||
void rubout(T const &element) {}
|
||||
static Container* factory() { return new Container(); }
|
||||
static Container* factory(bool b) { return new Container(); }
|
||||
static void staticstuff(bool) {}
|
||||
#ifdef SWIG
|
||||
%extend {
|
||||
void rubout(bool) {}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
%}
|
||||
|
||||
%extend Container {
|
||||
void rubout(int) {}
|
||||
}
|
||||
|
||||
%template(ContainerInt) Container<double>;
|
||||
%template(WrapContainerInt) Wrap< Container<double> >;
|
||||
|
|
@ -421,7 +421,7 @@ class Allocate:public Dispatcher {
|
|||
while (cc) {
|
||||
Node *cp = cc;
|
||||
if (classname) {
|
||||
Setattr(cp, "classname", classname);
|
||||
Setattr(cp, "extendsmartclassname", classname);
|
||||
}
|
||||
Setattr(cp, "allocate:smartpointeraccess", "1");
|
||||
/* If constant, we have to be careful */
|
||||
|
@ -827,7 +827,7 @@ Allocate():
|
|||
}
|
||||
List *methods = smart_pointer_methods(sc, 0, isconst);
|
||||
Setattr(inclass, "allocate:smartpointer", methods);
|
||||
Setattr(inclass, "allocate:smartpointerbase", base);
|
||||
Setattr(inclass, "allocate:smartpointerpointeeclassname", Getattr(sc, "name"));
|
||||
} else {
|
||||
/* Hmmm. The return value is not a pointer. If the type is a value
|
||||
or reference. We're going to chase it to see if another operator->()
|
||||
|
|
|
@ -1242,8 +1242,8 @@ int Language::memberfunctionHandler(Node *n) {
|
|||
|
||||
String *fname = Swig_name_member(NSpace, ClassPrefix, symname);
|
||||
if (Extend && SmartPointer) {
|
||||
if (!Getattr(n, "classname")) {
|
||||
Setattr(n, "classname", Getattr(CurrentClass, "allocate:smartpointerbase"));
|
||||
if (!Getattr(n, "extendsmartclassname")) {
|
||||
Setattr(n, "extendsmartclassname", Getattr(CurrentClass, "allocate:smartpointerpointeeclassname"));
|
||||
}
|
||||
}
|
||||
// Set up the type for the cast to this class for use when wrapping const director (virtual) methods.
|
||||
|
@ -1562,7 +1562,7 @@ int Language::membervariableHandler(Node *n) {
|
|||
int Language::staticmembervariableHandler(Node *n) {
|
||||
Swig_require("staticmembervariableHandler", n, "*name", "*sym:name", "*type", "?value", NIL);
|
||||
String *value = Getattr(n, "value");
|
||||
String *classname = !SmartPointer ? (isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerbase");
|
||||
String *classname = !SmartPointer ? (isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerpointeeclassname");
|
||||
|
||||
if (!value || !Getattr(n, "hasconsttype")) {
|
||||
String *name = Getattr(n, "name");
|
||||
|
|
|
@ -941,7 +941,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
|
|||
is_smart_pointer_overload = 1;
|
||||
}
|
||||
else if (Swig_storage_isstatic(n)) {
|
||||
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
|
||||
String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname;
|
||||
String *ctname = SwigType_namestr(cname);
|
||||
self = NewStringf("(*(%s const *)this)->", ctname);
|
||||
is_smart_pointer_overload = 1;
|
||||
|
@ -1058,7 +1058,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
|
|||
|
||||
String *defaultargs = Getattr(n, "defaultargs");
|
||||
String *code = Getattr(n, "code");
|
||||
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
|
||||
String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname;
|
||||
String *membername = Swig_name_member(nspace, cname, name);
|
||||
String *mangled = Swig_name_mangle(membername);
|
||||
int is_smart_pointer = flags & CWRAP_SMART_POINTER;
|
||||
|
|
Loading…
Reference in New Issue