Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e28b2255c | |||
| b2f834b7cd |
+4
-3
@@ -10,7 +10,7 @@ set(libucore_VERSION ${libucore_VERSION_MAJOR}.${libucore_VERSION_MINOR}.${libuc
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wundef -Wcast-qual -Wshadow -Wcast-align -pipe -Wno-unused-parameter -Werror=implicit-function-declaration -Winit-self")
|
||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2")
|
||||
@@ -30,13 +30,14 @@ if (CODE_COVERAGE)
|
||||
set(build_type "${build_type}-coverage")
|
||||
endif()
|
||||
|
||||
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
|
||||
option(BUILD_SANITIZE "build with address sanitizer" OFF)
|
||||
if (BUILD_SANITIZE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||
set(build_type "${build_type}-sanitize")
|
||||
endif()
|
||||
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(CHECK REQUIRED IMPORTED_TARGET check)
|
||||
include_directories(include)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
@@ -25,9 +25,9 @@ extern "C" {
|
||||
*/
|
||||
typedef struct UCSArena UCSArena;
|
||||
struct UCSArena {
|
||||
char *start; // start of user buffer
|
||||
char *curr; // next alloc point
|
||||
char *end; // one past end of user buffer
|
||||
unsigned char *start; // start of user buffer
|
||||
unsigned char *curr; // next alloc point
|
||||
unsigned char *end; // one past end of user buffer
|
||||
};
|
||||
|
||||
/** Initialize a UCSArena with predefined backing array.
|
||||
|
||||
@@ -26,42 +26,3 @@ void uc_slot_free(UCSlotAlloc *restrict sa, void *restrict slot)
|
||||
assert((size_t)slot_index < sa->num_slots);
|
||||
uc_bv_clr_bit(&sa->bitmap, slot_index);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
UC_SLOT_ALLOC_DEF(sa, 24, 1)
|
||||
|
||||
void *p1 = uc_slot_alloc(&sa);
|
||||
printf("%p\n", &sa_memory.memory[0]);
|
||||
printf("%p\n", p1);
|
||||
|
||||
void *p2 = uc_slot_alloc(&sa);
|
||||
printf("%p\n", p2);
|
||||
uc_slot_free(&sa, p1);
|
||||
|
||||
p2 = uc_slot_alloc(&sa);
|
||||
printf("%p\n", p2);
|
||||
|
||||
printf("__malloc__\n");
|
||||
void *v = malloc(24 * (1<<16));
|
||||
UC_SLOT_ALLOC_DEF_EX(sa2, 24, (1<<16), v)
|
||||
char *v2 = NULL;
|
||||
for (int i = 0; i < 1<<16; i++) {
|
||||
char *c = uc_slot_alloc(&sa2);
|
||||
if (c == NULL) {
|
||||
printf("uc_slot_alloc failed at %d\n", i);
|
||||
break;
|
||||
}
|
||||
*c = i;
|
||||
if (i == 0) {
|
||||
v2 = c;
|
||||
}
|
||||
}
|
||||
for (int i = (1<<16) -1 ; i >= 0; i--) {
|
||||
uc_slot_free(&sa2, v2 + 24*i);
|
||||
}
|
||||
free(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
file(GLOB TEST_SOURCE_FILES test_*.c)
|
||||
|
||||
link_libraries(check ucore Threads::Threads)
|
||||
link_libraries(ucore Threads::Threads PkgConfig::CHECK)
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
include_directories("/opt/homebrew/include")
|
||||
link_directories("/opt/homebrew/lib")
|
||||
|
||||
Reference in New Issue
Block a user