clang format files under port/ (#10849)

Summary:
Run "clang-format" against files under port to make it happy.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10849

Test Plan: Watch existing CI to pass.

Reviewed By: anand1976

Differential Revision: D40645839

fbshipit-source-id: 582b4215503223795cf6234af90cc4e8e4eba773
main
sdong 2 years ago committed by Facebook GitHub Bot
parent 4d9cb433fa
commit 7cf27eae0a
  1. 4
      port/lang.h
  2. 4
      port/port_dirent.h
  3. 47
      port/port_posix.cc
  4. 9
      port/port_posix.h
  5. 2
      port/stack_trace.cc
  6. 2
      port/sys_time.h
  7. 3
      port/win/io_win.h
  8. 16
      port/win/port_win.h
  9. 1
      port/win/win_jemalloc.cc
  10. 6
      port/win/win_logger.cc
  11. 3
      port/win/win_logger.h
  12. 47
      port/win/win_thread.cc
  13. 2
      port/win/win_thread.h
  14. 69
      port/win/xpress_win.cc
  15. 4
      port/win/xpress_win.h

@ -11,7 +11,9 @@
#elif defined(__GNUC__) && __GNUC__ >= 7 #elif defined(__GNUC__) && __GNUC__ >= 7
#define FALLTHROUGH_INTENDED [[gnu::fallthrough]] #define FALLTHROUGH_INTENDED [[gnu::fallthrough]]
#else #else
#define FALLTHROUGH_INTENDED do {} while (0) #define FALLTHROUGH_INTENDED \
do { \
} while (0)
#endif #endif
#endif #endif

@ -33,11 +33,11 @@ int closedir(DIR* dirp);
} // namespace port } // namespace port
using port::dirent; using port::closedir;
using port::DIR; using port::DIR;
using port::dirent;
using port::opendir; using port::opendir;
using port::readdir; using port::readdir;
using port::closedir;
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -64,12 +64,10 @@ Mutex::Mutex(bool adaptive) {
} else { } else {
pthread_mutexattr_t mutex_attr; pthread_mutexattr_t mutex_attr;
PthreadCall("init mutex attr", pthread_mutexattr_init(&mutex_attr)); PthreadCall("init mutex attr", pthread_mutexattr_init(&mutex_attr));
PthreadCall("set mutex attr", PthreadCall("set mutex attr", pthread_mutexattr_settype(
pthread_mutexattr_settype(&mutex_attr, &mutex_attr, PTHREAD_MUTEX_ADAPTIVE_NP));
PTHREAD_MUTEX_ADAPTIVE_NP));
PthreadCall("init mutex", pthread_mutex_init(&mu_, &mutex_attr)); PthreadCall("init mutex", pthread_mutex_init(&mu_, &mutex_attr));
PthreadCall("destroy mutex attr", PthreadCall("destroy mutex attr", pthread_mutexattr_destroy(&mutex_attr));
pthread_mutexattr_destroy(&mutex_attr));
} }
#else #else
PthreadCall("init mutex", pthread_mutex_init(&mu_, nullptr)); PthreadCall("init mutex", pthread_mutex_init(&mu_, nullptr));
@ -108,8 +106,7 @@ void Mutex::AssertHeld() {
#endif #endif
} }
CondVar::CondVar(Mutex* mu) CondVar::CondVar(Mutex* mu) : mu_(mu) {
: mu_(mu) {
PthreadCall("init cv", pthread_cond_init(&cv_, nullptr)); PthreadCall("init cv", pthread_cond_init(&cv_, nullptr));
} }
@ -146,9 +143,7 @@ bool CondVar::TimedWait(uint64_t abs_time_us) {
return false; return false;
} }
void CondVar::Signal() { void CondVar::Signal() { PthreadCall("signal", pthread_cond_signal(&cv_)); }
PthreadCall("signal", pthread_cond_signal(&cv_));
}
void CondVar::SignalAll() { void CondVar::SignalAll() {
PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
@ -158,28 +153,40 @@ RWMutex::RWMutex() {
PthreadCall("init mutex", pthread_rwlock_init(&mu_, nullptr)); PthreadCall("init mutex", pthread_rwlock_init(&mu_, nullptr));
} }
RWMutex::~RWMutex() { PthreadCall("destroy mutex", pthread_rwlock_destroy(&mu_)); } RWMutex::~RWMutex() {
PthreadCall("destroy mutex", pthread_rwlock_destroy(&mu_));
}
void RWMutex::ReadLock() { PthreadCall("read lock", pthread_rwlock_rdlock(&mu_)); } void RWMutex::ReadLock() {
PthreadCall("read lock", pthread_rwlock_rdlock(&mu_));
}
void RWMutex::WriteLock() { PthreadCall("write lock", pthread_rwlock_wrlock(&mu_)); } void RWMutex::WriteLock() {
PthreadCall("write lock", pthread_rwlock_wrlock(&mu_));
}
void RWMutex::ReadUnlock() { PthreadCall("read unlock", pthread_rwlock_unlock(&mu_)); } void RWMutex::ReadUnlock() {
PthreadCall("read unlock", pthread_rwlock_unlock(&mu_));
}
void RWMutex::WriteUnlock() { PthreadCall("write unlock", pthread_rwlock_unlock(&mu_)); } void RWMutex::WriteUnlock() {
PthreadCall("write unlock", pthread_rwlock_unlock(&mu_));
}
int PhysicalCoreID() { int PhysicalCoreID() {
#if defined(ROCKSDB_SCHED_GETCPU_PRESENT) && defined(__x86_64__) && \ #if defined(ROCKSDB_SCHED_GETCPU_PRESENT) && defined(__x86_64__) && \
(__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 22)) (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 22))
// sched_getcpu uses VDSO getcpu() syscall since 2.22. I believe Linux offers VDSO // sched_getcpu uses VDSO getcpu() syscall since 2.22. I believe Linux offers
// support only on x86_64. This is the fastest/preferred method if available. // VDSO support only on x86_64. This is the fastest/preferred method if
// available.
int cpuno = sched_getcpu(); int cpuno = sched_getcpu();
if (cpuno < 0) { if (cpuno < 0) {
return -1; return -1;
} }
return cpuno; return cpuno;
#elif defined(__x86_64__) || defined(__i386__) #elif defined(__x86_64__) || defined(__i386__)
// clang/gcc both provide cpuid.h, which defines __get_cpuid(), for x86_64 and i386. // clang/gcc both provide cpuid.h, which defines __get_cpuid(), for x86_64 and
// i386.
unsigned eax, ebx = 0, ecx, edx; unsigned eax, ebx = 0, ecx, edx;
if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx)) { if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
return -1; return -1;
@ -229,9 +236,7 @@ void *cacheline_aligned_alloc(size_t size) {
#endif #endif
} }
void cacheline_aligned_free(void *memblock) { void cacheline_aligned_free(void* memblock) { free(memblock); }
free(memblock);
}
static size_t GetPageSize() { static size_t GetPageSize() {
#if defined(OS_LINUX) || defined(_SC_PAGESIZE) #if defined(OS_LINUX) || defined(_SC_PAGESIZE)

@ -39,8 +39,8 @@
#endif #endif
#include <alloca.h> #include <alloca.h>
#elif defined(OS_AIX) #elif defined(OS_AIX)
#include <sys/types.h>
#include <arpa/nameser_compat.h> #include <arpa/nameser_compat.h>
#include <sys/types.h>
#define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN) #define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN)
#include <alloca.h> #include <alloca.h>
#elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \ #elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \
@ -52,9 +52,9 @@
#include <endian.h> #include <endian.h>
#endif #endif
#include <pthread.h> #include <pthread.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <limits> #include <limits>
#include <string> #include <string>
@ -71,8 +71,8 @@
#define fflush_unlocked fflush #define fflush_unlocked fflush
#endif #endif
#if defined(OS_MACOSX) || defined(OS_FREEBSD) ||\ #if defined(OS_MACOSX) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || \
defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) defined(OS_DRAGONFLYBSD)
// Use fsync() on platforms without fdatasync() // Use fsync() on platforms without fdatasync()
#define fdatasync fsync #define fdatasync fsync
#endif #endif
@ -154,6 +154,7 @@ class CondVar {
bool TimedWait(uint64_t abs_time_us); bool TimedWait(uint64_t abs_time_us);
void Signal(); void Signal();
void SignalAll(); void SignalAll();
private: private:
pthread_cond_t cv_; pthread_cond_t cv_;
Mutex* mu_; Mutex* mu_;

@ -24,13 +24,13 @@ void* SaveStack(int* /*num_frames*/, int /*first_frames_to_skip*/) {
#else #else
#include <cxxabi.h>
#include <execinfo.h> #include <execinfo.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <cxxabi.h>
#if defined(OS_FREEBSD) #if defined(OS_FREEBSD)
#include <sys/sysctl.h> #include <sys/sysctl.h>

@ -39,8 +39,8 @@ inline struct tm* LocalTimeR(const time_t* timep, struct tm* result) {
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE
#else #else
#include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h>
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

@ -40,8 +40,7 @@ inline IOStatus IOError(const std::string& context, int err_number) {
return (err_number == ENOSPC) return (err_number == ENOSPC)
? IOStatus::NoSpace(context, errnoStr(err_number).c_str()) ? IOStatus::NoSpace(context, errnoStr(err_number).c_str())
: (err_number == ENOENT) : (err_number == ENOENT)
? IOStatus::PathNotFound(context, ? IOStatus::PathNotFound(context, errnoStr(err_number).c_str())
errnoStr(err_number).c_str())
: IOStatus::IOError(context, errnoStr(err_number).c_str()); : IOStatus::IOError(context, errnoStr(err_number).c_str());
} }

@ -38,7 +38,6 @@
#undef DeleteFile #undef DeleteFile
#undef GetCurrentTime #undef GetCurrentTime
#ifndef strcasecmp #ifndef strcasecmp
#define strcasecmp _stricmp #define strcasecmp _stricmp
#endif #endif
@ -133,12 +132,9 @@ class Mutex {
void operator=(const Mutex&) = delete; void operator=(const Mutex&) = delete;
private: private:
friend class CondVar; friend class CondVar;
std::mutex& getLock() { std::mutex& getLock() { return mutex_; }
return mutex_;
}
std::mutex mutex_; std::mutex mutex_;
#ifndef NDEBUG #ifndef NDEBUG
@ -170,8 +166,7 @@ class RWMutex {
class CondVar { class CondVar {
public: public:
explicit CondVar(Mutex* mu) : mu_(mu) { explicit CondVar(Mutex* mu) : mu_(mu) {}
}
~CondVar(); ~CondVar();
void Wait(); void Wait();
@ -191,7 +186,6 @@ class CondVar {
Mutex* mu_; Mutex* mu_;
}; };
#ifdef _POSIX_THREADS #ifdef _POSIX_THREADS
using Thread = std::thread; using Thread = std::thread;
#else #else
@ -204,7 +198,6 @@ using Thread = WindowsThread;
// Posix semantics with initialization // Posix semantics with initialization
// adopted in the project // adopted in the project
struct OnceType { struct OnceType {
struct Init {}; struct Init {};
OnceType() {} OnceType() {}
@ -322,7 +315,6 @@ bool GenerateRfcUuid(std::string* output);
} // namespace port } // namespace port
#ifdef ROCKSDB_WINDOWS_UTF8_FILENAMES #ifdef ROCKSDB_WINDOWS_UTF8_FILENAMES
#define RX_FILESTRING std::wstring #define RX_FILESTRING std::wstring
@ -376,11 +368,11 @@ bool GenerateRfcUuid(std::string* output);
#endif #endif
using port::pthread_key_t; using port::pthread_getspecific;
using port::pthread_key_create; using port::pthread_key_create;
using port::pthread_key_delete; using port::pthread_key_delete;
using port::pthread_key_t;
using port::pthread_setspecific; using port::pthread_setspecific;
using port::pthread_getspecific;
using port::truncate; using port::truncate;
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -14,6 +14,7 @@
#endif #endif
#include <stdexcept> #include <stdexcept>
#include "jemalloc/jemalloc.h" #include "jemalloc/jemalloc.h"
#include "port/win/port_win.h" #include "port/win/port_win.h"

@ -57,9 +57,7 @@ void WinLogger::DebugWriter(const char* str, int len) {
WinLogger::~WinLogger() { CloseInternal().PermitUncheckedError(); } WinLogger::~WinLogger() { CloseInternal().PermitUncheckedError(); }
Status WinLogger::CloseImpl() { Status WinLogger::CloseImpl() { return CloseInternal(); }
return CloseInternal();
}
Status WinLogger::CloseInternal() { Status WinLogger::CloseInternal() {
Status s; Status s;
@ -187,7 +185,7 @@ void WinLogger::Logv(const char* format, va_list ap) {
size_t WinLogger::GetLogFileSize() const { return log_size_; } size_t WinLogger::GetLogFileSize() const { return log_size_; }
} } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -45,7 +45,6 @@ class WinLogger : public ROCKSDB_NAMESPACE::Logger {
void DebugWriter(const char* str, int len); void DebugWriter(const char* str, int len);
protected: protected:
Status CloseImpl() override; Status CloseImpl() override;
private: private:
@ -60,6 +59,6 @@ protected:
const static uint64_t flush_every_seconds_ = 5; const static uint64_t flush_every_seconds_ = 5;
}; };
} } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -28,14 +28,10 @@ namespace ROCKSDB_NAMESPACE {
namespace port { namespace port {
struct WindowsThread::Data { struct WindowsThread::Data {
std::function<void()> func_; std::function<void()> func_;
uintptr_t handle_; uintptr_t handle_;
Data(std::function<void()>&& func) : Data(std::function<void()>&& func) : func_(std::move(func)), handle_(0) {}
func_(std::move(func)),
handle_(0) {
}
Data(const Data&) = delete; Data(const Data&) = delete;
Data& operator=(const Data&) = delete; Data& operator=(const Data&) = delete;
@ -43,36 +39,30 @@ struct WindowsThread::Data {
static unsigned int __stdcall ThreadProc(void* arg); static unsigned int __stdcall ThreadProc(void* arg);
}; };
void WindowsThread::Init(std::function<void()>&& func) { void WindowsThread::Init(std::function<void()>&& func) {
data_ = std::make_shared<Data>(std::move(func)); data_ = std::make_shared<Data>(std::move(func));
// We create another instance of std::shared_ptr to get an additional ref // We create another instance of std::shared_ptr to get an additional ref
// since we may detach and destroy this instance before the threadproc // since we may detach and destroy this instance before the threadproc
// may start to run. We choose to allocate this additional ref on the heap // may start to run. We choose to allocate this additional ref on the heap
// so we do not need to synchronize and allow this thread to proceed // so we do not need to synchronize and allow this thread to proceed
std::unique_ptr<std::shared_ptr<Data>> th_data(new std::shared_ptr<Data>(data_)); std::unique_ptr<std::shared_ptr<Data>> th_data(
new std::shared_ptr<Data>(data_));
data_->handle_ = _beginthreadex(NULL, data_->handle_ = _beginthreadex(NULL,
0, // stack size 0, // stack size
&Data::ThreadProc, &Data::ThreadProc, th_data.get(),
th_data.get(),
0, // init flag 0, // init flag
&th_id_); &th_id_);
if (data_->handle_ == 0) { if (data_->handle_ == 0) {
throw std::system_error(std::make_error_code( throw std::system_error(
std::errc::resource_unavailable_try_again), std::make_error_code(std::errc::resource_unavailable_try_again),
"Unable to create a thread"); "Unable to create a thread");
} }
th_data.release(); th_data.release();
} }
WindowsThread::WindowsThread() : WindowsThread::WindowsThread() : data_(nullptr), th_id_(0) {}
data_(nullptr),
th_id_(0)
{}
WindowsThread::~WindowsThread() { WindowsThread::~WindowsThread() {
// Must be joined or detached // Must be joined or detached
@ -87,13 +77,11 @@ WindowsThread::~WindowsThread() {
} }
} }
WindowsThread::WindowsThread(WindowsThread&& o) noexcept : WindowsThread::WindowsThread(WindowsThread&& o) noexcept : WindowsThread() {
WindowsThread() {
*this = std::move(o); *this = std::move(o);
} }
WindowsThread& WindowsThread::operator=(WindowsThread&& o) noexcept { WindowsThread& WindowsThread::operator=(WindowsThread&& o) noexcept {
if (joinable()) { if (joinable()) {
assert(false); assert(false);
std::terminate(); std::terminate();
@ -107,9 +95,7 @@ WindowsThread& WindowsThread::operator=(WindowsThread&& o) noexcept {
return *this; return *this;
} }
bool WindowsThread::joinable() const { bool WindowsThread::joinable() const { return (data_ && data_->handle_ != 0); }
return (data_ && data_->handle_ != 0);
}
WindowsThread::native_handle_type WindowsThread::native_handle() const { WindowsThread::native_handle_type WindowsThread::native_handle() const {
return reinterpret_cast<native_handle_type>(data_->handle_); return reinterpret_cast<native_handle_type>(data_->handle_);
@ -120,11 +106,9 @@ unsigned WindowsThread::hardware_concurrency() {
} }
void WindowsThread::join() { void WindowsThread::join() {
if (!joinable()) { if (!joinable()) {
assert(false); assert(false);
throw std::system_error( throw std::system_error(std::make_error_code(std::errc::invalid_argument),
std::make_error_code(std::errc::invalid_argument),
"Thread is no longer joinable"); "Thread is no longer joinable");
} }
@ -135,13 +119,12 @@ void WindowsThread::join() {
"Can not join itself"); "Can not join itself");
} }
auto ret = WaitForSingleObject(reinterpret_cast<HANDLE>(data_->handle_), auto ret =
INFINITE); WaitForSingleObject(reinterpret_cast<HANDLE>(data_->handle_), INFINITE);
if (ret != WAIT_OBJECT_0) { if (ret != WAIT_OBJECT_0) {
auto lastError = GetLastError(); auto lastError = GetLastError();
assert(false); assert(false);
throw std::system_error(static_cast<int>(lastError), throw std::system_error(static_cast<int>(lastError), std::system_category(),
std::system_category(),
"WaitForSingleObjectFailed: thread join"); "WaitForSingleObjectFailed: thread join");
} }
@ -157,11 +140,9 @@ void WindowsThread::join() {
} }
bool WindowsThread::detach() { bool WindowsThread::detach() {
if (!joinable()) { if (!joinable()) {
assert(false); assert(false);
throw std::system_error( throw std::system_error(std::make_error_code(std::errc::invalid_argument),
std::make_error_code(std::errc::invalid_argument),
"Thread is no longer available"); "Thread is no longer available");
} }

@ -11,8 +11,8 @@
#ifndef _POSIX_THREADS #ifndef _POSIX_THREADS
#include <memory>
#include <functional> #include <functional>
#include <memory>
#include <type_traits> #include <type_traits>
#include "rocksdb/rocksdb_namespace.h" #include "rocksdb/rocksdb_namespace.h"

@ -10,12 +10,13 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "port/win/xpress_win.h" #include "port/win/xpress_win.h"
#include <windows.h> #include <windows.h>
#include <cassert> #include <cassert>
#include <memory>
#include <limits>
#include <iostream> #include <iostream>
#include <limits>
#include <memory>
#ifdef XPRESS #ifdef XPRESS
@ -41,10 +42,9 @@ auto CloseDecompressorFun = [](void* h) {
::CloseDecompressor(reinterpret_cast<DECOMPRESSOR_HANDLE>(h)); ::CloseDecompressor(reinterpret_cast<DECOMPRESSOR_HANDLE>(h));
} }
}; };
} } // namespace
bool Compress(const char* input, size_t length, std::string* output) { bool Compress(const char* input, size_t length, std::string* output) {
assert(input != nullptr); assert(input != nullptr);
assert(output != nullptr); assert(output != nullptr);
@ -57,27 +57,26 @@ bool Compress(const char* input, size_t length, std::string* output) {
COMPRESSOR_HANDLE compressor = NULL; COMPRESSOR_HANDLE compressor = NULL;
BOOL success = CreateCompressor( BOOL success =
COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm CreateCompressor(COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm
allocRoutinesPtr, // Optional allocation routine allocRoutinesPtr, // Optional allocation routine
&compressor); // Handle &compressor); // Handle
if (!success) { if (!success) {
#ifdef _DEBUG #ifdef _DEBUG
std::cerr << "XPRESS: Failed to create Compressor LastError: " << std::cerr << "XPRESS: Failed to create Compressor LastError: "
GetLastError() << std::endl; << GetLastError() << std::endl;
#endif #endif
return false; return false;
} }
std::unique_ptr<void, decltype(CloseCompressorFun)> std::unique_ptr<void, decltype(CloseCompressorFun)> compressorGuard(
compressorGuard(compressor, CloseCompressorFun); compressor, CloseCompressorFun);
SIZE_T compressedBufferSize = 0; SIZE_T compressedBufferSize = 0;
// Query compressed buffer size. // Query compressed buffer size.
success = ::Compress( success = ::Compress(compressor, // Compressor Handle
compressor, // Compressor Handle
const_cast<char*>(input), // Input buffer const_cast<char*>(input), // Input buffer
length, // Uncompressed data size length, // Uncompressed data size
NULL, // Compressed Buffer NULL, // Compressed Buffer
@ -85,14 +84,13 @@ bool Compress(const char* input, size_t length, std::string* output) {
&compressedBufferSize); // Compressed Data size &compressedBufferSize); // Compressed Data size
if (!success) { if (!success) {
auto lastError = GetLastError(); auto lastError = GetLastError();
if (lastError != ERROR_INSUFFICIENT_BUFFER) { if (lastError != ERROR_INSUFFICIENT_BUFFER) {
#ifdef _DEBUG #ifdef _DEBUG
std::cerr << std::cerr
"XPRESS: Failed to estimate compressed buffer size LastError " << << "XPRESS: Failed to estimate compressed buffer size LastError "
lastError << std::endl; << lastError << std::endl;
#endif #endif
return false; return false;
} }
@ -106,8 +104,7 @@ bool Compress(const char* input, size_t length, std::string* output) {
SIZE_T compressedDataSize = 0; SIZE_T compressedDataSize = 0;
// Compress // Compress
success = ::Compress( success = ::Compress(compressor, // Compressor Handle
compressor, // Compressor Handle
const_cast<char*>(input), // Input buffer const_cast<char*>(input), // Input buffer
length, // Uncompressed data size length, // Uncompressed data size
&result[0], // Compressed Buffer &result[0], // Compressed Buffer
@ -116,8 +113,8 @@ bool Compress(const char* input, size_t length, std::string* output) {
if (!success) { if (!success) {
#ifdef _DEBUG #ifdef _DEBUG
std::cerr << "XPRESS: Failed to compress LastError " << std::cerr << "XPRESS: Failed to compress LastError " << GetLastError()
GetLastError() << std::endl; << std::endl;
#endif #endif
return false; return false;
} }
@ -141,12 +138,11 @@ char* Decompress(const char* input_data, size_t input_length,
DECOMPRESSOR_HANDLE decompressor = NULL; DECOMPRESSOR_HANDLE decompressor = NULL;
BOOL success = CreateDecompressor( BOOL success =
COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm CreateDecompressor(COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm
allocRoutinesPtr, // Optional allocation routine allocRoutinesPtr, // Optional allocation routine
&decompressor); // Handle &decompressor); // Handle
if (!success) { if (!success) {
#ifdef _DEBUG #ifdef _DEBUG
std::cerr << "XPRESS: Failed to create Decompressor LastError " std::cerr << "XPRESS: Failed to create Decompressor LastError "
@ -155,13 +151,12 @@ char* Decompress(const char* input_data, size_t input_length,
return nullptr; return nullptr;
} }
std::unique_ptr<void, decltype(CloseDecompressorFun)> std::unique_ptr<void, decltype(CloseDecompressorFun)> compressorGuard(
compressorGuard(decompressor, CloseDecompressorFun); decompressor, CloseDecompressorFun);
SIZE_T decompressedBufferSize = 0; SIZE_T decompressedBufferSize = 0;
success = ::Decompress( success = ::Decompress(decompressor, // Compressor Handle
decompressor, // Compressor Handle
const_cast<char*>(input_data), // Compressed data const_cast<char*>(input_data), // Compressed data
input_length, // Compressed data size input_length, // Compressed data size
NULL, // Buffer set to NULL NULL, // Buffer set to NULL
@ -169,7 +164,6 @@ char* Decompress(const char* input_data, size_t input_length,
&decompressedBufferSize); // Decompressed Data size &decompressedBufferSize); // Decompressed Data size
if (!success) { if (!success) {
auto lastError = GetLastError(); auto lastError = GetLastError();
if (lastError != ERROR_INSUFFICIENT_BUFFER) { if (lastError != ERROR_INSUFFICIENT_BUFFER) {
@ -190,19 +184,14 @@ char* Decompress(const char* input_data, size_t input_length,
SIZE_T decompressedDataSize = 0; SIZE_T decompressedDataSize = 0;
success = ::Decompress( success = ::Decompress(decompressor, const_cast<char*>(input_data),
decompressor, input_length, outputBuffer.get(),
const_cast<char*>(input_data), decompressedBufferSize, &decompressedDataSize);
input_length,
outputBuffer.get(),
decompressedBufferSize,
&decompressedDataSize);
if (!success) { if (!success) {
#ifdef _DEBUG #ifdef _DEBUG
std::cerr << std::cerr << "XPRESS: Failed to decompress LastError " << GetLastError()
"XPRESS: Failed to decompress LastError " << << std::endl;
GetLastError() << std::endl;
#endif #endif
return nullptr; return nullptr;
} }
@ -212,8 +201,8 @@ char* Decompress(const char* input_data, size_t input_length,
// Return the raw buffer to the caller supporting the tradition // Return the raw buffer to the caller supporting the tradition
return outputBuffer.release(); return outputBuffer.release();
} }
} } // namespace xpress
} } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE
#endif #endif

@ -21,6 +21,6 @@ bool Compress(const char* input, size_t length, std::string* output);
char* Decompress(const char* input_data, size_t input_length, char* Decompress(const char* input_data, size_t input_length,
size_t* uncompressed_size); size_t* uncompressed_size);
} } // namespace xpress
} } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

Loading…
Cancel
Save