This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Is this MORECORE definition in malloc.c just dead code, or am I missing something?
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Brooks Moses <bmoses at google dot com>
- Cc: libc-alpha <libc-alpha at sourceware dot org>, Paul Pluzhnikov <ppluzhnikov at google dot com>
- Date: Wed, 12 Mar 2014 01:01:06 +0100
- Subject: Re: Is this MORECORE definition in malloc.c just dead code, or am I missing something?
- Authentication-results: sourceware.org; auth=none
- References: <CAOxa4KoUgC2tjF9PSsXpF4ueUcon8OpZ5z+=-8AkGFa6qxpVqA at mail dot gmail dot com>
On Tue, Mar 11, 2014 at 04:45:46PM -0700, Brooks Moses wrote:
> 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?
>
Yes in malloc these are historic relic from dlmalloc. User could supply
a custom sbrk. Probably these could be cleaned up. Look at
documentation in malloc.c starting by line
* Synopsis of compile-time options: