Re: Implementing a customtree with Gtk2::TreeModel




On Jan 13, 2005, at 12:18 AM, ofey aikon wrote:

If any one has code snippets related to this task, please throw it in. My (non-working) code is attached, in case some one has the time to review it and let me know how disturbing it is :)

You're already running up against one of the basic difficulties, imposed by the stack-use-based design of C GtkTreeIter.

What you're seeing ("There is a disparity...") is an internal GtkTreeView sanity check failing, because one of the items you've placed into your iter ($iter->[2]) is a string, and by the time the iter gets back to a place where it can be used, the scalar has already been destroyed.


The problem is the complete lack of lifetime management on GtkTreeIter in the C api, which is a side effect of its design for speed and efficiency. There is no destructor called when the GtkTreeIter is destroyed. This is alright for binding the client-side use of the iter, but is deadly for implementing a TreeIter in a language like perl, in which even primitive values (strings, numbers, references) are lifetime-managed complex objects (SVs). Because the TreeModel interface is made up of virtual functions from which we return new objects to calling C code, and because the Iter is necessarily bound in a way that doesn't know about the internals of the structure, we can neither use mortal SVs (they will be destroyed at the next perl statement, which, because the bindings can't look inside Iters from the client side, won't know to keep the object alive) nor typical SVs with a single reference (because without a destruction notification, we'll simply leak them). Our only viable solution is to place a "weak reference" to a scalar in the iter --- that is, just the address of a scalar that is lifetime-managed by the model implementation.

In other words, you have to cache any non-integer value you place into an iter.


(sorry to leave it at that, i'm out of time for the morning)

--
To me, "hajime" means "the man standing opposite you is about to hit you with a stick".
  -- Ian Malpass, speaking of the Japanese word for "the beginning"




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]