diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index 61ffedd31..2e7931332 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -33,6 +33,7 @@ namespace class scoped_dohptr { public: + scoped_dohptr() : obj_(NULL) {} explicit scoped_dohptr(DOH* obj) : obj_(obj) {} ~scoped_dohptr() { Delete(obj_); } @@ -49,6 +50,16 @@ public: return *this; } + // Assignment operator takes ownership of the pointer, just as the ctor does. + scoped_dohptr& operator=(DOH* obj) { + if (obj != obj_) { + Delete(obj_); + obj_ = obj; + } + + return *this; + } + DOH* get() const { return obj_; } DOH* release() const /* not really */ { @@ -196,13 +207,12 @@ public: String *getGlobalWrapperName(Node *n, String *name) const { // Use namespace as the prefix if feature:nspace is in use. - scoped_dohptr scopename_prefix(Swig_scopename_prefix(Getattr(n, "name"))); - if (scopename_prefix) { - if (GetFlag(parentNode(n), "feature:nspace")) { + scoped_dohptr scopename_prefix; + if (GetFlag(parentNode(n), "feature:nspace")) { + scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); + if (scopename_prefix) { scoped_dohptr mangled_prefix(Swig_string_mangle(scopename_prefix)); scopename_prefix = mangled_prefix; - } else { - scopename_prefix.reset(); } }