glib dependency for the X Server

Ray Strode halfline at gmail.com
Mon Apr 3 11:00:02 PDT 2006


Hi,

On 4/3/06, Erwin Rol <mailinglists at erwinrol.com> wrote:
> On Mon, 2006-04-03 at 19:41 +0900, Carsten Haitzler wrote:
>
> > > So I think glib wouldn't be that bad of a choice.
> >
> > abort().
>
> Did anybody asked the glib developers if that could be changed ? It
> would probably not be that big a deal to add some OOM handler that
> defaults to abort() but can be set to something else by the user (Xorg
> in this case).
glib already has a mechanism for making memory allocation calls not
abort. You can just do g_mem_set_vtable and pass g_try_malloc as the
malloc handler.  Then g_malloc will return NULL on OOM.  The problem
is none of the glib data structures expect g_malloc to return NULL so
instead of abort you'll just hit a segfault from NULL pointer
dereferencing and such.

I don't think it would be too hard to change most of glib's data
structures to handle NULL malloc returns gracefully, but I could be
wrong.  You'd have to be careful about some things like statically
allocating a special OOM GError for functions that return GErrors, and
in some case it might be hard to keep function semantics exactly the
same in the default abort() case.  It would also add a lot of error
checking code that will never be hit in apps (becuase by default glib
would still abort()). On linux with the default over committing
behavior enabled the error checking code is pretty worthless too,
because the kernel will just kill programs randomly on Out of memory
instead of return NULL from a malloc.

If X doesn't currently handle OOM gracefully anyway, then it seems
like a silly requirement though.



More information about the xorg mailing list