[Kde-bindings] KDE/kdebindings/kalyptus

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Aug 7 09:53:22 UTC 2008


SVN commit 843493 by rdale:

* If a class has a static method called self() and no public constructor then assume it is a singleton.
  This fixes a crash when calling methods on classes like KGlobalSettings() because the destructor
  was being called on the temporary instance created for the method call.

CCMAIL: kde-bindings at kde.org


 M  +10 -3     kalyptusCxxToSmoke.pm  


--- trunk/KDE/kdebindings/kalyptus/kalyptusCxxToSmoke.pm #843492:843493
@@ -708,7 +708,10 @@
 			}
 		}
 
-		
+		if ($name eq 'self' && $m->{Flags} =~ "s") {
+			$classNode->AddProp( "Singleton", 1 );
+		}
+
 	    my $argId = 0;
 	    my $firstDefaultParam;
 	    foreach my $arg ( @{$m->{ParamList}} ) {
@@ -1726,8 +1729,12 @@
             $methodCode .= "private:\n";
             $methodCode .= "    $className *xthis;\n";
             $methodCode .= "public:\n";
-            $methodCode .= "    $xClassName\(void *x) : xthis(($className*)x) {}\n";
-            $switchCode .= "    $xClassName xtmp(obj), *xself = &xtmp;\n";
+            if ($classNode->{Singleton}) {
+                $switchCode .= "    $xClassName *xself = ($xClassName *) $className" . "::self();\n";
+            } else {
+                $methodCode .= "    $xClassName\(void *x) : xthis(($className*)x) {}\n";
+                $switchCode .= "    $xClassName xtmp(obj), *xself = &xtmp;\n";
+            }
         } else {
             $switchCode .= "    $xClassName *xself = ($xClassName*)obj;\n";
             $methodCode .= "public:\n";



More information about the Kde-bindings mailing list