> That's not an issue - you can put even a pointer but the problem is that
> you need to pin object. You don't know (automatically without user
> intervention) when you can free the resource. At any point GTK might
> keep GtkTreeIter alive so data you put inside cannot be freed (or
> garbage collected or however you'll call it) and it need's to be always
> considered 'alive'. I guess it is possible to workaround the issue by
> reverse engineering the Gtk internals but solution would be very
> unstable and not remotely elegant. 

The problem with GtkTreeIter is that you can't make any function to be
called when iter goes out of scope. Example:

int
foo(void)
{
  GtkTreeIter iter;
  get_iter_of_something (&iter);
  do_something_with_iter (&iter);

  /* iter is no longer needed, C frees its memory 
     automatically, but we can't make it call a 
     custom function, as C doesn't have C++'s
     destructors, that's why we can't put references
     to JavaScript objects into them */
}

However, luckily for us, GtkTreeIter has an integer stamp field that
could be used instead of a direct reference. JavaScript custom tree
models will be slower as they would need to look up items by their
stamps. Example:

_init: function() {
  this.parent(...);
  this._items = [];
},

getTreeIterOfItem: function(itemStamp)
{
  if (this._items[itemStamp] === undefined)
    return undefined;

  return new Gtk.TreeIter(itemStamp);
},

getItemByTreeIter: function(iter)
{
  return this._items[iter.stamp];
}

_______________________________________________
desktop-devel-list mailing list
desktop-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/desktop-devel-list

Reply via email to