From: Marcelo M. <mar...@us...> - 2005-10-31 09:58:32
|
Update of /cvsroot/swig/SWIG/Source/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1976 Modified Files: lang.cxx python.cxx Log Message: remove 'thisown' and ClassPtr Index: python.cxx =================================================================== RCS file: /cvsroot/swig/SWIG/Source/Modules/python.cxx,v retrieving revision 1.118 retrieving revision 1.119 diff -C2 -d -r1.118 -r1.119 *** python.cxx 26 Oct 2005 14:11:28 -0000 1.118 --- python.cxx 31 Oct 2005 09:58:24 -0000 1.119 *************** *** 352,361 **** --- 352,367 ---- tab4, tab4, "if isinstance(value, class_type):\n", tab4, tab8, "self.__dict__[name] = value.this\n", + #ifdef USE_THISOWN tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", + #endif tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", + #ifdef USE_THISOWN tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", + #else + tab4, "if (not static) or hasattr(self,name):\n", + #endif tab4, tab4, "self.__dict__[name] = value\n", tab4, "else:\n", *************** *** 390,394 **** --- 396,404 ---- "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n", + #ifdef USE_THISOWN tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", + #else + tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", + #endif tab4, tab4, tab4, "set(self,name,value)\n", tab4, tab4, "else:\n", *************** *** 524,528 **** * ------------------------------------------------------------ */ ! String *funcCallHelper(String *name, int kw) { String *str; --- 534,538 ---- * ------------------------------------------------------------ */ ! String *funcCallHelper(String *name, int kw, const char* self = 0) { String *str; *************** *** 531,535 **** Printv(str, "apply(", module, ".", name, ", args", (kw ? ", kwargs" : ""), ")", NIL); } else { ! Printv(str, module, ".", name, "(*args", (kw ? ", **kwargs" : ""), ")", NIL); } return str; --- 541,550 ---- Printv(str, "apply(", module, ".", name, ", args", (kw ? ", kwargs" : ""), ")", NIL); } else { ! if (self) { ! Printv(str, module, ".", name, "(", self, ", *args", (kw ? ", **kwargs" : ""), ")", NIL); ! } else { ! Printv(str, module, ".", name, "(*args", (kw ? ", **kwargs" : ""), ")", NIL); ! } ! } return str; *************** *** 785,789 **** } } else { ! Printf(doc, "??"); } --- 800,804 ---- } } else { ! Printf(doc, "?"); } *************** *** 1455,1464 **** Replaceall(tm,"$target", "resultobj"); Replaceall(tm,"$result", "resultobj"); ! if (GetFlag(n,"feature:new")) { ! Replaceall(tm,"$owner","SWIG_POINTER_OWN"); ! } else { ! Replaceall(tm,"$owner","0"); } - // FIXME: this will not try to unwrap directors returned as non-director // base class pointers! --- 1470,1482 ---- Replaceall(tm,"$target", "resultobj"); Replaceall(tm,"$result", "resultobj"); ! if (constructor || Getattr(n,"handled_as_constructor")) { ! Replaceall(tm,"$owner","SWIG_POINTER_NEW"); ! } else { ! if (GetFlag(n,"feature:new")) { ! Replaceall(tm,"$owner","SWIG_POINTER_OWN"); ! } else { ! Replaceall(tm,"$owner","0"); ! } } // FIXME: this will not try to unwrap directors returned as non-director // base class pointers! *************** *** 1923,1927 **** --- 1941,1949 ---- String *mrename = Swig_name_disown(symname); //Getattr(n, "name")); Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); + #ifdef USE_THISOWN Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); + #else + Printv(f_shadow, tab8, "self.this.disown()\n", NIL); + #endif Printv(f_shadow, tab8, module, ".", mrename,"(self)\n", NIL); Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL); *************** *** 2108,2112 **** } if (!have_constructor) { ! Printv(f_shadow_file,tab4,"def __init__(self): raise RuntimeError, \"No constructor defined\"\n",NIL); } --- 2130,2143 ---- } if (!have_constructor) { ! String *rclassname = Swig_class_name(getCurrentClass()); ! Printv(f_shadow_file, tab4,"def __init__(self, **kwargs):\n",NIL); ! Printv(f_shadow_file, tab8, "try: this = kwargs[\"_swig_this\"]\n", NIL); ! Printv(f_shadow_file, tab8, "except: this = None\n", NIL); ! Printv(f_shadow_file, tab8, "if this == None: raise RuntimeError, \"No constructor defined\"\n", NIL); ! if (!modern) { ! Printv(f_shadow_file, tab8, "_swig_setattr(self, ", rclassname, ", 'this', this )\n", NIL); ! } else { ! Printv(f_shadow_file, tab8, "self.this = this\n", NIL); ! } } *************** *** 2117,2121 **** Printv(f_shadow_file, tab4, "def __repr__(self):\n", ! tab8, "return \"<%s.%s; proxy of ", CPlusPlus ? "C++ " : "C ", rname," instance at %s>\" % (self.__class__.__module__, self.__class__.__name__, self.this,)\n", NIL); } --- 2148,2152 ---- Printv(f_shadow_file, tab4, "def __repr__(self):\n", ! tab8, "return \"<%s.%s; proxy of ", CPlusPlus ? "C++ " : "C ", rname," instance at 0x%x>\" % (self.__class__.__module__, self.__class__.__name__, self.this,)\n", NIL); } *************** *** 2123,2127 **** Printv(f_shadow_file, tab4, "def __repr__(self):\n", ! tab8, "return \"<C ", rname," instance at %s>\" % (self.this,)\n", NIL); } --- 2154,2158 ---- Printv(f_shadow_file, tab4, "def __repr__(self):\n", ! tab8, "return \"<C ", rname," instance at 0x%x>\" % (self.this,)\n", NIL); } *************** *** 2134,2137 **** --- 2165,2169 ---- /* Now the Ptr class */ + #if 0 Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", *************** *** 2140,2155 **** Printv(f_shadow_file, tab8, "_swig_setattr(self, ", class_name, ", 'this', this)\n", tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n", tab8, "self.__class__ = ", class_name, "\n", NIL); } else { Printv(f_shadow_file, tab8, "self.this = this\n", tab8, "if not hasattr(self,\"thisown\"): self.thisown = 0\n", tab8, "self.__class__ = ", class_name, "\n", NIL); // tab8,"try: self.this = this.this; self.thisown = getattr(this,'thisown',0); this.thisown=0\n", // tab8,"except AttributeError: self.this = this\n" } ! Printf(f_shadow_file,"%s.%s_swigregister(%sPtr)\n", module, class_name, class_name,0); shadow_indent = 0; Printf(f_shadow_file,"%s\n", f_shadow_stubs); --- 2172,2192 ---- Printv(f_shadow_file, tab8, "_swig_setattr(self, ", class_name, ", 'this', this)\n", + #ifdef USE_THISOWN tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n", + #endif tab8, "self.__class__ = ", class_name, "\n", NIL); } else { Printv(f_shadow_file, tab8, "self.this = this\n", + #ifdef USE_THISOWN tab8, "if not hasattr(self,\"thisown\"): self.thisown = 0\n", + #endif tab8, "self.__class__ = ", class_name, "\n", NIL); // tab8,"try: self.this = this.this; self.thisown = getattr(this,'thisown',0); this.thisown=0\n", // tab8,"except AttributeError: self.this = this\n" } + #endif ! Printf(f_shadow_file,"%s.%s_swigregister(%s)\n", module, class_name, class_name,0); shadow_indent = 0; Printf(f_shadow_file,"%s\n", f_shadow_stubs); *************** *** 2337,2341 **** String *rclassname = Swig_class_name(getCurrentClass()); assert(rclassname); ! if (use_director) { Printv(pass_self, tab8, NIL); Printf(pass_self, "if self.__class__ == %s:\n", classname); --- 2374,2378 ---- String *rclassname = Swig_class_name(getCurrentClass()); assert(rclassname); ! if (use_director) { Printv(pass_self, tab8, NIL); Printf(pass_self, "if self.__class__ == %s:\n", classname); *************** *** 2346,2351 **** } ! Printv(f_shadow, tab4, "def __init__(self, *args", ! (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL); if ( have_docstring(n) ) Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); --- 2383,2387 ---- } ! Printv(f_shadow, tab4, "def __init__(self, *args, **kwargs):\n", NIL); if ( have_docstring(n) ) Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); *************** *** 2353,2368 **** Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); Printv(f_shadow, pass_self, NIL); if (!modern) { ! Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', ", ! funcCallHelper(Swig_name_construct(symname), allow_kwargs), ")\n", NIL); Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'thisown', 1)\n", NIL); } else { ! Printv(f_shadow, tab8, "newobj = ", ! funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); ! Printv(f_shadow, tab8, "self.this = newobj.this\n", NIL); Printv(f_shadow, tab8, "self.thisown = 1\n", NIL); Printv(f_shadow, tab8, "del newobj.thisown\n", NIL); } if ( have_pythonappend(n) ) --- 2389,2408 ---- Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); Printv(f_shadow, pass_self, NIL); + Printv(f_shadow, tab8, "try: this = kwargs[\"_swig_this\"]\n", NIL); + Printv(f_shadow, tab8, "except: this = None\n", NIL); + Printv(f_shadow, tab8, "if this == None: this = ", funcCallHelper(Swig_name_construct(symname), allow_kwargs),"\n", NIL); if (!modern) { ! Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', this )\n", NIL); Printv(f_shadow, + #ifdef USE_THISOWN tab8, "_swig_setattr(self, ", rclassname, ", 'thisown', 1)\n", + #endif NIL); } else { ! Printv(f_shadow, tab8, "self.this = this\n", NIL); ! #ifdef USE_THISOWN Printv(f_shadow, tab8, "self.thisown = 1\n", NIL); Printv(f_shadow, tab8, "del newobj.thisown\n", NIL); + #endif } if ( have_pythonappend(n) ) *************** *** 2391,2395 **** --- 2431,2437 ---- Printv(f_shadow_stubs, tab4, "val = ", funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); + #ifdef USE_THISOWN Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); + #endif if ( have_pythonappend(n) ) Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL); *************** *** 2411,2414 **** --- 2453,2457 ---- if (shadow) shadow = shadow | PYSHADOW_MEMBER; + //Setattr(n,"emit:dealloc","1"); Language::destructorHandler(n); shadow = oldshadow; *************** *** 2426,2432 **** --- 2469,2481 ---- if ( have_pythonprepend(n) ) Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); + #ifdef USE_THISOWN Printv(f_shadow, tab8, "try:\n", NIL); Printv(f_shadow, tab8, tab4, "if self.thisown: destroy(self)\n", NIL); Printv(f_shadow, tab8, "except: pass\n", NIL); + #else + Printv(f_shadow, tab8, "try:\n", NIL); + Printv(f_shadow, tab8, tab4, "if self.this.own(): destroy(self.this)\n", NIL); + Printv(f_shadow, tab8, "except: pass\n", NIL); + #endif if ( have_pythonappend(n) ) Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); Index: lang.cxx =================================================================== RCS file: /cvsroot/swig/SWIG/Source/Modules/lang.cxx,v retrieving revision 1.120 retrieving revision 1.121 diff -C2 -d -r1.120 -r1.121 *** lang.cxx 18 Oct 2005 14:04:14 -0000 1.120 --- lang.cxx 31 Oct 2005 09:58:24 -0000 1.121 *************** *** 2270,2277 **** --- 2270,2284 ---- String *symname = Getattr(n,"sym:name"); String *mrename = Swig_name_construct(symname); + String *nodeType = Getattr(n, "nodeType"); + int constructor = (!Cmp(nodeType, "constructor")); List *abstract = 0; String *director_ctor = get_director_ctor_code(n, director_ctor_code, director_prot_ctor_code, abstract); + if (!constructor) { + /* if not originally a constructor, still handle it as one */ + Setattr(n,"handled_as_constructor","1"); + } + Swig_ConstructorToFunction(n, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 :Extend); |