From 2ef4b69760af183792a740f425eb371a6aeb0009 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 6 Apr 2025 20:29:25 +0200 Subject: [PATCH] libutil: disallow implicit ref creations 448c7d50e1bfac6644c0cf13085eb1bbeda32e6b was a bit over-eager and didn't make the `ref(enable_shared_from_this &)` constructor explicit. this has confused hydra maintainers, and is just generally bad practice since any reference is allowed to implicitly convert, even if those references are not associated with an active control block. we can't avoid this problem entirely, but we can make what happens more explicit by ... well, making the involved constructor explicit. enable_shared_from_this is statically unsafe in principle and we really have to get rid of this nonsense soon. Change-Id: I8b48ef4353e6301b61af3569083f42bc7379b0a4 --- lix/libexpr/eval-cache.cc | 2 +- lix/libstore/binary-cache-store.cc | 2 +- lix/libstore/remote-store.cc | 2 +- lix/libutil/ref.hh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lix/libexpr/eval-cache.cc b/lix/libexpr/eval-cache.cc index e4e5dabee..2fb950b77 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(*this, std::nullopt); + return make_ref(ref(*this), std::nullopt); } AttrCursor::AttrCursor( diff --git a/lix/libstore/binary-cache-store.cc b/lix/libstore/binary-cache-store.cc index 43872c7cb..f300a44ba 100644 --- a/lix/libstore/binary-cache-store.cc +++ b/lix/libstore/binary-cache-store.cc @@ -532,7 +532,7 @@ try { ref BinaryCacheStore::getFSAccessor() { - return make_ref(*this, config().localNarCache); + return make_ref(ref(*this), config().localNarCache); } kj::Promise> diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index e24c578b7..b3c74ab73 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -1022,7 +1022,7 @@ try { ref RemoteStore::getFSAccessor() { - return make_ref(*this); + return make_ref(ref(*this)); } static Logger::Fields readFields(Source & from) diff --git a/lix/libutil/ref.hh b/lix/libutil/ref.hh index ab7e60e7b..44858e482 100644 --- a/lix/libutil/ref.hh +++ b/lix/libutil/ref.hh @@ -39,7 +39,7 @@ public: } template> T2> - ref(T2 & r) : p(r.shared_from_this()) + explicit ref(T2 & r) : p(r.shared_from_this()) { }