Commit 8622363b authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Reimplement SignalSafeElfCache::Path

Summary: [Folly] Reimplement `SignalSafeElfCache::Path` minimally so that it meets the expectations of `std::basic_string` as used by the rest of `SignalSafeElfCache`.

Reviewed By: chadaustin, luciang

Differential Revision: D23152224

fbshipit-source-id: 48c7a7277d00a928d3de2937699ad112d6d560c2
parent bc6736ac
......@@ -24,6 +24,16 @@
namespace folly {
namespace symbolizer {
SignalSafeElfCache::Path::Path(
char const* const data,
std::size_t const size,
reentrant_allocator<char> const& alloc) noexcept
: data_{alloc} {
data_.reserve(size + 1);
data_.insert(data_.end(), data, data + size);
data_.insert(data_.end(), '\0');
}
std::shared_ptr<ElfFile> SignalSafeElfCache::getFile(StringPiece p) {
struct cmp {
bool operator()(Entry const& a, StringPiece b) const noexcept {
......
......@@ -21,6 +21,7 @@
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include <boost/intrusive/avl_set.hpp>
......@@ -47,8 +48,42 @@ class SignalSafeElfCache : public ElfCacheBase {
public:
std::shared_ptr<ElfFile> getFile(StringPiece path) override;
using Path = std::
basic_string<char, std::char_traits<char>, reentrant_allocator<char>>;
// Path
//
// A minimal implementation of the subset of std::string used below, as if:
//
// using Path = std::basic_string<
// char, std::char_traits<char>, reentrant_allocator<char>>;
//
// Since some library implementations of std::basic_string, as on CentOS 7,
// do not build when instantiated with a non-default-constructible allocator,
// and since other library replacements, such as folly::basic_fbstring, just
// ignore the allocator parameter.
class Path {
public:
Path(
char const* data,
std::size_t size,
reentrant_allocator<char> const& alloc) noexcept;
Path() = delete;
Path(Path const&) = delete;
void operator=(Path const&) = delete;
/* implicit */ operator StringPiece() const noexcept {
return data_;
}
char const* c_str() const noexcept {
return data_.data();
}
friend bool operator<(Path const& a, Path const& b) noexcept {
return a.data_ < b.data_;
}
private:
std::vector<char, reentrant_allocator<char>> data_;
};
struct Entry : boost::intrusive::avl_set_base_hook<> {
Path path;
......
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