Skip to content

Commit

Permalink
Merge pull request facebook#657 from yuslepukhin/ensure_clean_public_…
Browse files Browse the repository at this point in the history
…headers

Ensure Windows build w/o port/port.h in public headers
  • Loading branch information
siying committed Jul 17, 2015
2 parents ac2b936 + 415c473 commit d730c36
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set(SOURCES
db/builder.cc
db/c.cc
db/column_family.cc
db/compacted_db_impl.cc
db/compaction.cc
db/compaction_job.cc
db/compaction_picker.cc
Expand Down Expand Up @@ -202,7 +203,6 @@ set(SOURCES
util/xxhash.cc
utilities/backupable/backupable_db.cc
utilities/checkpoint/checkpoint.cc
utilities/compacted_db/compacted_db_impl.cc
utilities/document/document_db.cc
utilities/document/json_document.cc
utilities/document/json_document_builder.cc
Expand All @@ -215,8 +215,8 @@ set(SOURCES
utilities/merge_operators/uint64add.cc
utilities/redis/redis_lists.cc
utilities/spatialdb/spatial_db.cc
utilities/transactions/optimistic_transaction_impl.cc
utilities/transactions/optimistic_transaction_db_impl.cc
utilities/transactions/optimistic_transaction_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_internal.cc
Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

#pragma once

#ifdef OS_WIN
#ifdef _WIN32
#ifdef ROCKSDB_DLL
#ifdef ROCKSDB_LIBRARY_EXPORTS
#define ROCKSDB_LIBRARY_API __declspec(dllexport)
Expand Down
20 changes: 18 additions & 2 deletions include/rocksdb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#include "rocksdb/listener.h"
#include "rocksdb/thread_status.h"

#ifdef _WIN32
// Windows API macro interference
#undef DeleteFile
#endif


namespace rocksdb {

struct Options;
Expand Down Expand Up @@ -431,7 +437,12 @@ class DB {
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,
const Slice* end, bool change_level = false,
int target_level = -1, uint32_t target_path_id = 0) {
Expand All @@ -441,7 +452,12 @@ class DB {
options.target_path_id = target_path_id;
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,
bool change_level = false, int target_level = -1,
uint32_t target_path_id = 0) {
Expand Down
26 changes: 4 additions & 22 deletions include/rocksdb/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "rocksdb/status.h"
#include "rocksdb/thread_status.h"

#ifdef GetCurrentTime
#ifdef _WIN32
// Windows API macro interference
#undef DeleteFile
#undef GetCurrentTime
#endif

Expand Down Expand Up @@ -163,7 +165,6 @@ class Env {
virtual Status GetChildren(const std::string& dir,
std::vector<std::string>* result) = 0;

#undef DeleteFile
// Delete the named file.
virtual Status DeleteFile(const std::string& fname) = 0;

Expand Down Expand Up @@ -650,27 +651,8 @@ class Logger {
// and format. Any log with level under the internal log level
// of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be
// printed.
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;
}
virtual void Logv(const InfoLogLevel log_level, const char* format, va_list ap);

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; }
// Flush to the OS buffers
virtual void Flush() {}
Expand Down
4 changes: 4 additions & 0 deletions include/rocksdb/iostats_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ struct IOStatsContext {
};

#ifndef IOS_CROSS_COMPILE
# ifdef _WIN32
extern __declspec(thread) IOStatsContext iostats_context;
# else
extern __thread IOStatsContext iostats_context;
# endif
#endif // IOS_CROSS_COMPILE

} // namespace rocksdb
2 changes: 2 additions & 0 deletions include/rocksdb/perf_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ struct PerfContext {

#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
extern PerfContext perf_context;
#elif _WIN32
extern __declspec(thread) PerfContext perf_context;
#else
extern __thread PerfContext perf_context;
#endif
Expand Down
6 changes: 6 additions & 0 deletions include/rocksdb/utilities/stackable_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include <string>
#include "rocksdb/db.h"

#ifdef _WIN32
// Windows API macro interference
#undef DeleteFile
#endif


namespace rocksdb {

// This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d
Expand Down
7 changes: 6 additions & 1 deletion include/rocksdb/utilities/utility_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class UtilityDB {
// This function is here only for backwards compatibility. Please use the
// functions defined in DBWithTTl (rocksdb/utilities/db_ttl.h)
// (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,
StackableDB** dbptr,
int32_t ttl = 0,
Expand Down
2 changes: 1 addition & 1 deletion include/utilities/pragma_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning x))

#elif defined(OS_WIN)
#elif defined(_WIN32)

// Wrap unportable warning macro
#if defined(_MSC_VER)
Expand Down
13 changes: 13 additions & 0 deletions port/win/port_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

#include "rocksdb/options.h"

#undef min
#undef max
#undef DeleteFile
#undef GetCurrentTime


#ifndef strcasecmp
#define strcasecmp _stricmp
#endif
Expand All @@ -40,12 +46,17 @@
#define snprintf _snprintf
#endif

#undef GetCurrentTime
#undef DeleteFile

typedef SSIZE_T ssize_t;

// size_t printf formatting named in the manner of C99 standard formatting
// strings such as PRIu64
// in fact, we could use that one
#ifndef ROCKSDB_PRIszt
#define ROCKSDB_PRIszt "Iu"
#endif

#define __attribute__(A)

Expand All @@ -68,7 +79,9 @@ typedef SSIZE_T ssize_t;

// Thread local storage on Linux
// There is thread_local in C++11
#ifndef __thread
#define __thread __declspec(thread)
#endif

#ifndef PLATFORM_IS_LITTLE_ENDIAN
#define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
Expand Down
1 change: 1 addition & 0 deletions table/adaptive_table_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "table/adaptive_table_factory.h"

#include "table/format.h"
#include "port/port.h"

namespace rocksdb {

Expand Down
4 changes: 3 additions & 1 deletion util/db_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include <fcntl.h>
#include <inttypes.h>
#ifndef OS_WIN
#include <unistd.h>
#endif

#include <algorithm>
#include <set>
Expand All @@ -36,7 +38,7 @@
#include "rocksdb/slice.h"
#include "rocksdb/table.h"
#include "rocksdb/utilities/checkpoint.h"
#include "rocksdb/utilities/convenience.h"
#include "rocksdb/convenience.h"
#include "table/block_based_table_factory.h"
#include "table/mock_table.h"
#include "table/plain_table_factory.h"
Expand Down
25 changes: 25 additions & 0 deletions util/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "rocksdb/env.h"

#include <thread>
#include "port/port.h"
#include "port/sys_time.h"
#include "port/port.h"

#include "rocksdb/options.h"
#include "util/arena.h"
Expand Down Expand Up @@ -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,
...) {
if (info_log && info_log->GetInfoLogLevel() <= log_level) {
Expand Down
4 changes: 4 additions & 0 deletions util/iostats_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
namespace rocksdb {

#ifndef IOS_CROSS_COMPILE
# ifdef _WIN32
__declspec(thread) IOStatsContext iostats_context;
# else
__thread IOStatsContext iostats_context;
# endif
#endif // IOS_CROSS_COMPILE

void IOStatsContext::Reset() {
Expand Down
1 change: 1 addition & 0 deletions util/manual_compaction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "rocksdb/slice.h"
#include "rocksdb/write_batch.h"
#include "util/testharness.h"
#include "port/port.h"

using namespace rocksdb;

Expand Down
7 changes: 4 additions & 3 deletions util/perf_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
namespace rocksdb {

#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
__thread PerfContext perf_context;
__thread PerfContext perf_context;
#endif

void PerfContext::Reset() {
Expand Down
2 changes: 2 additions & 0 deletions utilities/backupable/backupable_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include "port/port.h"


namespace rocksdb {

Expand Down
6 changes: 6 additions & 0 deletions utilities/ttl/db_ttl_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#include "rocksdb/utilities/db_ttl.h"
#include "db/db_impl.h"

#ifdef _WIN32
// Windows API macro interference
#undef GetCurrentTime
#endif


namespace rocksdb {

class DBWithTTLImpl : public DBWithTTL {
Expand Down

0 comments on commit d730c36

Please sign in to comment.