Skip to content

Commit

Permalink
Add XXH_NAMESPACE, for namespace emulation in C
Browse files Browse the repository at this point in the history
  • Loading branch information
Éric Lemoine committed May 23, 2017
1 parent ef3723a commit 95426a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utilities/roslz4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions utilities/roslz4/src/xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


//****************************
Expand Down

0 comments on commit 95426a1

Please sign in to comment.