From 8cf096699b1d490e9686489f44ff19c48e7dfa6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 23 May 2017 18:23:47 +0200 Subject: [PATCH] Add XXH_NAMESPACE, for namespace emulation in C --- utilities/roslz4/CMakeLists.txt | 4 ++-- utilities/roslz4/src/xxhash.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/utilities/roslz4/CMakeLists.txt b/utilities/roslz4/CMakeLists.txt index 68f65f7846..2cae56bde5 100644 --- a/utilities/roslz4/CMakeLists.txt +++ b/utilities/roslz4/CMakeLists.txt @@ -29,8 +29,8 @@ catkin_package( include_directories(include ${lz4_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) add_library(roslz4 src/lz4s.c src/xxhash.c) set_source_files_properties( - src/lz4s.c -PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") + src/lz4s.c src/xxhash.c +PROPERTIES COMPILE_FLAGS "-Wno-sign-compare" COMPILE_DEFINITIONS "XXH_NAMESPACE=ROSLZ4_") target_link_libraries(roslz4 ${lz4_LIBRARIES} ${catkin_LIBRARIES}) if(NOT ANDROID) diff --git a/utilities/roslz4/src/xxhash.h b/utilities/roslz4/src/xxhash.h index a319bcc9b3..3560bf2f69 100644 --- a/utilities/roslz4/src/xxhash.h +++ b/utilities/roslz4/src/xxhash.h @@ -69,6 +69,28 @@ extern "C" { //**************************** typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; +/*!XXH_NAMESPACE, aka Namespace Emulation : + +If you want to include _and expose_ xxHash functions from within your own library, +but also want to avoid symbol collisions with other libraries which may also include xxHash, + +you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library +with the value of XXH_NAMESPACE (therefore, avoid NULL and numeric values). + +Note that no change is required within the calling program as long as it includes `xxhash.h` : +regular symbol name will be automatically translated by this header. +*/ +#ifdef XXH_NAMESPACE +# define XXH_CAT(A,B) A##B +# define XXH_NAME2(A,B) XXH_CAT(A,B) +# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32) +# define XXH32_sizeofState XXH_NAME2(XXH_NAMESPACE, XXH32_sizeofState) +# define XXH32_resetState XXH_NAME2(XXH_NAMESPACE, XXH32_resetState) +# define XXH32_init XXH_NAME2(XXH_NAMESPACE, XXH32_init) +# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update) +# define XXH32_intermediateDigest XXH_NAME2(XXH_NAMESPACE, XXH32_intermediateDigest) +# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest) +#endif //****************************