Merge pull request #3 from dgarske/realloc

Implementation of `pvPortRealloc`.
pull/5/head
John Safranek 2019-12-16 11:35:58 -08:00 committed by GitHub
commit 659d06ecf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View File

@ -308,6 +308,33 @@ BlockLink_t *pxLink;
}
/*-----------------------------------------------------------*/
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
if(pv)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - xHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= (xHeapStructSize + HEAP_CHECK_SIZE);
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
vPortFree(pv);
}
}
}
else {
pvReturn = pvPortMalloc(xWantedSize);
}
return pvReturn;
}
/*-----------------------------------------------------------*/
size_t xPortGetFreeHeapSize( void )
{
return xFreeBytesRemaining;

View File

@ -317,6 +317,33 @@ BlockLink_t *pxLink;
}
/*-----------------------------------------------------------*/
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
if(pv)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - uxHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= (uxHeapStructSize + HEAP_CHECK_SIZE);
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
vPortFree(pv);
}
}
}
else {
pvReturn = pvPortMalloc(xWantedSize);
}
return pvReturn;
}
/*-----------------------------------------------------------*/
size_t xPortGetFreeHeapSize( void )
{
return xFreeBytesRemaining;