Re: [Vala] Some basic questions

2008-04-07 Thread Jürg Billeter
On Wed, 2008-04-02 at 12:52 +0200, Juerg Billeter wrote:
> On Sat, March 22, 2008 20:06, Mikael Hermansson wrote:
> > 1:
> >
> > If I want a copy of Gtk.TreePath I have to use weak but the problem is
> > howto free it after use?
> 
> That's a bug in the bindings, copy should obviously not return a weak
> reference.

Fixed now.

> > 2:
> >
> > Another problem probadly a binding bug:
> >
> > weak List selection = tw.get_selection().get_selected_rows();
> >
> > Because of the weak ref vala will not free the object but howto free it
> > manually then??
> 
> Same here, bug in the bindings.

Fixed now.

> > 3: Also the model parameter should not be unrefed
> >
> > TreeModel model;
> > selections=treeviewPlaylist.get_selection().get_selected_rows( out
> > model);
> > if (selection)
> >   return ;
> 
> That's a bug in the compiler, the bindings correctly state that it's a out
> weak parameter, i.e. it shouldn't be unref'd.

Not fixed yet, it should be possible to work around this issue by
declaring the local model variable as "weak TreeModel model;". Please
open a bug report about the issue.

Jürg

___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Some basic questions

2008-04-02 Thread Juerg Billeter
On Sat, March 22, 2008 20:06, Mikael Hermansson wrote:
> 1:
>
> If I want a copy of Gtk.TreePath I have to use weak but the problem is
> howto free it after use?

That's a bug in the bindings, copy should obviously not return a weak
reference.

> 2:
>
> Another problem probadly a binding bug:
>
> weak List selection = tw.get_selection().get_selected_rows();
>
> Because of the weak ref vala will not free the object but howto free it
> manually then??

Same here, bug in the bindings.

> 3: Also the model parameter should not be unrefed
>
> TreeModel model;
> selections=treeviewPlaylist.get_selection().get_selected_rows( out
> model);
> if (selection)
>   return ;

That's a bug in the compiler, the bindings correctly state that it's a out
weak parameter, i.e. it shouldn't be unref'd.

Feel free to open bug reports to make sure we don't forget about these
issues.

Juerg

___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Some basic questions

2008-03-23 Thread Mikael Hermansson
On Sat, 2008-03-22 at 19:23 +, Phil Housley wrote:
> On 22/03/2008, Mikael Hermansson <[EMAIL PROTECTED]> wrote:
> > 1:
> >
> >  If I want a copy of Gtk.TreePath I have to use weak but the problem
is
> >  howto free it after use?
> >
> >  TreePath a;
> >  weak TreePath b;
> >
> >  b=a.copy();
> >  b.[free/unref] <- does not work.
> 
> You should never have to free anything in Vala, except where you
> specifically choose not to use the automatic memory management (by
> using pointers.)  When you get a weak reference to an object, you are
> accepting that the object might be free'd even though you still have a
> reference to it - this usually implies that the actual management of
> that object is totally hidden away inside a library.

valac --pkg gtk+-2.0

If I take a copy of TreeView it will not free the object.

Example code here:

using Gtk;
public class Tree
{
TreeView tw;
construct 
{
TreeIter iter;
TreePath path;
weak TreePath path2;
tw = new TreeView.with_model(new ListStore(1, typeof(string)));
var model =(ListStore) tw.get_model();
model.append(out iter);
model.get_iter_first(out iter);
path = model.get_path(iter);
path2=path.copy();
}
}


Created C code last line in the tree_constructur:

path2 = gtk_tree_path_copy (path);
(path == NULL ? NULL : (path = (gtk_tree_path_free
(path), NULL)));
}

This means app will leak the gtk.TreePath 



> >  List selection = tw.get_tree_selection().get_selected_rows();
> >
> Again, you never need to free.  Probably the weak ref is used because
> the library might decide to free the object as soon as it is no longer
> valid.

Well then the binding is wrong because Gtk reference API says returned
selection list should be free after use and if I take a close look in
the C source created it will not free the list and its objects.

I dont know howto fix the binding maybe I should send a bugreport about
this...

>  3: Also the model parameter should not be unrefed
>
>  TreeModel model;
>  selections=treeviewPlaylist.get_selection().get_selected_rows( out
>  model);
>  if (selection)
>   return ;
> Should it definitely not be unref'd?  Normally and out parameter will
> result in a strong reference being made, and so an unref is needed
> when the local variable goes out of scope.  You could well be right in
> this case though, I haven't looked at what this code actually does.
> 

If i not pass weak TreeModel to the .get_selected_rows(model) it will
unref the object and the result is a corrupt TreeModel.

Greets

Mikael Hermansson


___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Some basic questions

2008-03-22 Thread Phil Housley
On 22/03/2008, Mikael Hermansson <[EMAIL PROTECTED]> wrote:
> 1:
>
>  If I want a copy of Gtk.TreePath I have to use weak but the problem is
>  howto free it after use?
>
>  TreePath a;
>  weak TreePath b;
>
>  b=a.copy();
>  b.[free/unref] <- does not work.

You should never have to free anything in Vala, except where you
specifically choose not to use the automatic memory management (by
using pointers.)  When you get a weak reference to an object, you are
accepting that the object might be free'd even though you still have a
reference to it - this usually implies that the actual management of
that object is totally hidden away inside a library.

>  2:
>
>  Another problem probadly a binding bug:
>
>  weak List selection = tw.get_selection().get_selected_rows();
>
>  Because of the weak ref vala will not free the object but howto free it
>  manually then??
>
>  Also tried this:
>
>  List selection = tw.get_tree_selection().get_selected_rows();
>
>  but it didnt compile.

Again, you never need to free.  Probably the weak ref is used because
the library might decide to free the object as soon as it is no longer
valid.

>  3: Also the model parameter should not be unrefed
>
>  TreeModel model;
>  selections=treeviewPlaylist.get_selection().get_selected_rows( out
>  model);
>  if (selection)
>   return ;
>
>  C code will generate:
>
>  GtkTreeModel *model;
>
>  (&model)
>  if (selection == NULL) {
> g_object_unref(model);  <- WRONG should not unref model
> return 0;
>  }
>
>  adding a weak reference fixes the issue but should vala give a warning
>  or is the binding wrong?

Should it definitely not be unref'd?  Normally and out parameter will
result in a strong reference being made, and so an unref is needed
when the local variable goes out of scope.  You could well be right in
this case though, I haven't looked at what this code actually does.

-- 
Phil Housley
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Some basic questions

2008-03-22 Thread Mikael Hermansson
1:

If I want a copy of Gtk.TreePath I have to use weak but the problem is 
howto free it after use?

TreePath a;
weak TreePath b;

b=a.copy();
b.[free/unref] <- does not work.


2:

Another problem probadly a binding bug:

weak List selection = tw.get_selection().get_selected_rows();

Because of the weak ref vala will not free the object but howto free it
manually then??

Also tried this:

List selection = tw.get_tree_selection().get_selected_rows();

but it didnt compile.

3: Also the model parameter should not be unrefed
 
TreeModel model;
selections=treeviewPlaylist.get_selection().get_selected_rows( out
model);
if (selection)
  return ;

C code will generate:

GtkTreeModel *model;

(&model)
if (selection == NULL) {
g_object_unref(model);  <- WRONG should not unref model
return 0; 
}

adding a weak reference fixes the issue but should vala give a warning
or is the binding wrong?


Greets

Mikael Hermansson

___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list