Re: Abstract string properties with getter/setter functions



On Thu, 2007-09-20 at 08:34 +0200, Raffaele Sandrini wrote:

> Take a look at 'gtk_file_chooser_get_preview_widget'. While the hack
> done there is somehow possible with objects it is not with strings.
> 
> GtkWidget *
> gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
> {
>   GtkWidget *preview_widget;
>   
>   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
> 
>   g_object_get (chooser, "preview-widget", &preview_widget, NULL);
>   
>   /* Horrid hack; g_object_get() refs returned objects but
>    * that contradicts the memory management conventions
>    * for accessors.
>    */
>   if (preview_widget)
>     g_object_unref (preview_widget);
> 
>   return preview_widget;
> }

By the way, this is a *TERRIBLE* idea.  I don't remember why I wrote the
code that way.  Please don't follow that broken pattern.

[In the file chooser it works because the GtkFileChooser implementation
always holds a reference to the preview widget.]

It's much easier to write things if you always get a new reference from
accessors.

  Federico




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