Commit 8ef9851e authored by Dominik Charousset's avatar Dominik Charousset

Fix build on CentOS 3.10, close #705

parent f793d7ed
......@@ -28,6 +28,7 @@ set(LIBCAF_CORE_SRCS
src/actor_registry.cpp
src/actor_system.cpp
src/actor_system_config.cpp
src/append_hex.cpp
src/atom.cpp
src/attachable.cpp
src/behavior.cpp
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <string>
namespace caf {
namespace detail {
void append_hex(std::string& result, const uint8_t* xs, size_t n);
} // namespace detail
} // namespace caf
......@@ -35,8 +35,9 @@
#include "caf/meta/omittable_if_none.hpp"
#include "caf/meta/omittable_if_empty.hpp"
#include "caf/detail/int_list.hpp"
#include "caf/detail/append_hex.hpp"
#include "caf/detail/apply_args.hpp"
#include "caf/detail/int_list.hpp"
#include "caf/detail/type_traits.hpp"
namespace caf {
......@@ -74,8 +75,6 @@ public:
void consume(const char* cstr);
void consume_hex(const uint8_t* xs, size_t n);
inline void consume(bool& x) {
result_ += x ? "true" : "false";
}
......@@ -252,7 +251,8 @@ public:
template <class T, class... Ts>
void traverse(meta::hex_formatted_t, T& x, Ts&&... xs) {
sep();
consume_hex(reinterpret_cast<uint8_t*>(deconst(x).data()), x.size());
append_hex(result_, reinterpret_cast<uint8_t*>(deconst(x).data()),
x.size());
traverse(std::forward<Ts>(xs)...);
}
......
......@@ -18,13 +18,13 @@
#pragma once
#include <string>
#include <cstddef>
#include <cinttypes>
#include <algorithm>
#include <cstddef>
#include <stdexcept>
#include <string>
#include <type_traits>
#include "caf/detail/append_hex.hpp"
#include "caf/detail/comparable.hpp"
#include "caf/detail/type_traits.hpp"
......@@ -246,12 +246,10 @@ bool operator<(const T* x, const intrusive_ptr<T>& y) {
template <class T>
std::string to_string(const intrusive_ptr<T>& x) {
std::string result;
auto v = reinterpret_cast<uintptr_t>(x.get());
// we convert to hex representation, i.e.,
// one byte takes two characters + null terminator + "0x" prefix
char buf[sizeof(v) * 2 + 3];
sprintf(buf, "%" PRIxPTR, v);
return buf;
detail::append_hex(result, reinterpret_cast<uint8_t*>(&v), sizeof(v));
return result;
}
} // namespace caf
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/stringification_inspector.hpp"
namespace caf {
namespace detail {
void append_hex(std::string& result, const uint8_t* xs, size_t n) {
if (n == 0) {
result += "00";
return;
}
auto tbl = "0123456789ABCDEF";
char buf[3] = {0, 0, 0};
for (size_t i = 0; i < n; ++i) {
auto c = xs[i];
buf[0] = tbl[c >> 4];
buf[1] = tbl[c & 0x0F];
result += buf;
}
}
} // namespace detail
} // namespace caf
......@@ -188,8 +188,7 @@ void append_to_string(std::string& x, const node_id& y) {
x += "invalid-node";
return;
}
detail::stringification_inspector si{x};
si.consume_hex(reinterpret_cast<const uint8_t*>(y.host_id().data()),
detail::append_hex(x, reinterpret_cast<const uint8_t*>(y.host_id().data()),
y.host_id().size());
x += '#';
x += std::to_string(y.process_id());
......
......@@ -70,20 +70,5 @@ void stringification_inspector::consume(const char* cstr) {
result_ += '"';
}
void stringification_inspector::consume_hex(const uint8_t* xs, size_t n) {
if (n == 0) {
result_ += "00";
return;
}
auto tbl = "0123456789ABCDEF";
char buf[3] = {0, 0, 0};
for (size_t i = 0; i < n; ++i) {
auto c = xs[i];
buf[0] = tbl[c >> 4];
buf[1] = tbl[c & 0x0F];
result_ += buf;
}
}
} // namespace detail
} // namespace caf
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