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:
@@ -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(
|
||||
|
||||
@@ -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>>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user