This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Is this MORECORE definition in malloc.c just dead code, or am I missing something?
- From: Brooks Moses <bmoses at google dot com>
- To: libc-alpha <libc-alpha at sourceware dot org>
- Cc: Paul Pluzhnikov <ppluzhnikov at google dot com>
- Date: Tue, 11 Mar 2014 16:45:46 -0700
- Subject: Is this MORECORE definition in malloc.c just dead code, or am I missing something?
- Authentication-results: sourceware.org; auth=none
I was recently looking through malloc/malloc.c to understand how the
various macros inside it get defined, and I am confused. Perhaps
someone can help me figure this out?
On lines 401 and 402, we have:
#define MORECORE (*__morecore)
#define MORECORE_FAILURE 0
Then, on lines 421-423, we have:
#ifndef MORECORE
#define MORECORE sbrk
#endif
And likewise for MORECORE_FAILURE on lines 432-434. As far as I can
tell, there's no code between these two blocks that would cause
MORECORE to be undefined, and so there's no possible way that the
second set of definitions could fire. Why are they there?
I am also feeling somewhat confused about why we use this
__default_morecore indirection, anyway. It looks like mostly
__default_morecore (in malloc/morecore.c) just calls __sbrk and
changes the error return value. Why not just define MORECORE to
__sbrk and MORECORE_FAILURE to -1?
Thanks,
- Brooks