This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is this MORECORE definition in malloc.c just dead code, or am I missing something?


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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]