sapling/eden/fs/store/StoreResult.cpp
Sergey Zhupanov 419a57b1bc Enabled additional compiler warnings in Eden.
Summary:
1. Enabled a number of additional C++ compiler warnings in Eden.
2. Fixed warnings-turned-errors that resulted from this change.

Reviewed By: simpkins

Differential Revision: D8132543

fbshipit-source-id: 2290ffaaab55024d582e29201a1bcaa1152e6b3e
2018-06-01 11:39:01 -07:00

54 lines
1.7 KiB
C++

/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "StoreResult.h"
#include <folly/io/IOBuf.h>
using folly::IOBuf;
namespace {
void freeString(void* /* buffer */, void* userData) {
auto str = static_cast<std::string*>(userData);
delete str;
}
} // namespace
namespace facebook {
namespace eden {
IOBuf StoreResult::iobufWrapper() const {
ensureValid();
return IOBuf{IOBuf::WRAP_BUFFER, bytes()};
}
folly::IOBuf StoreResult::extractIOBuf() {
ensureValid();
// Unfortunately RocksDB returns data to us in a std::string. This makes it
// difficult for us to control the lifetime. We end up having to allocate a
// new std::string on the heap, just to control when it will free the
// underlying data it points to.
auto stringPtr = std::make_unique<std::string>(std::move(data_));
// Extract the data and size before we pass stringPtr.release()
// to the IOBuf constructor. Arguments are evaluated in an arbitrary order,
// and we need to make sure we do this before release() happens.
auto data = const_cast<char*>(stringPtr->data());
auto size = stringPtr->size();
return IOBuf(
IOBuf::TAKE_OWNERSHIP, data, size, freeString, stringPtr.release());
}
[[noreturn]] void StoreResult::throwInvalidError() const {
// Maybe we should define our own more specific error type in the future
throw std::domain_error("value not present in store");
}
} // namespace eden
} // namespace facebook