Ensure Windows build w/o port/port.h in public headers

- Remove make file defines from public headers and use _WIN32 because it is compiler defined
 - use __GNUC__ and __clang__ to guard non-portable attributes
 - add #include "port/port.h" to some new .cc files.
 - minor changes in CMakeLists to reflect recent changes
main
Dmitri Smirnov 9 years ago
parent 81d072623c
commit d1a457181d
  1. 4
      CMakeLists.txt
  2. 2
      include/rocksdb/c.h
  3. 20
      include/rocksdb/db.h
  4. 26
      include/rocksdb/env.h
  5. 4
      include/rocksdb/iostats_context.h
  6. 2
      include/rocksdb/perf_context.h
  7. 6
      include/rocksdb/utilities/stackable_db.h
  8. 7
      include/rocksdb/utilities/utility_db.h
  9. 2
      include/utilities/pragma_error.h
  10. 13
      port/win/port_win.h
  11. 1
      table/adaptive_table_factory.cc
  12. 4
      util/db_test_util.h
  13. 25
      util/env.cc
  14. 4
      util/iostats_context.cc
  15. 1
      util/manual_compaction_test.cc
  16. 7
      util/perf_context.cc
  17. 2
      utilities/backupable/backupable_db.cc
  18. 6
      utilities/ttl/db_ttl_impl.h

@ -72,6 +72,7 @@ set(SOURCES
db/builder.cc db/builder.cc
db/c.cc db/c.cc
db/column_family.cc db/column_family.cc
db/compacted_db_impl.cc
db/compaction.cc db/compaction.cc
db/compaction_job.cc db/compaction_job.cc
db/compaction_picker.cc db/compaction_picker.cc
@ -202,7 +203,6 @@ set(SOURCES
util/xxhash.cc util/xxhash.cc
utilities/backupable/backupable_db.cc utilities/backupable/backupable_db.cc
utilities/checkpoint/checkpoint.cc utilities/checkpoint/checkpoint.cc
utilities/compacted_db/compacted_db_impl.cc
utilities/document/document_db.cc utilities/document/document_db.cc
utilities/document/json_document.cc utilities/document/json_document.cc
utilities/document/json_document_builder.cc utilities/document/json_document_builder.cc
@ -215,8 +215,8 @@ set(SOURCES
utilities/merge_operators/uint64add.cc utilities/merge_operators/uint64add.cc
utilities/redis/redis_lists.cc utilities/redis/redis_lists.cc
utilities/spatialdb/spatial_db.cc utilities/spatialdb/spatial_db.cc
utilities/transactions/optimistic_transaction_db_impl.cc
utilities/transactions/optimistic_transaction_impl.cc utilities/transactions/optimistic_transaction_impl.cc
utilities/transactions/optimistic_transaction_db_impl.cc
utilities/ttl/db_ttl_impl.cc utilities/ttl/db_ttl_impl.cc
utilities/write_batch_with_index/write_batch_with_index.cc utilities/write_batch_with_index/write_batch_with_index.cc
utilities/write_batch_with_index/write_batch_with_index_internal.cc utilities/write_batch_with_index/write_batch_with_index_internal.cc

@ -46,7 +46,7 @@
#pragma once #pragma once
#ifdef OS_WIN #ifdef _WIN32
#ifdef ROCKSDB_DLL #ifdef ROCKSDB_DLL
#ifdef ROCKSDB_LIBRARY_EXPORTS #ifdef ROCKSDB_LIBRARY_EXPORTS
#define ROCKSDB_LIBRARY_API __declspec(dllexport) #define ROCKSDB_LIBRARY_API __declspec(dllexport)

@ -24,6 +24,12 @@
#include "rocksdb/listener.h" #include "rocksdb/listener.h"
#include "rocksdb/thread_status.h" #include "rocksdb/thread_status.h"
#ifdef _WIN32
// Windows API macro interference
#undef DeleteFile
#endif
namespace rocksdb { namespace rocksdb {
struct Options; struct Options;
@ -431,7 +437,12 @@ class DB {
return CompactRange(options, DefaultColumnFamily(), begin, end); return CompactRange(options, DefaultColumnFamily(), begin, end);
} }
__attribute__((deprecated)) virtual Status #if defined(__GNUC__) || defined(__clang__)
__attribute__((deprecated))
#elif _WIN32
__declspec(deprecated)
#endif
virtual Status
CompactRange(ColumnFamilyHandle* column_family, const Slice* begin, CompactRange(ColumnFamilyHandle* column_family, const Slice* begin,
const Slice* end, bool change_level = false, const Slice* end, bool change_level = false,
int target_level = -1, uint32_t target_path_id = 0) { int target_level = -1, uint32_t target_path_id = 0) {
@ -441,7 +452,12 @@ class DB {
options.target_path_id = target_path_id; options.target_path_id = target_path_id;
return CompactRange(options, column_family, begin, end); return CompactRange(options, column_family, begin, end);
} }
__attribute__((deprecated)) virtual Status #if defined(__GNUC__) || defined(__clang__)
__attribute__((deprecated))
#elif _WIN32
__declspec(deprecated)
#endif
virtual Status
CompactRange(const Slice* begin, const Slice* end, CompactRange(const Slice* begin, const Slice* end,
bool change_level = false, int target_level = -1, bool change_level = false, int target_level = -1,
uint32_t target_path_id = 0) { uint32_t target_path_id = 0) {

@ -26,7 +26,9 @@
#include "rocksdb/status.h" #include "rocksdb/status.h"
#include "rocksdb/thread_status.h" #include "rocksdb/thread_status.h"
#ifdef GetCurrentTime #ifdef _WIN32
// Windows API macro interference
#undef DeleteFile
#undef GetCurrentTime #undef GetCurrentTime
#endif #endif
@ -163,7 +165,6 @@ class Env {
virtual Status GetChildren(const std::string& dir, virtual Status GetChildren(const std::string& dir,
std::vector<std::string>* result) = 0; std::vector<std::string>* result) = 0;
#undef DeleteFile
// Delete the named file. // Delete the named file.
virtual Status DeleteFile(const std::string& fname) = 0; virtual Status DeleteFile(const std::string& fname) = 0;
@ -650,27 +651,8 @@ class Logger {
// and format. Any log with level under the internal log level // and format. Any log with level under the internal log level
// of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be // of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be
// printed. // printed.
virtual void Logv(const InfoLogLevel log_level, const char* format, va_list ap) { virtual void Logv(const InfoLogLevel log_level, const char* format, va_list ap);
static const char* kInfoLogLevelNames[5] = {"DEBUG", "INFO", "WARN",
"ERROR", "FATAL"};
if (log_level < log_level_) {
return;
}
if (log_level == InfoLogLevel::INFO_LEVEL) {
// Doesn't print log level if it is INFO level.
// This is to avoid unexpected performance regression after we add
// the feature of log level. All the logs before we add the feature
// are INFO level. We don't want to add extra costs to those existing
// logging.
Logv(format, ap);
} else {
char new_format[500];
snprintf(new_format, sizeof(new_format) - 1, "[%s] %s",
kInfoLogLevelNames[log_level], format);
Logv(new_format, ap);
}
}
virtual size_t GetLogFileSize() const { return kDoNotSupportGetLogFileSize; } virtual size_t GetLogFileSize() const { return kDoNotSupportGetLogFileSize; }
// Flush to the OS buffers // Flush to the OS buffers
virtual void Flush() {} virtual void Flush() {}

@ -44,7 +44,11 @@ struct IOStatsContext {
}; };
#ifndef IOS_CROSS_COMPILE #ifndef IOS_CROSS_COMPILE
# ifdef _WIN32
extern __declspec(thread) IOStatsContext iostats_context;
# else
extern __thread IOStatsContext iostats_context; extern __thread IOStatsContext iostats_context;
# endif
#endif // IOS_CROSS_COMPILE #endif // IOS_CROSS_COMPILE
} // namespace rocksdb } // namespace rocksdb

@ -87,6 +87,8 @@ struct PerfContext {
#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE) #if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
extern PerfContext perf_context; extern PerfContext perf_context;
#elif _WIN32
extern __declspec(thread) PerfContext perf_context;
#else #else
extern __thread PerfContext perf_context; extern __thread PerfContext perf_context;
#endif #endif

@ -6,6 +6,12 @@
#include <string> #include <string>
#include "rocksdb/db.h" #include "rocksdb/db.h"
#ifdef _WIN32
// Windows API macro interference
#undef DeleteFile
#endif
namespace rocksdb { namespace rocksdb {
// This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d // This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d

@ -19,7 +19,12 @@ class UtilityDB {
// This function is here only for backwards compatibility. Please use the // This function is here only for backwards compatibility. Please use the
// functions defined in DBWithTTl (rocksdb/utilities/db_ttl.h) // functions defined in DBWithTTl (rocksdb/utilities/db_ttl.h)
// (deprecated) // (deprecated)
__attribute__((deprecated)) static Status OpenTtlDB(const Options& options, #if defined(__GNUC__) || defined(__clang__)
__attribute__((deprecated))
#elif _WIN32
__declspec(deprecated)
#endif
static Status OpenTtlDB(const Options& options,
const std::string& name, const std::string& name,
StackableDB** dbptr, StackableDB** dbptr,
int32_t ttl = 0, int32_t ttl = 0,

@ -18,7 +18,7 @@
#define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning x)) #define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning x))
#elif defined(OS_WIN) #elif defined(_WIN32)
// Wrap unportable warning macro // Wrap unportable warning macro
#if defined(_MSC_VER) #if defined(_MSC_VER)

@ -31,6 +31,12 @@
#include "rocksdb/options.h" #include "rocksdb/options.h"
#undef min
#undef max
#undef DeleteFile
#undef GetCurrentTime
#ifndef strcasecmp #ifndef strcasecmp
#define strcasecmp _stricmp #define strcasecmp _stricmp
#endif #endif
@ -40,12 +46,17 @@
#define snprintf _snprintf #define snprintf _snprintf
#endif #endif
#undef GetCurrentTime
#undef DeleteFile
typedef SSIZE_T ssize_t; typedef SSIZE_T ssize_t;
// size_t printf formatting named in the manner of C99 standard formatting // size_t printf formatting named in the manner of C99 standard formatting
// strings such as PRIu64 // strings such as PRIu64
// in fact, we could use that one // in fact, we could use that one
#ifndef ROCKSDB_PRIszt
#define ROCKSDB_PRIszt "Iu" #define ROCKSDB_PRIszt "Iu"
#endif
#define __attribute__(A) #define __attribute__(A)
@ -68,7 +79,9 @@ typedef SSIZE_T ssize_t;
// Thread local storage on Linux // Thread local storage on Linux
// There is thread_local in C++11 // There is thread_local in C++11
#ifndef __thread
#define __thread __declspec(thread) #define __thread __declspec(thread)
#endif
#ifndef PLATFORM_IS_LITTLE_ENDIAN #ifndef PLATFORM_IS_LITTLE_ENDIAN
#define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN) #define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)

@ -6,6 +6,7 @@
#include "table/adaptive_table_factory.h" #include "table/adaptive_table_factory.h"
#include "table/format.h" #include "table/format.h"
#include "port/port.h"
namespace rocksdb { namespace rocksdb {

@ -14,7 +14,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
#ifndef OS_WIN
#include <unistd.h> #include <unistd.h>
#endif
#include <algorithm> #include <algorithm>
#include <set> #include <set>
@ -36,7 +38,7 @@
#include "rocksdb/slice.h" #include "rocksdb/slice.h"
#include "rocksdb/table.h" #include "rocksdb/table.h"
#include "rocksdb/utilities/checkpoint.h" #include "rocksdb/utilities/checkpoint.h"
#include "rocksdb/utilities/convenience.h" #include "rocksdb/convenience.h"
#include "table/block_based_table_factory.h" #include "table/block_based_table_factory.h"
#include "table/mock_table.h" #include "table/mock_table.h"
#include "table/plain_table_factory.h" #include "table/plain_table_factory.h"

@ -10,7 +10,9 @@
#include "rocksdb/env.h" #include "rocksdb/env.h"
#include <thread> #include <thread>
#include "port/port.h"
#include "port/sys_time.h" #include "port/sys_time.h"
#include "port/port.h"
#include "rocksdb/options.h" #include "rocksdb/options.h"
#include "util/arena.h" #include "util/arena.h"
@ -56,6 +58,29 @@ void Log(Logger* info_log, const char* format, ...) {
} }
} }
void Logger::Logv(const InfoLogLevel log_level, const char* format, va_list ap) {
static const char* kInfoLogLevelNames[5] = { "DEBUG", "INFO", "WARN",
"ERROR", "FATAL" };
if (log_level < log_level_) {
return;
}
if (log_level == InfoLogLevel::INFO_LEVEL) {
// Doesn't print log level if it is INFO level.
// This is to avoid unexpected performance regression after we add
// the feature of log level. All the logs before we add the feature
// are INFO level. We don't want to add extra costs to those existing
// logging.
Logv(format, ap);
} else {
char new_format[500];
snprintf(new_format, sizeof(new_format) - 1, "[%s] %s",
kInfoLogLevelNames[log_level], format);
Logv(new_format, ap);
}
}
void Log(const InfoLogLevel log_level, Logger* info_log, const char* format, void Log(const InfoLogLevel log_level, Logger* info_log, const char* format,
...) { ...) {
if (info_log && info_log->GetInfoLogLevel() <= log_level) { if (info_log && info_log->GetInfoLogLevel() <= log_level) {

@ -10,7 +10,11 @@
namespace rocksdb { namespace rocksdb {
#ifndef IOS_CROSS_COMPILE #ifndef IOS_CROSS_COMPILE
# ifdef _WIN32
__declspec(thread) IOStatsContext iostats_context;
# else
__thread IOStatsContext iostats_context; __thread IOStatsContext iostats_context;
# endif
#endif // IOS_CROSS_COMPILE #endif // IOS_CROSS_COMPILE
void IOStatsContext::Reset() { void IOStatsContext::Reset() {

@ -13,6 +13,7 @@
#include "rocksdb/slice.h" #include "rocksdb/slice.h"
#include "rocksdb/write_batch.h" #include "rocksdb/write_batch.h"
#include "util/testharness.h" #include "util/testharness.h"
#include "port/port.h"
using namespace rocksdb; using namespace rocksdb;

@ -10,10 +10,11 @@
namespace rocksdb { namespace rocksdb {
#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE) #if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
// This is a dummy variable since some place references it PerfContext perf_context;
PerfContext perf_context; #elif _WIN32
__declspec(thread) PerfContext perf_context;
#else #else
__thread PerfContext perf_context; __thread PerfContext perf_context;
#endif #endif
void PerfContext::Reset() { void PerfContext::Reset() {

@ -35,6 +35,8 @@
#include <thread> #include <thread>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include "port/port.h"
namespace rocksdb { namespace rocksdb {

@ -17,6 +17,12 @@
#include "rocksdb/utilities/db_ttl.h" #include "rocksdb/utilities/db_ttl.h"
#include "db/db_impl.h" #include "db/db_impl.h"
#ifdef _WIN32
// Windows API macro interference
#undef GetCurrentTime
#endif
namespace rocksdb { namespace rocksdb {
class DBWithTTLImpl : public DBWithTTL { class DBWithTTLImpl : public DBWithTTL {

Loading…
Cancel
Save