You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/11/13 18:28:50 UTC

[GitHub] ccollins476ad closed pull request #1518: libc/baselibc: syscfg for stubbing out malloc/free

ccollins476ad closed pull request #1518: libc/baselibc: syscfg for stubbing out malloc/free
URL: https://github.com/apache/mynewt-core/pull/1518
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/libc/baselibc/src/malloc.c b/libc/baselibc/src/malloc.c
index 2bf45515d4..cef8bc9a04 100644
--- a/libc/baselibc/src/malloc.c
+++ b/libc/baselibc/src/malloc.c
@@ -10,6 +10,15 @@
 #include <stdint.h>
 #include "malloc.h"
 
+#include "os/mynewt.h"
+
+#if MYNEWT_VAL(BASELIBC_MALLOC_STUB)
+
+void *malloc(size_t size) { return NULL; }
+void free(void *ptr) { }
+
+#else
+
 /* Both the arena list and the free memory list are double linked
    list with head node.  This the head node. Note that the arena list
    is sorted in order of address. */
@@ -274,3 +283,4 @@ void set_malloc_locking(malloc_lock_t lock, malloc_unlock_t unlock)
     else
         malloc_unlock = &malloc_unlock_nop;
 }
+#endif /* MYNEWT_VAL(BASELIBC_MALLOC_STUB) */
diff --git a/libc/baselibc/syscfg.yml b/libc/baselibc/syscfg.yml
index 7f6dc3cbbf..2496122dec 100644
--- a/libc/baselibc/syscfg.yml
+++ b/libc/baselibc/syscfg.yml
@@ -22,6 +22,13 @@ syscfg.defs:
         description: "Indicates that baselibc is the libc implementation."
         value: 1
 
+    BASELIBC_MALLOC_STUB:
+        description: >
+            Replaces baselibc's implementations of `malloc()` and `free()` with
+            no-op stubs.  Useful for reducing code size in builds that do not
+            use dynamically allocated memory.
+        value: 0
+
     BASELIBC_ASSERT_FILE_LINE:
         defunct: 1
         description: 'Use OS_CRASH_FILE_LINE instead'


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services