Re: Freeing memory used by QTableItem

Richard Dale <[email protected]>
Newsgroups gmane.comp.kde.devel.perl
Organization Lost Highway
Message-ID <[email protected]>
On Friday 09 July 2004 12:22, Oliver Kreuer wrote:
> my $junk = Qt::PushButton("Hello World!", undef);
> Qt::dispose($junk);
>
> this works fine. But I tried my example program (see attachment)
> and I got the following error messages:
>
> QGVector::remove: Index -2 out of range
> QGVector::remove: Index -2 out of range
Yes, that still happens.

> Memory fault
He's a version of the patch that works like this:

my $junk = Qt::PushButton("Hello World!", undef);
$junk->dispose();
if ($junk->isDisposed()) {
...

It also has the fix for the crash problem.

$ cp perlqtdispose_0.2.patch PerlQt-3.008
$ cd PerlQt-3.008/PerlQt
$ patch -p1 < ../perlqtdispose_0.2.patch

Then make and install PerlQt

I'm looking into the resize/not updating bug now. I would have thought it was 
a bug in Qt - It also happens in qtruby, but you say it doesn't happen with 
C++ - which is interesting. Hmm..

Trying to help out with perlqt fixes is actually a good way of improving 
qtruby too. Thanks for the example code..

-- Richard

_______________________________________________
Kde-perl mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-perl
perlqtdispose_0.2.patch (text/x-diff, 2.6 KB)
diff -Naur -X /home/duke/bin/patcher.exclude PerlQt/Qt.pm temp/Qt.pm
--- PerlQt/Qt.pm	2003-09-09 03:57:11.000000000 +0100
+++ temp/Qt.pm	2004-07-10 10:21:32.000000000 +0100
@@ -421,9 +421,13 @@
 	    my $t = $typename;
 	    $t =~ s/^const\s+//;
 	    $t =~ s/(?<=\w)[&*]$//;
-	    my $isa = classIsa($argtype, $t);
-	    if($isa) {
-		$match{$method} = 0;
+		if ( $argtype eq $t ) {
+			$match{$method} = 1;
+		} else {
+	    	my $isa = classIsa($argtype, $t);
+	    	if($isa) {
+			$match{$method} = 0;
+			}
 	    }
 	}
     }
@@ -1108,4 +1112,17 @@
     return 1
 }
 
+sub Qt::base::dispose 
+{ 
+    package Qt::_internal;
+	Qt::_internal::dispose(this());
+	return;
+}
+
+sub Qt::base::isDisposed 
+{ 
+    package Qt::_internal;
+	return Qt::_internal::isDisposed(this());
+}
+
 1;
diff -Naur -X /home/duke/bin/patcher.exclude PerlQt/Qt.xs temp/Qt.xs
--- PerlQt/Qt.xs	2003-09-09 09:41:25.000000000 +0100
+++ temp/Qt.xs	2004-07-10 10:21:25.000000000 +0100
@@ -999,6 +999,7 @@
 	    SvREFCNT_dec(sv_this);
 	    sv_this = old_this;
 	}
+	o->allocated = false;
 	if( ret && (do_debug & qtdb_gc) )
 	    fprintf(stderr, "Increasing refcount in DESTROY for %s=%p (still has a parent)\n", package, o->ptr);
     } else {
@@ -1492,7 +1493,12 @@
     CODE:
     Smoke::Method &m = qt_Smoke->methods[method];
     Smoke::Index *args = qt_Smoke->argumentList + m.args;
-    RETVAL = (char*)qt_Smoke->types[args[idx]].name;
+    if ((qt_Smoke->types[args[idx]].flags & 0x0f) == Smoke::t_enum) {
+		// Just treat enums as longs, don't bother matching on the enum name
+		RETVAL = "long";
+	} else {
+    	RETVAL = (char*)qt_Smoke->types[args[idx]].name;
+	}
     OUTPUT:
     RETVAL
 
@@ -1743,6 +1749,44 @@
     delete qobj;
 
 void
+dispose(obj)
+    SV *obj
+    CODE:
+    smokeperl_object *o = sv_obj_info(obj);
+    if(!o || !o->ptr) { 
+		XSRETURN_EMPTY;
+	} else {
+		const char *className = o->smoke->classes[o->classId].className;
+		char *methodName = new char[strlen(className) + 2];
+		methodName[0] = '~';
+		strcpy(methodName + 1, className);
+		Smoke::Index nameId = o->smoke->idMethodName(methodName);
+		Smoke::Index meth = o->smoke->findMethod(o->classId, nameId);
+		if(meth > 0) {
+			Smoke::Method &m = o->smoke->methods[o->smoke->methodMaps[meth].method];
+			Smoke::ClassFn fn = o->smoke->classes[m.classId].classFn;
+			Smoke::StackItem i[1];
+			(*fn)(m.method, o->ptr, i);
+		}
+		delete[] methodName;
+		o->ptr = 0;
+		o->allocated = false;
+	}
+
+bool
+isDisposed(obj)
+    SV *obj
+    CODE:
+    smokeperl_object *o = sv_obj_info(obj);
+    if(!o || !o->ptr) { 
+		RETVAL = 0; 
+	} else {
+		RETVAL = 1;
+	}
+    OUTPUT:
+    RETVAL
+
+void
 mapObject(obj)
     SV *obj
     CODE:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.