More compatibility!

Denys Vlasenko vda.linux at googlemail.com
Sun Dec 5 00:31:17 UTC 2010


On Sunday 05 December 2010 00:22, Chris Rees wrote:
> On 4 December 2010 18:52, Denys Vlasenko <vda.linux at googlemail.com> wrote:
> > On Thursday 02 December 2010 22:32, Chris Rees wrote:
> >> On 1 December 2010 21:06, Chris Rees <utisoft at gmail.com> wrote:
> >> > On 1 December 2010 20:42, Paul Smith <paul at mad-scientist.net> wrote:
> >> >> On Wed, 2010-12-01 at 19:09 +0000, Chris Rees wrote:
> >> >>> Hi,
> >> >>>
> >> >>> The use of malloc.h is a SYSVism, and the attached patch fixes for
> >> >>> FreeBSD at least!
> >> >>>
> >> >>> http://www.bayofrum.net/~chris/patch-appletlib-c
> >> >>>
> >> >>> If it needs reworking I'll do it; I'm likely to be sending a few soon
> >> >>> and I want them to be minimal effort for you.
> >> >>
> >> >> Is there some reason we don't just use stdlib.h everywhere?  That was
> >> >> defined back in ANSI C 1989--surely we can assume it's available now.
> >> >
> >> > I had considered that first, but I didn't want to be too radical as a
> >> > new arrival.
> >> >
> >> > Chris
> >>
> >> Right, forget the moderate, here's the radical (but trivial) patch....
> >>
> >> http://www.bayofrum.net/~chris/patch-appletlib-c_malloc_to_stdlib
> >>
> >> Would that be OK?
> >
> > Not really.
> >
> > --- a/libbb/appletlib.c
> > +++ b/libbb/appletlib.c
> > @@ -28,7 +28,7 @@
> >  */
> >  #include "busybox.h"
> >  #include <assert.h>
> > -#include <malloc.h>
> > +#include <stdlib.h>
> >
> > (1) as a result, M_TRIM_THRESHOLD is no longer visible even on systems
> > which do have it.
> > (2) stdlib.h is included by busybox.h, no need to include it again.
> >
> >
> > --- a/shell/hush.c
> > +++ b/shell/hush.c
> > @@ -82,7 +82,11 @@
> >  *              aaa
> >  */
> >  #include "busybox.h"  /* for APPLET_IS_NOFORK/NOEXEC */
> > -#include <malloc.h>   /* for malloc_trim */
> > +#ifdef M_TRIM_THRESHOLD
> > +# include <malloc.h>   /* for malloc_trim */
> > +#else
> > +# include <stdlib.h>
> > +#endif
> >
> > as a result, M_TRIM_THRESHOLD is no longer visible even on systems
> > which do have it.
> >
> > I think a better patch would be to frame #include <malloc.h>
> > in #ifndef <system which is known to not have malloc.h>
> >
> 
> You're absolutely right, I misguidedly thought M_TRIM_THRESHOLD was a
> busybox config item.
> 
> Improved patch here:
> 
> http://www.bayofrum.net/~chris/patch-malloc-h-portability
> 
> That OK?

(1) #if condition is wrong, should be:

#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
        || defined(__APPLE__) \
    )


(2) appletlib.c lost mallopt tweaking, since you didn't add #if there.

Fixed that and applied to git:

http://git.busybox.net/busybox/commit/?id=8da415ef2503936bc9730f78a25b00177ff2db1d

-- 
vda


More information about the busybox mailing list