Fix warnings when building for msp430-elf
The MSP430 target supports both 16-bit and 20-bit size_t and intptr_t. Some implicit casts in Newlib expect these types to be "long", (a 32-bit type on MSP430) which causes warnings during compilation such as: "cast from pointer to integer of different size"
This commit is contained in:
parent
a634adda5a
commit
754386c7f5
|
@ -11,6 +11,9 @@
|
|||
Red Hat, Inc.
|
||||
*/
|
||||
|
||||
int write (int fd, const char *buf, int len);
|
||||
void abort (void);
|
||||
|
||||
char *
|
||||
_sbrk (int adj)
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#endif
|
||||
|
||||
/* 16 bit integer machines */
|
||||
#if defined(__Z8001__) || defined(__Z8002__) || defined(__H8500__) || defined(__W65__) || defined (__mn10200__) || defined (__AVR__)
|
||||
#if defined(__Z8001__) || defined(__Z8002__) || defined(__H8500__) || defined(__W65__) || defined (__mn10200__) || defined (__AVR__) || defined (__MSP430__)
|
||||
|
||||
#undef INT_MAX
|
||||
#undef UINT_MAX
|
||||
|
@ -162,7 +162,7 @@
|
|||
#define __SMALL_BITFIELDS
|
||||
|
||||
#ifdef __MSP430X_LARGE__
|
||||
#define _POINTER_INT long
|
||||
#define _POINTER_INT __int20
|
||||
#else
|
||||
#define _POINTER_INT int
|
||||
#endif
|
||||
|
|
|
@ -125,7 +125,7 @@ typedef struct {
|
|||
int lorder; /* byte order */
|
||||
} BTREEINFO;
|
||||
|
||||
#define HASHMAGIC 0x061561
|
||||
#define HASHMAGIC 0x061561L
|
||||
#define HASHVERSION 2
|
||||
|
||||
/* Structure used to pass parameters to the hashing routines. */
|
||||
|
|
|
@ -72,7 +72,12 @@ SLIST_HEAD(internal_head, internal_entry);
|
|||
* max * sizeof internal_entry must fit into size_t.
|
||||
* assumes internal_entry is <= 32 (2^5) bytes.
|
||||
*/
|
||||
#ifdef __MSP430X_LARGE__
|
||||
/* 20-bit size_t. */
|
||||
#define MAX_BUCKETS_LG2 (20 - 1 - 5)
|
||||
#else
|
||||
#define MAX_BUCKETS_LG2 (sizeof (size_t) * 8 - 1 - 5)
|
||||
#endif
|
||||
#define MAX_BUCKETS ((size_t)1 << MAX_BUCKETS_LG2)
|
||||
|
||||
/* Default hash function, from db/hash/hash_func.c */
|
||||
|
|
|
@ -326,8 +326,8 @@ internal_open_memstream_r (struct _reent *ptr,
|
|||
if (c->max < 64)
|
||||
c->max = 64;
|
||||
#if (SIZE_MAX >= 64 * 1024)
|
||||
else if (c->max > 64 * 1024)
|
||||
c->max = 64 * 1024;
|
||||
else if (c->max > (size_t)64 * 1024)
|
||||
c->max = (size_t)64 * 1024;
|
||||
#endif
|
||||
*size = 0;
|
||||
*buf = _malloc_r (ptr, c->max);
|
||||
|
|
|
@ -99,7 +99,8 @@ _rs_stir(void)
|
|||
rs->rs_have = 0;
|
||||
memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
|
||||
|
||||
rs->rs_count = (SIZE_MAX <= 65535) ? 65000 : 1600000;
|
||||
rs->rs_count = (SIZE_MAX <= 65535) ? 65000
|
||||
: (SIZE_MAX <= 1048575 ? 1048000 : 1600000);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
|
@ -106,8 +106,10 @@
|
|||
#define sbrk_start __malloc_sbrk_start
|
||||
#define current_mallinfo __malloc_current_mallinfo
|
||||
|
||||
#define ALIGN_TO(size, align) \
|
||||
(((size) + (align) -1L) & ~((align) -1L))
|
||||
#define ALIGN_PTR(ptr, align) \
|
||||
(((ptr) + (align) - (intptr_t)1) & ~((align) - (intptr_t)1))
|
||||
#define ALIGN_SIZE(size, align) \
|
||||
(((size) + (align) - (size_t)1) & ~((align) - (size_t)1))
|
||||
|
||||
/* Alignment of allocated block */
|
||||
#define MALLOC_ALIGN (8U)
|
||||
|
@ -214,7 +216,7 @@ static void* sbrk_aligned(RARG malloc_size_t s)
|
|||
if (p == (void *)-1)
|
||||
return p;
|
||||
|
||||
align_p = (char*)ALIGN_TO((unsigned long)p, CHUNK_ALIGN);
|
||||
align_p = (char*)ALIGN_PTR((uintptr_t)p, CHUNK_ALIGN);
|
||||
if (align_p != p)
|
||||
{
|
||||
/* p is not aligned, ask for a few more bytes so that we have s
|
||||
|
@ -239,7 +241,7 @@ void * nano_malloc(RARG malloc_size_t s)
|
|||
|
||||
malloc_size_t alloc_size;
|
||||
|
||||
alloc_size = ALIGN_TO(s, CHUNK_ALIGN); /* size of aligned data load */
|
||||
alloc_size = ALIGN_SIZE(s, CHUNK_ALIGN); /* size of aligned data load */
|
||||
alloc_size += MALLOC_PADDING; /* padding */
|
||||
alloc_size += CHUNK_OFFSET; /* size of chunk head */
|
||||
alloc_size = MAX(alloc_size, MALLOC_MINCHUNK);
|
||||
|
@ -305,7 +307,7 @@ void * nano_malloc(RARG malloc_size_t s)
|
|||
|
||||
ptr = (char *)r + CHUNK_OFFSET;
|
||||
|
||||
align_ptr = (char *)ALIGN_TO((unsigned long)ptr, MALLOC_ALIGN);
|
||||
align_ptr = (char *)ALIGN_PTR((uintptr_t)ptr, MALLOC_ALIGN);
|
||||
offset = align_ptr - ptr;
|
||||
|
||||
if (offset)
|
||||
|
@ -578,16 +580,16 @@ void * nano_memalign(RARG size_t align, size_t s)
|
|||
if ((align & (align-1)) != 0) return NULL;
|
||||
|
||||
align = MAX(align, MALLOC_ALIGN);
|
||||
ma_size = ALIGN_TO(MAX(s, MALLOC_MINSIZE), CHUNK_ALIGN);
|
||||
ma_size = ALIGN_SIZE(MAX(s, MALLOC_MINSIZE), CHUNK_ALIGN);
|
||||
size_with_padding = ma_size + align - MALLOC_ALIGN;
|
||||
|
||||
allocated = nano_malloc(RCALL size_with_padding);
|
||||
if (allocated == NULL) return NULL;
|
||||
|
||||
chunk_p = get_chunk_from_ptr(allocated);
|
||||
aligned_p = (char *)ALIGN_TO(
|
||||
(unsigned long)((char *)chunk_p + CHUNK_OFFSET),
|
||||
(unsigned long)align);
|
||||
aligned_p = (char *)ALIGN_PTR(
|
||||
(uintptr_t)((char *)chunk_p + CHUNK_OFFSET),
|
||||
(uintptr_t)align);
|
||||
offset = aligned_p - ((char *)chunk_p + CHUNK_OFFSET);
|
||||
|
||||
if (offset)
|
||||
|
@ -642,6 +644,6 @@ void * nano_valloc(RARG size_t s)
|
|||
#ifdef DEFINE_PVALLOC
|
||||
void * nano_pvalloc(RARG size_t s)
|
||||
{
|
||||
return nano_valloc(RCALL ALIGN_TO(s, MALLOC_PAGE_ALIGN));
|
||||
return nano_valloc(RCALL ALIGN_SIZE(s, MALLOC_PAGE_ALIGN));
|
||||
}
|
||||
#endif /* DEFINE_PVALLOC */
|
||||
|
|
Loading…
Reference in New Issue