Skip to content

Commit

Permalink
AssertAllocatedBy for cross-boundary code.
Browse files Browse the repository at this point in the history
Required for macOS unique_ptr allocator change.
  • Loading branch information
rnlahaye committed Mar 8, 2021
1 parent 3fc4823 commit c44f898
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion journal/player_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <vector>

#include "base/allocated_by.hpp"
#include "benchmark/benchmark.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -38,7 +39,8 @@ class PlayerTest : public ::testing::Test {
: test_info_(testing::UnitTest::GetInstance()->current_test_info()),
test_case_name_(test_info_->test_case_name()),
test_name_(test_info_->name()),
plugin_(interface::principia__NewPlugin("MJD0", "MJD0", 0)) {}
plugin_(base::AssertAllocatedBy<std::allocator<ksp_plugin::Plugin>>(
interface::principia__NewPlugin("MJD0", "MJD0", 0))) {}

template<typename Profile>
bool RunIfAppropriate(serialization::Method const& method_in,
Expand Down
4 changes: 3 additions & 1 deletion journal/recorder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <vector>

#include "base/allocated_by.hpp"
#include "base/array.hpp"
#include "base/hexadecimal.hpp"
#include "base/version.hpp"
Expand All @@ -24,7 +25,8 @@ class RecorderTest : public testing::Test {
RecorderTest()
: test_name_(
testing::UnitTest::GetInstance()->current_test_info()->name()),
plugin_(interface::principia__NewPlugin("MJD0", "MJD0", 0)),
plugin_(base::AssertAllocatedBy<std::allocator<ksp_plugin::Plugin>>(
interface::principia__NewPlugin("MJD0", "MJD0", 0))),
recorder_(new Recorder(test_name_ + ".journal.hex")) {
Recorder::Activate(recorder_);
}
Expand Down
5 changes: 4 additions & 1 deletion ksp_plugin/interface_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <utility>

#include "base/allocated_by.hpp"
#include "base/array.hpp"
#include "geometry/named_quantities.hpp"
#include "geometry/orthogonal_map.hpp"
Expand All @@ -19,6 +20,7 @@
namespace principia {
namespace interface {

using base::AssertAllocatedBy;
using base::UniqueArray;
using geometry::OrthogonalMap;
using geometry::RigidTransformation;
Expand Down Expand Up @@ -144,7 +146,8 @@ inline bool NaNIndependentEq(double const left, double const right) {
template<typename T>
std::unique_ptr<T> TakeOwnership(T** const pointer) {
CHECK_NOTNULL(pointer);
std::unique_ptr<T> owned_pointer(*pointer);
std::unique_ptr<T> owned_pointer(
AssertAllocatedBy<std::allocator<T>>(*pointer));
*pointer = nullptr;
return owned_pointer;
}
Expand Down

0 comments on commit c44f898

Please sign in to comment.