Re: g_try_new and g_try_new0 + error reporting for g_object_set

As the mail remained uncommented, it has now been posted under


Stefan Kost wrote:
hi hi,

is there a reason why we dont have g_try_new and g_try_new0.

Why I am asking? We use g_new a lot in our code. Recently we have added a helper
method to our unit-tests that goes over gobject properties of a given instance
and does read/write checks.
This triggered a 'problem'. For one class there is a property denoting the size
of a data-structure (number of slots). One can write to this property and then
the datastructure will adapt its size.
On one hand we do not want to limit the size more than neccesary, so the number
of entries is a g_ulong. The unit-testing code now tried to set the property to
the largest ulong and this caused it to abort, as g_new0 wasn't be able to
allocate that much. Now here would would rather like to notifiy the user that we
were not be able to perform that operation, than just aborting.
Therefor the need for g_try_new0.

The second thing is how does one report that a g_object_set failed? All I can
currently think of is an error-property in the object, which the caller can
connect a notify handler on and retrieve the GError object in case of a problem.

Sorry if this is a bit offtopic, its more a best-practise question...


gtk-devel-list mailing list
gtk-devel-list gnome org

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