mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-11-09 07:02:06 +01:00
fixed some more small things
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#define __MINIMAL_HEAP_H__
|
||||
|
||||
#define MIHP_VERSION_MAJOR 1
|
||||
#define MIHP_VERSION_MINOR 13
|
||||
#define MIHP_VERSION_MINOR 14
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -18,6 +18,10 @@
|
||||
#endif
|
||||
/* */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uintptr_t MIHP_HeapOpaque;
|
||||
|
||||
typedef void*(MIHP_PlatformRequestMemoryFn)(MIHP_HeapOpaque heap, size_t minRequestedSize, size_t* outActualSize);
|
||||
@@ -213,4 +217,8 @@ size_t MIHP_GetMaximalPayloadSize(const MIHP_Heap* heap);
|
||||
#include "minimal_heap_implementation.inl"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -405,10 +405,14 @@ MIHP_HeapError MIHP_SetPointerCustomMetadata(MIHP_Heap* heap, void* ptr, MIHP_Al
|
||||
if (!MIHP_IsAddressInHeap(heap, ptr))
|
||||
return MIHP_HE_InvalidHeap;
|
||||
|
||||
MIHP_LockHeap(heap);
|
||||
|
||||
MIHP_HeapSegmentHeader* segment = MIHP_GetHeapSegmentHeaderPtr(heap, ptr);
|
||||
MIHP_ValidateHeapSegmentHeader(heap, segment);
|
||||
segment->CustomMetadata = metadata;
|
||||
segment->Checksum = MIHP_GenerateHeapSegmentChecksum(heap, segment);
|
||||
|
||||
MIHP_UnlockHeap(heap);
|
||||
return MIHP_HE_Success;
|
||||
}
|
||||
|
||||
@@ -420,14 +424,22 @@ MIHP_HeapError MIHP_GetPointerCustomMetadata(MIHP_Heap* heap, void* ptr, MIHP_Al
|
||||
if (!MIHP_IsAddressInHeap(heap, ptr))
|
||||
return MIHP_HE_InvalidHeap;
|
||||
|
||||
MIHP_LockHeap(heap);
|
||||
|
||||
MIHP_HeapSegmentHeader* segment = MIHP_GetHeapSegmentHeaderPtr(heap, ptr);
|
||||
MIHP_ValidateHeapSegmentHeader(heap, segment);
|
||||
*outMetadata = segment->CustomMetadata;
|
||||
|
||||
MIHP_UnlockHeap(heap);
|
||||
|
||||
return MIHP_HE_Success;
|
||||
}
|
||||
|
||||
MIHP_HeapError MIHP_MergeHeaps(MIHP_Heap* sourceHeap, MIHP_Heap* heapToAbsorb)
|
||||
{
|
||||
if (sourceHeap == heapToAbsorb)
|
||||
return MIHP_HE_InvalidParameter;
|
||||
|
||||
if (!MIHP_IsHeapInitialized(sourceHeap))
|
||||
return MIHP_HE_InvalidHeap;
|
||||
|
||||
@@ -500,7 +512,7 @@ bool MIHP_IsAddressInHeap(MIHP_Heap* heap, void* ptr)
|
||||
uintptr_t ptrMin = (uintptr_t)currentArea;
|
||||
uintptr_t ptrMax = (uintptr_t)currentArea + currentArea->AreaSize;
|
||||
|
||||
if (searchingPtr >= ptrMin && searchingPtr <= ptrMax)
|
||||
if (searchingPtr >= ptrMin && searchingPtr < ptrMax)
|
||||
{
|
||||
MIHP_UnlockHeap(heap);
|
||||
return true;
|
||||
@@ -568,6 +580,8 @@ MIHP_HeapError MIHP_WalkHeap(MIHP_Heap* heap, MIHP_WalkHeapCallbackFn* callback)
|
||||
if (callback == NULL)
|
||||
return MIHP_HE_InvalidParameter;
|
||||
|
||||
MIHP_LockHeap(heap);
|
||||
|
||||
MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea;
|
||||
while (nextArea != NULL)
|
||||
{
|
||||
@@ -586,6 +600,8 @@ MIHP_HeapError MIHP_WalkHeap(MIHP_Heap* heap, MIHP_WalkHeapCallbackFn* callback)
|
||||
}
|
||||
}
|
||||
|
||||
MIHP_UnlockHeap(heap);
|
||||
|
||||
return MIHP_HE_Success;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user