Re: [gtk-list] querying object args and gtk+ class initialisation



On Sat, 24 Apr 1999, Michael Beach wrote:

> Greetings gtk+ gurus...
> 
> In the course of fiddling about with gtk+ (version 1.2.1), I have been
> attempting to use the gtk_object_query_args() function in the context of the
> following program fragment...
> 
> int main(int argc, char *argv[])
> {
>     GtkType type_id;
>     GtkArg *arg_array;
>     guint num_args;
> 
>     gtk_init(NULL, NULL);
> 
>     gtk_window_get_type();
>     type_id = gtk_type_from_name("GtkWindow");
>     /* gtk_type_class(type_id); */
>     arg_array = gtk_object_query_args(type_id, NULL, &num_args);
> 
>     exit(0);
> }
> 
> Unfortunately, when I run it, it comes back with...
> 
> Gtk-CRITICAL **: file gtkarg.c: line 338 (gtk_args_query): assertion
> `arg_info_hash_table != NULL' failed.
> 
> After some digging, I discovered that in this case arg_info_hash_table was
> assigned the value of the object_arg_info_ht, a static in gtkobject.c. In order
> to ensure that this was not null, it was necessary to ensure that
> gtk_object_add_arg_type() was called. However this function seems to be
> called when a class is initialised.
> 
> Paradoxically though, gtk_args_query() contains the following snippet of code...
> 
>   g_return_val_if_fail (arg_info_hash_table != NULL, NULL);
> 
>   /* make sure the types class has been initialized, because
>    * the argument setup happens in the gtk_*_class_init() functions.
>    */
>   gtk_type_class (class_type);
> 
> ie it wants to call gtk_type_class() to ensure that class initialisation is
> done, but unless some class has been previously initialised through some other
> path of execution it can never get that far, as it will bomb out due to
> arg_info_hash_table being uninitialised. Indeed, when the call to
> gtk_type_class() is uncommented in my code fragment above, the error goes away,
> as the call results in object_arg_info_ht being initialised.
> 
> To me, all of this looks like a bit of a buglet.
[...]

yeah, you're absolutely correct, i added that line
>   gtk_type_class (class_type);
when we had a similar problem with signals, where a query function needed
the class to be initialized, and didn't really think about the hash table
constrains of the argument code.

the proper fix would be:

@@ gtkarg.c:gtk_args_query
-  /* make sure the types class has been initialized, because
-   * the argument setup happens in the gtk_*_class_init() functions.
-   */
-  gtk_type_class (class_type);

@@ gtkarg.h:gtk_args_query
+  /* make sure the types class has been initialized, so a
+   * arg_info_hash_table != NULL is passed into this function
+   */
 GtkArg*         gtk_args_query           (GtkType       class_type,

@@ gtkcontainer.h:gtk_container_query_child_args
+  gtk_type_class (class_type);
+
   return gtk_args_query (class_type, container_child_arg_info_ht, arg_flags, n_args);

@@ gtkobject.h:gtk_object_query_args
+  gtk_type_class (class_type);
+
   return gtk_args_query (class_type, object_arg_info_ht, arg_flags, n_args);


---
ciaoTJ



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