Opened 9 years ago

Closed 9 years ago

#12132 closed bug (fixed)

Implement malloc_usable_size()

Reported by: korli Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: System/POSIX Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

Blender requires the following GNU POSIX extension, also provided by FreeBSD: size_t malloc_usable_size(void *ptr);

http://linux.die.net/man/3/malloc_usable_size

This is a request for comments.

diff --git a/headers/posix/malloc.h b/headers/posix/malloc.h
index b36b17d..7754038 100644
--- a/headers/posix/malloc.h
+++ b/headers/posix/malloc.h
@@ -20,6 +20,10 @@ extern void free(void *pointer);
 extern void *memalign(size_t alignment, size_t numBytes);
 extern void *valloc(size_t numBytes);
 
+#ifdef _GNU_SOURCE
+size_t malloc_usable_size(void *ptr);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/system/libroot/posix/malloc/wrapper.cpp b/src/system/libroot/posix/malloc/wrapper.cpp
index 5b5e066..c83336a 100644
--- a/src/system/libroot/posix/malloc/wrapper.cpp
+++ b/src/system/libroot/posix/malloc/wrapper.cpp
@@ -490,6 +490,15 @@ realloc(void *ptr, size_t size)
 }
 
 
+extern "C" size_t
+malloc_usable_size(void *ptr)
+{
+       if (ptr == NULL)
+               return 0;
+       return threadHeap::objectSize(ptr);
+}
+
+
 //     #pragma mark - BeOS specific extensions
 
 

Change History (1)

comment:1 by korli, 9 years ago

Resolution: fixed
Status: newclosed

Applied in hrev49286

Note: See TracTickets for help on using tickets.