diff --git a/SWIG/CHANGES.current b/SWIG/CHANGES.current index 734065c07..385cdda96 100644 --- a/SWIG/CHANGES.current +++ b/SWIG/CHANGES.current @@ -638,10 +638,17 @@ Version 1.3.28 (unreleased). *** POTENTIAL INCOMPATIBILITY *** - There is no more ClassPtr classes, so, if in the past you - needed to resort in some kind of trick to use, or overcome - their presence, it is no longer needed, but the extra code - you added could break. + There is no more ClassPtr classes in the python code. Hence, + if in the past you needed to resort in some kind of trick + to use them, or overcome their presence, it is no longer + required, but the extra code you added could now break + things arounds. + + If needed, you can use the option -classptr, i.e., + + swig -classptr -python ... + + to generate the old ClassPtr classes. 10/30/2005: mkoeppe diff --git a/SWIG/Source/Modules/python.cxx b/SWIG/Source/Modules/python.cxx index 19af5dbaa..0568fddb8 100644 --- a/SWIG/Source/Modules/python.cxx +++ b/SWIG/Source/Modules/python.cxx @@ -60,6 +60,7 @@ static String *real_classname; /* Thread Support */ static int threads = 0; static int nothreads = 0; +static int classptr = 0; /* flags for the make_autodoc function */ enum autodoc_t { @@ -86,6 +87,7 @@ Python Options (available with -python)\n\ -new_vwm - New value wrapper mode, use only when everything else fails \n\ -new_repr - Use more informative version of __repr__ in proxy classes (default) \n\ -old_repr - Use shorter and old version of __repr__ in proxy classes\n\ + -classptr - Generate shadow 'ClassPtr' as in older swig versions\n\ -threads - Add thread support for all the interface\n\ -nothreads - Disable thread support for all the interface\n\ -noexcept - No automatic exception handling\n\ @@ -214,6 +216,9 @@ public: } else if (strcmp(argv[i],"-old_repr") == 0) { new_repr = 0; Swig_mark_arg(i); + } else if (strcmp(argv[i],"-classptr") == 0) { + classptr = 1; + Swig_mark_arg(i); } else if ((strcmp(argv[i],"-noproxy") == 0)) { shadow = 0; Swig_mark_arg(i); @@ -2304,29 +2309,34 @@ public: Printv(f_shadow_file, f_shadow, NIL); /* Now the Ptr class */ -#if 0 - Printv(f_shadow_file, - "\nclass ", class_name, "Ptr(", class_name, "):\n", - tab4, "def __init__(self, this):\n", NIL); - if (!modern) { - Printv(f_shadow_file, - tab8, "_swig_setattr(self, ", class_name, ", 'this', this)\n", + if (classptr) { + Printv(f_shadow_file, + "\nclass ", class_name, "Ptr(", class_name, "):\n", + tab4, "def __init__(self, this):\n", NIL); + if (!modern) { + Printv(f_shadow_file, + tab8, "try: self.this.append(this)\n", + tab8, "except: self.this = this\n", #ifdef USE_THISOWN - tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n", + tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n", +#else + tab8, "self.this.own(0)\n", #endif - tab8, "self.__class__ = ", class_name, "\n", NIL); - } else { - Printv(f_shadow_file, - tab8, "self.this = this\n", + tab8, "self.__class__ = ", class_name, "\n\n", NIL); + } else { + Printv(f_shadow_file, + tab8, "try: self.this.append(this)\n", + tab8, "except: self.this = this\n", #ifdef USE_THISOWN - tab8, "if not hasattr(self,\"thisown\"): self.thisown = 0\n", + tab8, "if not hasattr(self,\"thisown\"): self.thisown = 0\n", +#else + tab8, "self.this.own(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" + tab8, "self.__class__ = ", class_name, "\n\n", NIL); + } } -#endif - + + List *shadow_list = Getattr(n,"shadow_methods"); for (int i = 0; i < Len(shadow_list); ++i) { String *symname = Getitem(shadow_list,i);