Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
backport changes made to ccommon in pelikan (twitter#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yao Yue authored May 8, 2019
1 parent a4c0334 commit dea5bee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
25 changes: 12 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,15 @@ endif(COVERAGE)
include(FindPackageHandleStandardArgs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")

find_package(Check)
find_package(PkgConfig QUIET)

if(PKG_CONFIG_FOUND)
pkg_check_modules(CHECK QUIET check>=0.10)
endif()

if(NOT CHECK_FOUND)
message(WARNING "Check is required to build and run tests")
endif(NOT CHECK_FOUND)
if(CHECK_FOUND)
check_symbol_exists(ck_assert_int_eq check.h CHECK_WORKING)
if(NOT CHECK_WORKING)
message(WARNING "Check version too old to build tests")
endif(NOT CHECK_WORKING)
endif(CHECK_FOUND)
find_package(Check QUIET 0.10)
endif()

find_package(Threads)

Expand All @@ -166,10 +165,10 @@ include_directories(

add_subdirectory(src)

if(CHECK_WORKING)
include_directories(${include_directories} "${CHECK_INCLUDES}")
if(CHECK_FOUND)
include_directories(${include_directories} ${CHECK_INCLUDES})
add_subdirectory(test)
endif(CHECK_WORKING)
endif(CHECK_FOUND)


if(HAVE_RUST)
Expand All @@ -193,4 +192,4 @@ message(STATUS "HAVE_SIGNAME: " ${HAVE_SIGNAME})

message(STATUS "HAVE_BACKTRACE: " ${HAVE_BACKTRACE})

message(STATUS "CHECK_WORKING: " ${CHECK_WORKING})
message(STATUS "CHECK_FOUND: " ${CHECK_FOUND})
4 changes: 4 additions & 0 deletions include/cc_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ extern "C" {
#define cc_munmap(_p, _s) \
_cc_munmap(_p, (size_t)(_s), __FILE__, __LINE__)

#define cc_alloc_usable_size(_p) \
_cc_alloc_usable_size(_p, __FILE__, __LINE__)

void * _cc_alloc(size_t size, const char *name, int line);
void * _cc_zalloc(size_t size, const char *name, int line);
void * _cc_calloc(size_t nmemb, size_t size, const char *name, int line);
Expand All @@ -74,6 +77,7 @@ void * _cc_realloc_move(void *ptr, size_t size, const char *name, int line);
void _cc_free(void *ptr, const char *name, int line);
void * _cc_mmap(size_t size, const char *name, int line);
int _cc_munmap(void *p, size_t size, const char *name, int line);
size_t _cc_alloc_usable_size(void *ptr, const char *name, int line);

#ifdef __cplusplus
}
Expand Down
11 changes: 11 additions & 0 deletions src/cc_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
/* TODO(yao): detect OS in one place and use one variable everywhere */
#if defined(__APPLE__) && defined(__MACH__)
# define MAP_ANONYMOUS MAP_ANON
#include <malloc/malloc.h>
#define malloc_usable_size malloc_size
#else
#include <malloc.h>
#endif

void *
Expand Down Expand Up @@ -167,3 +171,10 @@ _cc_munmap(void *p, size_t size, const char *name, int line)

return status;
}

size_t
_cc_alloc_usable_size(void *ptr, const char *name, int line)
{
log_vverb("malloc_usable_size(%p) @ %s:%d", ptr, name, line);
return malloc_usable_size(ptr);
}

0 comments on commit dea5bee

Please sign in to comment.