Commit 2a150c32 authored by A. Hobden's avatar A. Hobden Committed by Huachao Huang

Fix C++ 8.1 build errors. (#207)

Sync of https://github.com/pingcap/rocksdb/pull/22

Fix the following gcc-8 warnings:
- conflicting C language linkage declaration [-Werror]
- writing to an object with no trivial copy-assignment [-Werror=class-memaccess]
- array subscript -1 is below array bounds [-Werror=array-bounds]
parent b011ecb1
...@@ -1386,23 +1386,24 @@ void rocksdb_writebatch_put_log_data( ...@@ -1386,23 +1386,24 @@ void rocksdb_writebatch_put_log_data(
b->rep.PutLogData(Slice(blob, len)); b->rep.PutLogData(Slice(blob, len));
} }
class H : public WriteBatch::Handler {
public:
void* state_;
void (*put_)(void*, const char* k, size_t klen, const char* v, size_t vlen);
void (*deleted_)(void*, const char* k, size_t klen);
virtual void Put(const Slice& key, const Slice& value) override {
(*put_)(state_, key.data(), key.size(), value.data(), value.size());
}
virtual void Delete(const Slice& key) override {
(*deleted_)(state_, key.data(), key.size());
}
};
void rocksdb_writebatch_iterate( void rocksdb_writebatch_iterate(
rocksdb_writebatch_t* b, rocksdb_writebatch_t* b,
void* state, void* state,
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
void (*deleted)(void*, const char* k, size_t klen)) { void (*deleted)(void*, const char* k, size_t klen)) {
class H : public WriteBatch::Handler {
public:
void* state_;
void (*put_)(void*, const char* k, size_t klen, const char* v, size_t vlen);
void (*deleted_)(void*, const char* k, size_t klen);
virtual void Put(const Slice& key, const Slice& value) override {
(*put_)(state_, key.data(), key.size(), value.data(), value.size());
}
virtual void Delete(const Slice& key) override {
(*deleted_)(state_, key.data(), key.size());
}
};
H handler; H handler;
handler.state_ = state; handler.state_ = state;
handler.put_ = put; handler.put_ = put;
...@@ -1647,18 +1648,6 @@ void rocksdb_writebatch_wi_iterate( ...@@ -1647,18 +1648,6 @@ void rocksdb_writebatch_wi_iterate(
void* state, void* state,
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
void (*deleted)(void*, const char* k, size_t klen)) { void (*deleted)(void*, const char* k, size_t klen)) {
class H : public WriteBatch::Handler {
public:
void* state_;
void (*put_)(void*, const char* k, size_t klen, const char* v, size_t vlen);
void (*deleted_)(void*, const char* k, size_t klen);
virtual void Put(const Slice& key, const Slice& value) override {
(*put_)(state_, key.data(), key.size(), value.data(), value.size());
}
virtual void Delete(const Slice& key) override {
(*deleted_)(state_, key.data(), key.size());
}
};
H handler; H handler;
handler.state_ = state; handler.state_ = state;
handler.put_ = put; handler.put_ = put;
...@@ -3005,20 +2994,21 @@ void rocksdb_slicetransform_destroy(rocksdb_slicetransform_t* st) { ...@@ -3005,20 +2994,21 @@ void rocksdb_slicetransform_destroy(rocksdb_slicetransform_t* st) {
delete st; delete st;
} }
struct Wrapper : public rocksdb_slicetransform_t {
const SliceTransform* rep_;
~Wrapper() { delete rep_; }
const char* Name() const override { return rep_->Name(); }
Slice Transform(const Slice& src) const override {
return rep_->Transform(src);
}
bool InDomain(const Slice& src) const override {
return rep_->InDomain(src);
}
bool InRange(const Slice& src) const override { return rep_->InRange(src); }
static void DoNothing(void*) { }
};
rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix(size_t prefixLen) { rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix(size_t prefixLen) {
struct Wrapper : public rocksdb_slicetransform_t {
const SliceTransform* rep_;
~Wrapper() { delete rep_; }
const char* Name() const override { return rep_->Name(); }
Slice Transform(const Slice& src) const override {
return rep_->Transform(src);
}
bool InDomain(const Slice& src) const override {
return rep_->InDomain(src);
}
bool InRange(const Slice& src) const override { return rep_->InRange(src); }
static void DoNothing(void*) { }
};
Wrapper* wrapper = new Wrapper; Wrapper* wrapper = new Wrapper;
wrapper->rep_ = rocksdb::NewFixedPrefixTransform(prefixLen); wrapper->rep_ = rocksdb::NewFixedPrefixTransform(prefixLen);
wrapper->state_ = nullptr; wrapper->state_ = nullptr;
...@@ -3027,19 +3017,6 @@ rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix(size_t pref ...@@ -3027,19 +3017,6 @@ rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix(size_t pref
} }
rocksdb_slicetransform_t* rocksdb_slicetransform_create_noop() { rocksdb_slicetransform_t* rocksdb_slicetransform_create_noop() {
struct Wrapper : public rocksdb_slicetransform_t {
const SliceTransform* rep_;
~Wrapper() { delete rep_; }
const char* Name() const override { return rep_->Name(); }
Slice Transform(const Slice& src) const override {
return rep_->Transform(src);
}
bool InDomain(const Slice& src) const override {
return rep_->InDomain(src);
}
bool InRange(const Slice& src) const override { return rep_->InRange(src); }
static void DoNothing(void*) { }
};
Wrapper* wrapper = new Wrapper; Wrapper* wrapper = new Wrapper;
wrapper->rep_ = rocksdb::NewNoopTransform(); wrapper->rep_ = rocksdb::NewNoopTransform();
wrapper->state_ = nullptr; wrapper->state_ = nullptr;
......
...@@ -278,7 +278,7 @@ struct InlineSkipList<Comparator>::Node { ...@@ -278,7 +278,7 @@ struct InlineSkipList<Comparator>::Node {
// next_[0]. This is used for passing data from AllocateKey to Insert. // next_[0]. This is used for passing data from AllocateKey to Insert.
void StashHeight(const int height) { void StashHeight(const int height) {
assert(sizeof(int) <= sizeof(next_[0])); assert(sizeof(int) <= sizeof(next_[0]));
memcpy(&next_[0], &height, sizeof(int)); memcpy(static_cast<void*>(&next_[0]), &height, sizeof(int));
} }
// Retrieves the value passed to StashHeight. Undefined after a call // Retrieves the value passed to StashHeight. Undefined after a call
...@@ -298,30 +298,30 @@ struct InlineSkipList<Comparator>::Node { ...@@ -298,30 +298,30 @@ struct InlineSkipList<Comparator>::Node {
assert(n >= 0); assert(n >= 0);
// Use an 'acquire load' so that we observe a fully initialized // Use an 'acquire load' so that we observe a fully initialized
// version of the returned Node. // version of the returned Node.
return (next_[-n].load(std::memory_order_acquire)); return ((&next_[0] - n)->load(std::memory_order_acquire));
} }
void SetNext(int n, Node* x) { void SetNext(int n, Node* x) {
assert(n >= 0); assert(n >= 0);
// Use a 'release store' so that anybody who reads through this // Use a 'release store' so that anybody who reads through this
// pointer observes a fully initialized version of the inserted node. // pointer observes a fully initialized version of the inserted node.
next_[-n].store(x, std::memory_order_release); (&next_[0] - n)->store(x, std::memory_order_release);
} }
bool CASNext(int n, Node* expected, Node* x) { bool CASNext(int n, Node* expected, Node* x) {
assert(n >= 0); assert(n >= 0);
return next_[-n].compare_exchange_strong(expected, x); return (&next_[0] - n)->compare_exchange_strong(expected, x);
} }
// No-barrier variants that can be safely used in a few locations. // No-barrier variants that can be safely used in a few locations.
Node* NoBarrier_Next(int n) { Node* NoBarrier_Next(int n) {
assert(n >= 0); assert(n >= 0);
return next_[-n].load(std::memory_order_relaxed); return (&next_[0] - n)->load(std::memory_order_relaxed);
} }
void NoBarrier_SetNext(int n, Node* x) { void NoBarrier_SetNext(int n, Node* x) {
assert(n >= 0); assert(n >= 0);
next_[-n].store(x, std::memory_order_relaxed); (&next_[0] - n)->store(x, std::memory_order_relaxed);
} }
// Insert node after prev on specific level. // Insert node after prev on specific level.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment