Dozingfiretruck 2 лет назад
Родитель
Сommit
b151010a72
2 измененных файлов с 16 добавлено и 18 удалено
  1. 16 2
      luat/weak/luat_malloc_weak.c
  2. 0 16
      luat/weak/luat_mem_weak.c

+ 16 - 2
luat/weak/luat_malloc_weak.c

@@ -4,9 +4,12 @@
 
 #include <stdlib.h>
 #include <string.h>//add for memset
-#include "bget.h"
 #include "luat_malloc.h"
 
+#ifdef __LUATOS__
+#include "bget.h"
+#endif
+
 #define LUAT_LOG_TAG "vmheap"
 #include "luat_log.h"
 
@@ -14,6 +17,7 @@
 
 //------------------------------------------------
 //  管理系统内存
+LUAT_WEAK void luat_heap_init(void){}
 
 LUAT_WEAK void* luat_heap_malloc(size_t len) {
     return malloc(len);
@@ -34,10 +38,20 @@ LUAT_WEAK void* luat_heap_calloc(size_t count, size_t _size) {
     }
     return ptr;
 }
+
+LUAT_WEAK void* luat_heap_zalloc(size_t _size) {
+    void *ptr = luat_heap_malloc(_size);
+    if (ptr) {
+        memset(ptr, 0, _size);
+    }
+    return ptr;
+}
+
 //------------------------------------------------
 
 //------------------------------------------------
 // ---------- 管理 LuaVM所使用的内存----------------
+#ifdef __LUATOS__
 LUAT_WEAK void* luat_heap_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
     if (0) {
         if (ptr) {
@@ -81,5 +95,5 @@ LUAT_WEAK void luat_meminfo_luavm(size_t *total, size_t *used, size_t *max_used)
 	*max_used = bstatsmaxget();
     *total = curalloc + totfree;
 }
-
+#endif
 //-----------------------------------------------------------------------------

+ 0 - 16
luat/modules/luat_lib_mem.c → luat/weak/luat_mem_weak.c

@@ -37,21 +37,5 @@ LUAT_WEAK void luat_meminfo_opt_sys(LUAT_HEAP_TYPE_E type,size_t* total, size_t*
     luat_meminfo_sys(total, used, max_used);
 }
 
-LUAT_WEAK void luat_heap_init(void){}
 
-LUAT_WEAK void* luat_heap_calloc(size_t count, size_t _size) {
-    void *ptr = luat_heap_malloc(count * _size);
-    if (ptr) {
-        memset(ptr, 0, count * _size);
-    }
-    return ptr;
-}
-
-LUAT_WEAK void* luat_heap_zalloc(size_t _size) {
-    void *ptr = luat_heap_malloc(_size);
-    if (ptr) {
-        memset(ptr, 0, _size);
-    }
-    return ptr;
-}