libutil: add shared_from_this support to ref

we don't need to unsafely cast a shared_from_this pointer to create a
ref (the pointer must be non-null to not invoke nasal demons anyway).

Change-Id: I133fe5f07b2cff8ec2c925f0528f4c5288827261
This commit is contained in:
eldritch horrors
2025-04-05 21:57:45 +02:00
parent aa358eac91
commit 448c7d50e1
4 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -352,7 +352,7 @@ Value * EvalCache::getRootValue(EvalState & state)
ref<AttrCursor> EvalCache::getRoot()
{
return make_ref<AttrCursor>(ref(shared_from_this()), std::nullopt);
return make_ref<AttrCursor>(*this, std::nullopt);
}
AttrCursor::AttrCursor(
+1 -1
View File
@@ -530,7 +530,7 @@ try {
ref<FSAccessor> BinaryCacheStore::getFSAccessor()
{
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), config().localNarCache);
return make_ref<RemoteFSAccessor>(*this, config().localNarCache);
}
kj::Promise<Result<void>>
+1 -1
View File
@@ -1022,7 +1022,7 @@ try {
ref<FSAccessor> RemoteStore::getFSAccessor()
{
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()));
return make_ref<RemoteFSAccessor>(*this);
}
static Logger::Fields readFields(Source & from)
+5
View File
@@ -32,6 +32,11 @@ public:
throw std::invalid_argument("null pointer cast to ref");
}
template<std::derived_from<std::enable_shared_from_this<T>> T2>
ref(T2 & r) : p(r.shared_from_this())
{
}
T* operator ->() const
{
return &*p;