This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Rework malloc's long_sub_size_t
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: newlib at sources dot redhat dot com
- Date: 10 Oct 2002 10:20:41 +0100
- Subject: Rework malloc's long_sub_size_t
This patch replaces the mallocr.c definition of long_sub_size_t()
with one that uses sizeof. The current definition depends on
SIZE_T_SMALLER_THAN_LONG, but it can be difficult to get
SIZE_T_SMALLER_THAN_LONG right for every MIPS ABI.
As far as I can tell, there are no type problems in using
sizeof. And since the sizeof computation is a compile-time
constant, I don't see it's any less efficient than the current
definition.
Tested on mips64-elf, no regressions. Also tested on a version
of GNUPro with EABI32 -mlong64 multilibs (where sizeof (size_t)
is 4 and sizeof (long) is 8). OK to install?
Richard
[Based on a patch by Graham Stott]
* libc/stdlib/mallocr.c (long_sub_size_t): Define in a way that
doesn't require the SIZE_T_SMALLER_THAN_LONG macro.
Index: libc/stdlib/mallocr.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mallocr.c,v
retrieving revision 1.8
diff -c -d -p -r1.8 mallocr.c
*** libc/stdlib/mallocr.c 20 Aug 2002 15:29:30 -0000 1.8
--- libc/stdlib/mallocr.c 9 Oct 2002 15:36:18 -0000
*************** int _dummy_mallocr = 1;
*** 168,177 ****
MALLOC_ALIGNMENT (default: NOT defined)
Define this to 16 if you need 16 byte alignment instead of 8 byte alignment
which is the normal default.
- SIZE_T_SMALLER_THAN_LONG (default: NOT defined)
- Define this when the platform you are compiling has sizeof(long) > sizeof(size_t).
- The option causes some extra code to be generated to handle operations
- that use size_t operands and have long results.
REALLOC_ZERO_BYTES_FREES (default: NOT defined)
Define this if you think that realloc(p, 0) should be equivalent
to free(p). Otherwise, since malloc returns a unique pointer for
--- 168,173 ----
*************** extern void __malloc_unlock();
*** 448,458 ****
fact that assignment from unsigned to signed won't sign extend.
*/
! #ifdef SIZE_T_SMALLER_THAN_LONG
! #define long_sub_size_t(x, y) ( (x < y) ? -((long)(y - x)) : (x - y) );
! #else
! #define long_sub_size_t(x, y) ( (long)(x - y) )
! #endif
/*
REALLOC_ZERO_BYTES_FREES should be set if a call to
--- 444,453 ----
fact that assignment from unsigned to signed won't sign extend.
*/
! #define long_sub_size_t(x, y) \
! (sizeof (long) > sizeof (INTERNAL_SIZE_T) && x < y \
! ? -(long) (y - x) \
! : (long) (x - y))
/*
REALLOC_ZERO_BYTES_FREES should be set if a call to