[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] [bug] Gtk bug
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] [bug] Gtk bug |
Date: |
Wed, 29 Apr 2009 12:19:50 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (Macintosh/20090302) |
Gwenael Casaccio wrote:
> On Wednesday 29 April 2009 10:15:48 you wrote:
>> Hi Paolo,
>>
>> It seems that the crashes came when you free a GtkTreeIter or GtkTextIter,
>> you use the free_oop_for_g_object function (in gst-gtk.c) but these are
>> classical structures not GObject.
Almost there: I use gtk_tree_iter_free, but I allocate it with malloc
instead of gtk_tree_iter_copy.
This patch fixes half of it:
diff --git a/packages/gtk/GtkImpl.st b/packages/gtk/GtkImpl.st
index 4b32273..a383fb2 100644
--- a/packages/gtk/GtkImpl.st
+++ b/packages/gtk/GtkImpl.st
@@ -172,9 +172,16 @@ GdkRectangle extend [
GtkTreeIter class extend [
+ Prototype := nil.
+
+ gcNew [
+ ^self type gcNew
+ ]
+
new [
<category: 'instance creation'>
- ^(self type new)
+ Prototype isNil ifTrue: [ Prototype := self type gcNew ].
+ ^Prototype copy
addToBeFinalized;
yourself
]
@@ -185,9 +192,16 @@ GtkTreeIter class extend [
GtkTextIter class extend [
+ Prototype := nil.
+
+ gcNew [
+ ^self type gcNew
+ ]
+
new [
<category: 'instance creation'>
- ^(self type new)
+ Prototype isNil ifTrue: [ Prototype := self type gcNew ].
+ ^Prototype copy
addToBeFinalized;
yourself
]
Even then, GtkTreeIter>>#free do not set the object to point to NULL,
which may cause double frees. So we need this too:
diff --git a/packages/gtk/funcs.awk b/packages/gtk/funcs.awk
index 340cfbf..0ca78f6 100644
--- a/packages/gtk/funcs.awk
+++ b/packages/gtk/funcs.awk
@@ -308,3 +308,10 @@ match_function_first_line($0) {
+ if (decl == "free") {
+ print "free"
+ print " (self isAbsolute and: [ self address > 0 ])"
+ print "\tifTrue: [ self primFree. self address: 0 ]!"
+ decl = "primFree"
+ }
+
print decl
print " <cCall: '" cFuncName "' returning: " retType
print "\targs: #(" argdecl " )>! !\n"
Still, it's terribly inefficient to use finalization when GC could work
instead. Many of the helper methods in packages/gtk/GtkImpl.st could
use #gcNew instead of #new.
I'm committing the above patches. Thanks!
Paolo