Re: g_try_new and g_try_new0 + error reporting for g_object_set
- From: Tim Janik <timj gtk org>
- To: Stefan Kost <ensonic hora-obscura de>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>, Stefan Kost <kost imn htwk-leipzig de>
- Subject: Re: g_try_new and g_try_new0 + error reporting for g_object_set
- Date: Mon, 16 May 2005 15:33:30 +0200 (CEST)
On Thu, 12 May 2005, Stefan Kost wrote:
the problem is not the OOM case. The problem is that the user may has entered
a too large value for something and that is the base for an allocation.
It is much better telling the user that this much memory can't be allocated,
rather that just crash and loose the work of the user.
you are right, and similar situations are actually what g_try_new() and friends
were added for. however the GObject proeprty system has a limitation by design
that conflicts with the scenrio you outlined above. that is, setting an object
property will *always* succeed, there is no mechanism to handle or report
errors in setting object properties through the g_object_set*() interface and
there never will be.
the options you have to implement you user feedback above are:
* in any case accept the value set on the object via g_boject_set () (since you
have to and can't signal g_object_set() failing)
- simply don't change you internal value if the value set from the outside is
too large (i.e. turn property setters of too large values into a NOP).
- add a current-error or similar property which is changed when setting too
large values, so the user is notified (::notify::current-error) and can read
out the error.
- add a signal that is emitted if too big values are set, the signal can carry
an error description.
- use your own API instead of object properties which can have suitable
mechanisms to report failure and report errors.
] [Thread Prev