diff --git a/lix/libexpr/eval-cache.cc b/lix/libexpr/eval-cache.cc index 03d11ebdb..ad6e0a069 100644 --- a/lix/libexpr/eval-cache.cc +++ b/lix/libexpr/eval-cache.cc @@ -352,7 +352,7 @@ Value * EvalCache::getRootValue(EvalState & state) ref EvalCache::getRoot() { - return make_ref(ref(shared_from_this()), std::nullopt); + return make_ref(*this, std::nullopt); } AttrCursor::AttrCursor( diff --git a/lix/libstore/binary-cache-store.cc b/lix/libstore/binary-cache-store.cc index 2dbf57d2f..77602efec 100644 --- a/lix/libstore/binary-cache-store.cc +++ b/lix/libstore/binary-cache-store.cc @@ -530,7 +530,7 @@ try { ref BinaryCacheStore::getFSAccessor() { - return make_ref(ref(shared_from_this()), config().localNarCache); + return make_ref(*this, config().localNarCache); } kj::Promise> diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 6f2d61f18..e24c578b7 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -1022,7 +1022,7 @@ try { ref RemoteStore::getFSAccessor() { - return make_ref(ref(shared_from_this())); + return make_ref(*this); } static Logger::Fields readFields(Source & from) diff --git a/lix/libutil/ref.hh b/lix/libutil/ref.hh index 8ccad834b..312b7d09e 100644 --- a/lix/libutil/ref.hh +++ b/lix/libutil/ref.hh @@ -32,6 +32,11 @@ public: throw std::invalid_argument("null pointer cast to ref"); } + template> T2> + ref(T2 & r) : p(r.shared_from_this()) + { + } + T* operator ->() const { return &*p;