Skip to content

Commit

Permalink
Adding Snappy. Workaround for check_library_exists() not working and …
Browse files Browse the repository at this point in the history
…conditional defines in port_stdcxx.h now working.
  • Loading branch information
YabMek433 committed Jul 11, 2023
1 parent f16014b commit 521032c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
check_library_exists(zstd zstd_compress "" HAVE_ZSTD)
check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)

#remove when check_library_exits starts working
set(HAVE_SNAPPY ON)

include(CheckCXXSymbolExists)
# Using check_cxx_symbol_exists() instead of check_c_symbol_exists() because
# we're including the header from C++, and feature detection should use the same
Expand Down Expand Up @@ -284,7 +287,7 @@ endif(HAVE_TCMALLOC)

# Needed by port_stdcxx.h
find_package(Threads REQUIRED)
target_link_libraries(leveldb PUBLIC Threads::Threads zlibstaticleveldb)
target_link_libraries(leveldb Threads::Threads zlibstaticleveldb)

add_executable(leveldbutil
"db/leveldbutil.cc"
Expand Down
21 changes: 12 additions & 9 deletions port/port_stdcxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#if HAVE_CRC32C
#include <crc32c/crc32c.h>
#endif // HAVE_CRC32C
#if HAVE_SNAPPY
//#if HAVE_SNAPPY
#include <snappy.h>
#endif // HAVE_SNAPPY
//#endif // HAVE_SNAPPY
#if HAVE_ZSTD
#define ZSTD_STATIC_LINKING_ONLY // For ZSTD_compressionParameters.
#include <zstd.h>
Expand Down Expand Up @@ -90,45 +90,48 @@ class CondVar {

inline bool Snappy_Compress(const char* input, size_t length,
std::string* output) {
#if HAVE_SNAPPY
//#if HAVE_SNAPPY
output->resize(snappy::MaxCompressedLength(length));
size_t outlen;
snappy::RawCompress(input, length, &(*output)[0], &outlen);
output->resize(outlen);
return true;
#else
// Silence compiler warnings about unused arguments.
/*#else
//Silence compiler warnings about unused arguments.
(void)input;
(void)length;
(void)output;
#endif // HAVE_SNAPPY
return false;
*/
}

inline bool Snappy_GetUncompressedLength(const char* input, size_t length,
size_t* result) {
#if HAVE_SNAPPY
//#if HAVE_SNAPPY
return snappy::GetUncompressedLength(input, length, result);
#else
/*#else
// Silence compiler warnings about unused arguments.
(void)input;
(void)length;
(void)result;
return false;
#endif // HAVE_SNAPPY
*/
}

inline bool Snappy_Uncompress(const char* input, size_t length, char* output) {
#if HAVE_SNAPPY
//#if HAVE_SNAPPY
return snappy::RawUncompress(input, length, output);
#else
/*#else
// Silence compiler warnings about unused arguments.
(void)input;
(void)length;
(void)output;
return false;
#endif // HAVE_SNAPPY
*/
}

inline bool Zstd_Compress(int level, const char* input, size_t length,
Expand Down

0 comments on commit 521032c

Please sign in to comment.