From 65135ac96161eaa236b37ca2f3ace64345bbba66 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 20 Apr 2024 11:22:09 +0200 Subject: [PATCH] created why2_allocated fn checks for why2-mem allocation --- include/memory.h | 4 ++++ src/core/lib/utils/memory.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/include/memory.h b/include/memory.h index 1c146d7..5a2902c 100644 --- a/include/memory.h +++ b/include/memory.h @@ -23,6 +23,8 @@ along with this program. If not, see . extern "C" { #endif +#include + void *why2_malloc(unsigned long size); void *why2_calloc(unsigned long element, unsigned long size); void *why2_realloc(void *pointer, unsigned long size); @@ -37,6 +39,8 @@ void why2_deallocate(void *pointer); void why2_clean_memory(char *identifier); //identifier SPECIFIES WHICH NODES TO DEALLOCATE | THIS IS BASICALLY GARBAGE COLLECTOR | PASS why2_get_default_memory_identifier() FOR DEALLOCATING EVERYTHING +why2_bool why2_allocated(void *pointer); //CHECKS IF pointer WAS ALLOCATED USING WHY2-MEM + #ifdef __cplusplus } #endif diff --git a/src/core/lib/utils/memory.c b/src/core/lib/utils/memory.c index 946d006..e766566 100644 --- a/src/core/lib/utils/memory.c +++ b/src/core/lib/utils/memory.c @@ -240,4 +240,9 @@ void why2_clean_memory(char *identifier) if (buffer -> identifier == identifier || force_deallocating) why2_deallocate(buffer -> pointer); //LAST NODE why2_reset_memory_identifier(); //THIS WILL CAUSE SEGFAULT IF YOU DIDN'T USE why2_set_memory_identifier +} + +why2_bool why2_allocated(void *pointer) +{ + return get_node(pointer) != NULL; } \ No newline at end of file