test mimalloc

Update cmake_build.py

Update CMakeLists.txt

Update CMakeLists.txt
This commit is contained in:
blueloveTH 2025-07-01 15:34:26 +08:00
parent 7d484f8fa3
commit 152d6bbd49
6 changed files with 10 additions and 5 deletions

1
.gitignore vendored
View File

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

View File

@ -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()

View File

@ -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

View File

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

View File

@ -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)

View File

@ -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);
}
}