Răsfoiți Sursa

test mimalloc

Update cmake_build.py

Update CMakeLists.txt

Update CMakeLists.txt
blueloveTH 8 luni în urmă
părinte
comite
152d6bbd49
6 a modificat fișierele cu 10 adăugiri și 5 ștergeri
  1. 1 0
      .gitignore
  2. 4 1
      CMakeLists.txt
  3. 1 1
      cmake_build.py
  4. 1 0
      include/pocketpy/common/utils.h
  5. 1 1
      include/pocketpy/config.h
  6. 2 2
      src2/main.c

+ 1 - 0
.gitignore

@@ -40,3 +40,4 @@ docs/C-API/functions.md
 
 
 cmake-build-*
+tmp/

+ 4 - 1
CMakeLists.txt

@@ -86,10 +86,13 @@ if(PK_ENABLE_MIMALLOC)
     )
 
     set(MI_OVERRIDE OFF CACHE BOOL "" FORCE)
+    set(MI_NO_USE_CXX ON CACHE BOOL "" FORCE)
     set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE)
+    set(MI_BUILD_OBJECT OFF CACHE BOOL "" FORCE)
     set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE)
     set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE)
     FetchContent_MakeAvailable(mimalloc)
+    include_directories(${mimalloc_SOURCE_DIR}/include)
 
     add_definitions(-DPK_ENABLE_MIMALLOC=1)
 else()
@@ -173,5 +176,5 @@ if(PK_BUILD_MODULE_LIBHV)
 endif()
 
 if(PK_ENABLE_MIMALLOC)
-    target_link_libraries(${PROJECT_NAME} mimalloc::mimalloc)
+    target_link_libraries(${PROJECT_NAME} mimalloc-static)
 endif()

+ 1 - 1
cmake_build.py

@@ -20,7 +20,7 @@ assert config in ['Debug', 'Release', 'RelWithDebInfo']
 
 os.chdir("build")
 
-code = os.system(f"cmake .. -DPK_ENABLE_DETERMINISM=ON -DCMAKE_BUILD_TYPE={config} {extra_flags}")
+code = os.system(f"cmake .. -DPK_ENABLE_MIMALLOC=ON -DPK_ENABLE_DETERMINISM=ON -DCMAKE_BUILD_TYPE={config} {extra_flags}")
 assert code == 0
 code = os.system(f"cmake --build . --config {config} -j 4")
 assert code == 0

+ 1 - 0
include/pocketpy/common/utils.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <assert.h>
 
 #define PK_REGION(name) 1

+ 1 - 1
include/pocketpy/config.h

@@ -85,7 +85,7 @@
 // Memory allocation functions
 #ifndef PK_MALLOC
     #if PK_ENABLE_MIMALLOC
-        #include <mimalloc.h>
+        #include "mimalloc.h"
         #define PK_MALLOC(size)                 mi_malloc(size)
         #define PK_REALLOC(ptr, size)           mi_realloc(ptr, size)
         #define PK_FREE(ptr)                    mi_free(ptr)

+ 2 - 2
src2/main.c

@@ -19,7 +19,7 @@ static char* read_file(const char* path) {
     fseek(file, 0, SEEK_END);
     long size = ftell(file);
     fseek(file, 0, SEEK_SET);
-    char* buffer = malloc(size + 1);
+    char* buffer = PK_MALLOC(size + 1);
     size = fread(buffer, 1, size, file);
     buffer[size] = 0;
     return buffer;
@@ -84,7 +84,7 @@ int main(int argc, char** argv) {
         char* source = read_file(filename);
         if(source) {
             if(!py_exec(source, filename, EXEC_MODE, NULL)) py_printexc();
-            free(source);
+            PK_FREE(source);
         }
     }