mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-04 14:29:39 +00:00
Renamed mem_realloc() to mem_trim() to prevent confusion with realloc()
This commit is contained in:
parent
8336796c1a
commit
52970c2459
@ -131,6 +131,10 @@ HISTORY
|
||||
|
||||
++ Bugfixes:
|
||||
|
||||
2010-02-19: Simon Goldschmidt
|
||||
* mem.c/.h, pbuf.c: Renamed mem_realloc() to mem_trim() to prevent
|
||||
confusion with realloc()
|
||||
|
||||
2010-02-15: Simon Goldschmidt/Stephane Lesage
|
||||
* netif.c/.h: Link status does not depend on LWIP_NETIF_LINK_CALLBACK
|
||||
(fixes bug #28899)
|
||||
|
@ -224,7 +224,7 @@ static volatile u8_t mem_free_count;
|
||||
* one empty struct mem pointing to another empty struct mem.
|
||||
*
|
||||
* @param mem this points to a struct mem which just has been freed
|
||||
* @internal this function is only called by mem_free() and mem_realloc()
|
||||
* @internal this function is only called by mem_free() and mem_trim()
|
||||
*
|
||||
* This assumes access to the heap is protected by the calling function
|
||||
* already.
|
||||
@ -353,9 +353,7 @@ mem_free(void *rmem)
|
||||
}
|
||||
|
||||
/**
|
||||
* In contrast to its name, mem_realloc can only shrink memory, not expand it.
|
||||
* Since the only use (for now) is in pbuf_realloc (which also can only shrink),
|
||||
* this shouldn't be a problem!
|
||||
* Shrink memory returned by mem_malloc().
|
||||
*
|
||||
* @param rmem pointer to memory allocated by mem_malloc the is to be shrinked
|
||||
* @param newsize required size after shrinking (needs to be smaller than or
|
||||
@ -365,7 +363,7 @@ mem_free(void *rmem)
|
||||
* or freed!
|
||||
*/
|
||||
void *
|
||||
mem_realloc(void *rmem, mem_size_t newsize)
|
||||
mem_trim(void *rmem, mem_size_t newsize)
|
||||
{
|
||||
mem_size_t size;
|
||||
mem_size_t ptr, ptr2;
|
||||
@ -386,12 +384,12 @@ mem_realloc(void *rmem, mem_size_t newsize)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LWIP_ASSERT("mem_realloc: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
|
||||
LWIP_ASSERT("mem_trim: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
|
||||
(u8_t *)rmem < (u8_t *)ram_end);
|
||||
|
||||
if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
|
||||
SYS_ARCH_DECL_PROTECT(lev);
|
||||
LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_realloc: illegal memory\n"));
|
||||
LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_trim: illegal memory\n"));
|
||||
/* protect mem stats from concurrent access */
|
||||
SYS_ARCH_PROTECT(lev);
|
||||
MEM_STATS_INC(illegal);
|
||||
@ -404,7 +402,7 @@ mem_realloc(void *rmem, mem_size_t newsize)
|
||||
ptr = (mem_size_t)((u8_t *)mem - ram);
|
||||
|
||||
size = mem->next - ptr - SIZEOF_STRUCT_MEM;
|
||||
LWIP_ASSERT("mem_realloc can only shrink memory", newsize <= size);
|
||||
LWIP_ASSERT("mem_trim can only shrink memory", newsize <= size);
|
||||
if (newsize > size) {
|
||||
/* not supported */
|
||||
return NULL;
|
||||
|
@ -383,8 +383,8 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
|
||||
/* (other types merely adjust their length fields */
|
||||
if ((q->type == PBUF_RAM) && (rem_len != q->len)) {
|
||||
/* reallocate and adjust the length of the pbuf that will be split */
|
||||
q = (struct pbuf *)mem_realloc(q, (u16_t)((u8_t *)q->payload - (u8_t *)q) + rem_len);
|
||||
LWIP_ASSERT("mem_realloc give q == NULL", q != NULL);
|
||||
q = (struct pbuf *)mem_trim(q, (u16_t)((u8_t *)q->payload - (u8_t *)q) + rem_len);
|
||||
LWIP_ASSERT("mem_trim returned q == NULL", q != NULL);
|
||||
}
|
||||
/* adjust length fields for new last pbuf */
|
||||
q->len = rem_len;
|
||||
|
@ -58,10 +58,10 @@ typedef size_t mem_size_t;
|
||||
#ifndef mem_calloc
|
||||
#define mem_calloc calloc
|
||||
#endif
|
||||
/* ATTENTION: using realloc is currently not supported since the return value
|
||||
is ignored, so don't define mem_realloc() to realloc()! */
|
||||
#ifndef mem_realloc
|
||||
#define mem_realloc(mem, size) (mem)
|
||||
/* Since there is no C library allocation function to shrink memory without
|
||||
moving it, define this to nothing. */
|
||||
#ifndef mem_trim
|
||||
#define mem_trim(mem, size) (mem)
|
||||
#endif
|
||||
#else /* MEM_LIBC_MALLOC */
|
||||
|
||||
@ -77,13 +77,13 @@ typedef u16_t mem_size_t;
|
||||
#if MEM_USE_POOLS
|
||||
/** mem_init is not used when using pools instead of a heap */
|
||||
#define mem_init()
|
||||
/** mem_realloc is not used when using pools instead of a heap:
|
||||
/** mem_trim is not used when using pools instead of a heap:
|
||||
we can't free part of a pool element and don't want to copy the rest */
|
||||
#define mem_realloc(mem, size) (mem)
|
||||
#define mem_trim(mem, size) (mem)
|
||||
#else /* MEM_USE_POOLS */
|
||||
/* lwIP alternative malloc */
|
||||
void mem_init(void);
|
||||
void *mem_realloc(void *mem, mem_size_t size);
|
||||
void *mem_trim(void *mem, mem_size_t size);
|
||||
#endif /* MEM_USE_POOLS */
|
||||
void *mem_malloc(mem_size_t size);
|
||||
void *mem_calloc(mem_size_t count, mem_size_t size);
|
||||
|
@ -25,7 +25,7 @@ mem_teardown(void)
|
||||
|
||||
/* Test functions */
|
||||
|
||||
/** Call mem_malloc, mem_free and mem_realloc and check stats */
|
||||
/** Call mem_malloc, mem_free and mem_trim and check stats */
|
||||
START_TEST(test_mem_one)
|
||||
{
|
||||
#define SIZE1 16
|
||||
@ -51,7 +51,7 @@ START_TEST(test_mem_one)
|
||||
fail_unless(lwip_stats.mem.used >= SIZE2 + s1);
|
||||
s2 = lwip_stats.mem.used;
|
||||
|
||||
mem_realloc(p1, SIZE1_2);
|
||||
mem_trim(p1, SIZE1_2);
|
||||
|
||||
mem_free(p2);
|
||||
fail_unless(lwip_stats.mem.used <= s2 - SIZE2);
|
||||
|
Loading…
Reference in New Issue
Block a user