Re: Memory allocation troubles



On Wed, 20 Oct 2004 02:00:29 +0300, Paul Pogonyshev <pogonyshev gmx net> wrote:
[...]
Oh, I just remembered that you can use your own malloc() implementation
with Glib/GTK+!  So, while this doesn't solve your problem out of the box,
you can do something like this:

This doesn't help, 
     gtk+ is written with the assumption that its all-or-nothing
(memory available
or abort), so even if your implementation of malloc returns NULL
(which I think is
asserted anyway outside your implementation) then you'd have functions like
g_object_new() segfaulting instead of returning NULL (i.e. someone in
gtk_something_init() will allocate something, fail, access it and segfault).

I have to agree with Brian on the fact that, not checking function return code
is really ugly programmer practice as specialy when the function is returning
a reference to a newly created resource such as a file descriptor or a memory
region (my stomach turns every time I do  write `str =
g_strdup_printf()' instead of
`if ((str = g_strdup_printf()) != NULL)' ).

At the same time, I dont think its fair, that if I write an
application with the
assumption that g_object_new() will be "asserted" and all of a sudden
my application starts crashing because someone upgraded gtk+, its just
a matter of respect (to be respectfull, it would entail a "api change" and
at least require people to port their applications to the new behavior).

Cheers,
                                                -Tristan



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