[haiku-bugs] [Haiku] #12132: Implement malloc_usable_size()

  • From: "korli" <trac@xxxxxxxxxxxx>
  • Date: Mon, 08 Jun 2015 10:41:33 -0000

#12132: Implement malloc_usable_size()
--------------------------+------------------------------
Reporter: korli | Owner: nobody
Type: bug | Status: new
Priority: normal | Milestone: Unscheduled
Component: System/POSIX | Version: R1/Development
Keywords: | Blocked By:
Blocking: | Has a Patch: 0
Platform: All |
--------------------------+------------------------------
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



}}}

--
Ticket URL: <https://dev.haiku-os.org/ticket/12132>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: