mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd: Replace callsites w/ template deduced mutable_cast.
This commit is contained in:
parent
2eab4fb4f7
commit
f3886d60d8
12 changed files with 60 additions and 60 deletions
|
@ -87,7 +87,7 @@ inline boost::asio::io_context &
|
|||
ircd::ios::get()
|
||||
noexcept
|
||||
{
|
||||
auto &context(const_cast<asio::execution_context &>(main.context()));
|
||||
auto &context(mutable_cast(main.context()));
|
||||
return static_cast<asio::io_context &>(context);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,7 @@ pubsetbuf(stringstream &ss,
|
|||
{
|
||||
auto *const &data
|
||||
{
|
||||
const_cast<char *>(s.data())
|
||||
mutable_cast(s.data())
|
||||
};
|
||||
|
||||
ss.rdbuf()->pubsetbuf(data, s.size());
|
||||
|
|
|
@ -1981,7 +1981,7 @@ ircd::ctx::promise_base::promise_base(const promise_base &o)
|
|||
:st{o.st}
|
||||
,next{nullptr}
|
||||
{
|
||||
append(*this, const_cast<promise_base &>(o));
|
||||
append(*this, mutable_cast(o));
|
||||
}
|
||||
|
||||
ircd::ctx::promise_base &
|
||||
|
|
40
ircd/db.cc
40
ircd/db.cc
|
@ -1948,7 +1948,7 @@ const
|
|||
return std::all_of(std::begin(*this), std::end(*this), []
|
||||
(const auto &cell)
|
||||
{
|
||||
db::column &column(const_cast<db::cell &>(cell));
|
||||
db::column &column(mutable_cast(cell));
|
||||
return cell.valid() && db::cached(column, cell.key());
|
||||
});
|
||||
}
|
||||
|
@ -1960,7 +1960,7 @@ const
|
|||
return std::all_of(std::begin(*this), std::end(*this), [&key]
|
||||
(const auto &cell)
|
||||
{
|
||||
db::column &column(const_cast<db::cell &>(cell));
|
||||
db::column &column(mutable_cast(cell));
|
||||
return db::cached(column, key);
|
||||
});
|
||||
}
|
||||
|
@ -3149,8 +3149,8 @@ ircd::db::property(const column &column,
|
|||
const string_view &name)
|
||||
{
|
||||
std::string ret;
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database &d(const_cast<db::column &>(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
database &d(mutable_cast(column));
|
||||
if(!d.d->GetProperty(c, slice(name), &ret))
|
||||
throw not_found
|
||||
{
|
||||
|
@ -3169,8 +3169,8 @@ ircd::db::property(const column &column,
|
|||
const string_view &name)
|
||||
{
|
||||
uint64_t ret(0);
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database &d(const_cast<db::column &>(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
database &d(mutable_cast(column));
|
||||
if(!d.d->GetIntProperty(c, slice(name), &ret))
|
||||
throw not_found
|
||||
{
|
||||
|
@ -3189,8 +3189,8 @@ ircd::db::property(const column &column,
|
|||
const string_view &name)
|
||||
{
|
||||
std::map<std::string, std::string> ret;
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database &d(const_cast<db::column &>(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
database &d(mutable_cast(column));
|
||||
if(!d.d->GetMapProperty(c, slice(name), &ret))
|
||||
ret.emplace(std::string{name}, property<std::string>(column, name));
|
||||
|
||||
|
@ -3200,8 +3200,8 @@ ircd::db::property(const column &column,
|
|||
ircd::db::options
|
||||
ircd::db::getopt(const column &column)
|
||||
{
|
||||
database &d(const_cast<db::column &>(column));
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database &d(mutable_cast(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
return options
|
||||
{
|
||||
static_cast<rocksdb::ColumnFamilyOptions>(d.d->GetOptions(c))
|
||||
|
@ -3212,8 +3212,8 @@ size_t
|
|||
ircd::db::bytes(const column &column)
|
||||
{
|
||||
rocksdb::ColumnFamilyMetaData cfm;
|
||||
database &d(const_cast<db::column &>(column));
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database &d(mutable_cast(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
assert(bool(c.handle));
|
||||
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
|
||||
return cfm.size;
|
||||
|
@ -3223,8 +3223,8 @@ size_t
|
|||
ircd::db::file_count(const column &column)
|
||||
{
|
||||
rocksdb::ColumnFamilyMetaData cfm;
|
||||
database &d(const_cast<db::column &>(column));
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database &d(mutable_cast(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
assert(bool(c.handle));
|
||||
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
|
||||
return cfm.file_count;
|
||||
|
@ -3233,7 +3233,7 @@ ircd::db::file_count(const column &column)
|
|||
std::vector<std::string>
|
||||
ircd::db::files(const column &column)
|
||||
{
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
database &d(*c.d);
|
||||
|
||||
rocksdb::ColumnFamilyMetaData cfmd;
|
||||
|
@ -3927,7 +3927,7 @@ ircd::db::insert(rocksdb::Cache &cache,
|
|||
throw_on_error
|
||||
{
|
||||
cache.Insert(slice(key),
|
||||
const_cast<char *>(data(value.release())),
|
||||
mutable_cast(data(value.release())),
|
||||
value_size,
|
||||
deleter,
|
||||
nullptr)
|
||||
|
@ -3947,7 +3947,7 @@ ircd::db::for_each(const rocksdb::Cache &cache,
|
|||
const std::lock_guard lock{mutex};
|
||||
|
||||
thread_local rocksdb::Cache *_cache;
|
||||
_cache = const_cast<rocksdb::Cache *>(&cache);
|
||||
_cache = mutable_cast(&cache);
|
||||
|
||||
thread_local const cache_closure *_closure;
|
||||
_closure = &closure;
|
||||
|
@ -3975,7 +3975,7 @@ ircd::db::charge(const rocksdb::Cache &cache_,
|
|||
{
|
||||
auto &cache
|
||||
{
|
||||
const_cast<rocksdb::Cache &>(cache_)
|
||||
mutable_cast(cache_)
|
||||
};
|
||||
|
||||
const custom_ptr<rocksdb::Cache::Handle> handle
|
||||
|
@ -4004,7 +4004,7 @@ ircd::db::exists(const rocksdb::Cache &cache_,
|
|||
{
|
||||
auto &cache
|
||||
{
|
||||
const_cast<rocksdb::Cache &>(cache_)
|
||||
mutable_cast(cache_)
|
||||
};
|
||||
|
||||
const custom_ptr<rocksdb::Cache::Handle> handle
|
||||
|
@ -4747,7 +4747,7 @@ ircd::db::_seek(const vector_view<_read_op> &op,
|
|||
std::transform(begin(op), end(op), cf, []
|
||||
(auto &op_)
|
||||
{
|
||||
auto &op(const_cast<_read_op &>(op_));
|
||||
auto &op(mutable_cast(op_));
|
||||
database::column &c(std::get<column>(op));
|
||||
return static_cast<rocksdb::ColumnFamilyHandle *>(c);
|
||||
});
|
||||
|
|
|
@ -556,7 +556,7 @@ ircd::db::wals(const database &cd)
|
|||
{
|
||||
auto &d
|
||||
{
|
||||
const_cast<database &>(cd)
|
||||
mutable_cast(cd)
|
||||
};
|
||||
|
||||
std::vector<std::unique_ptr<rocksdb::LogFile>> vec;
|
||||
|
@ -595,7 +595,7 @@ ircd::db::files(const database &cd,
|
|||
uint64_t &msz)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
auto &d(const_cast<database &>(cd));
|
||||
auto &d(mutable_cast(cd));
|
||||
throw_on_error
|
||||
{
|
||||
d.d->GetLiveFiles(ret, &msz, false)
|
||||
|
@ -613,7 +613,7 @@ ircd::db::errors(const database &d)
|
|||
uint64_t
|
||||
ircd::db::sequence(const database &cd)
|
||||
{
|
||||
database &d(const_cast<database &>(cd));
|
||||
database &d(mutable_cast(cd));
|
||||
return d.d->GetLatestSequenceNumber();
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ ircd::db::property(const database &cd,
|
|||
const string_view &name)
|
||||
{
|
||||
uint64_t ret(0);
|
||||
database &d(const_cast<database &>(cd));
|
||||
database &d(mutable_cast(cd));
|
||||
if(!d.d->GetAggregatedIntProperty(slice(name), &ret))
|
||||
throw not_found
|
||||
{
|
||||
|
@ -3632,7 +3632,7 @@ ircd::db::database::sst::info::vector::vector(const database &d)
|
|||
|
||||
ircd::db::database::sst::info::vector::vector(const db::column &column)
|
||||
{
|
||||
database::column &c(const_cast<db::column &>(column));
|
||||
database::column &c(mutable_cast(column));
|
||||
database &d(*c.d);
|
||||
|
||||
rocksdb::ColumnFamilyMetaData cfmd;
|
||||
|
@ -3677,7 +3677,7 @@ ircd::db::database::sst::info::vector::vector(const db::column &column)
|
|||
ircd::db::database::sst::info::info(const database &d_,
|
||||
const string_view &filename)
|
||||
{
|
||||
auto &d(const_cast<database &>(d_));
|
||||
auto &d(mutable_cast(d_));
|
||||
const ctx::uninterruptible::nothrow ui;
|
||||
|
||||
std::vector<rocksdb::LiveFileMetaData> v;
|
||||
|
@ -3807,7 +3807,7 @@ ircd::db::database::sst::info::operator=(rocksdb::TableProperties &&tp)
|
|||
|
||||
ircd::db::database::wal::info::vector::vector(const database &d_)
|
||||
{
|
||||
auto &d{const_cast<database &>(d_)};
|
||||
auto &d{mutable_cast(d_)};
|
||||
std::vector<std::unique_ptr<rocksdb::LogFile>> vec;
|
||||
throw_on_error
|
||||
{
|
||||
|
@ -3826,7 +3826,7 @@ ircd::db::database::wal::info::vector::vector(const database &d_)
|
|||
ircd::db::database::wal::info::info(const database &d_,
|
||||
const string_view &filename)
|
||||
{
|
||||
auto &d{const_cast<database &>(d_)};
|
||||
auto &d{mutable_cast(d_)};
|
||||
std::vector<std::unique_ptr<rocksdb::LogFile>> vec;
|
||||
throw_on_error
|
||||
{
|
||||
|
|
|
@ -134,7 +134,7 @@ ircd::net::config(const acceptor &a)
|
|||
std::string
|
||||
ircd::net::cipher_list(const acceptor &a)
|
||||
{
|
||||
auto &ssl(const_cast<acceptor &>(a).ssl);
|
||||
auto &ssl(mutable_cast(a).ssl);
|
||||
return openssl::cipher_list(*ssl.native_handle());
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ void
|
|||
ircd::openssl::set_curves(SSL &ssl,
|
||||
std::string list)
|
||||
{
|
||||
auto data(const_cast<char *>(list.data()));
|
||||
auto data(mutable_cast(list.data()));
|
||||
call(::SSL_ctrl, &ssl, SSL_CTRL_SET_CURVES_LIST, 0, data);
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ void
|
|||
ircd::openssl::set_curves(SSL_CTX &ssl,
|
||||
std::string list)
|
||||
{
|
||||
auto data(const_cast<char *>(list.data()));
|
||||
auto data(mutable_cast(list.data()));
|
||||
call(::SSL_CTX_ctrl, &ssl, SSL_CTRL_SET_CURVES_LIST, 0, data);
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ ircd::openssl::cipher_list(const SSL_CTX &ctx,
|
|||
{
|
||||
const custom_ptr<SSL> ssl
|
||||
{
|
||||
SSL_new(const_cast<SSL_CTX *>(&ctx)), SSL_free
|
||||
SSL_new(mutable_cast(&ctx)), SSL_free
|
||||
};
|
||||
|
||||
std::stringstream ret;
|
||||
|
@ -254,7 +254,7 @@ ircd::openssl::current_cert(X509_STORE_CTX &cx)
|
|||
const X509 &
|
||||
ircd::openssl::current_cert(const X509_STORE_CTX &cx)
|
||||
{
|
||||
auto &mcx{const_cast<X509_STORE_CTX &>(cx)};
|
||||
auto &mcx{mutable_cast(cx)};
|
||||
const auto *const ret
|
||||
{
|
||||
X509_STORE_CTX_get_current_cert(&mcx)
|
||||
|
@ -272,7 +272,7 @@ ircd::openssl::current_cert(const X509_STORE_CTX &cx)
|
|||
uint
|
||||
ircd::openssl::get_error_depth(const X509_STORE_CTX &cx)
|
||||
{
|
||||
auto &mcx{const_cast<X509_STORE_CTX &>(cx)};
|
||||
auto &mcx{mutable_cast(cx)};
|
||||
const int ret
|
||||
{
|
||||
X509_STORE_CTX_get_error_depth(&mcx)
|
||||
|
@ -297,7 +297,7 @@ ircd::openssl::cert_error_string(const long &n)
|
|||
int
|
||||
ircd::openssl::get_error(const X509_STORE_CTX &cx)
|
||||
{
|
||||
auto &mcx{const_cast<X509_STORE_CTX &>(cx)};
|
||||
auto &mcx{mutable_cast(cx)};
|
||||
return X509_STORE_CTX_get_error(&mcx);
|
||||
}
|
||||
|
||||
|
@ -462,7 +462,7 @@ ircd::openssl::genX509(const mutable_buffer &out,
|
|||
std::string
|
||||
ircd::openssl::stringify(const X509 &cert_)
|
||||
{
|
||||
auto &cert{const_cast<X509 &>(cert_)};
|
||||
auto &cert{mutable_cast(cert_)};
|
||||
|
||||
// issuer
|
||||
std::vector<json::member> issuer_json;
|
||||
|
@ -608,7 +608,7 @@ bool
|
|||
ircd::openssl::for_each(const X509_NAME &name_,
|
||||
const x509_name_entry_closure &closure)
|
||||
{
|
||||
const auto name(const_cast<X509_NAME *>(&name_));
|
||||
const auto name(mutable_cast(&name_));
|
||||
const auto cnt(X509_NAME_entry_count(name));
|
||||
for(auto i(0); i < cnt; ++i)
|
||||
{
|
||||
|
@ -637,7 +637,7 @@ ircd::openssl::for_each(const X509_NAME &name_,
|
|||
time_t
|
||||
ircd::openssl::not_before(const X509 &cert_)
|
||||
{
|
||||
auto &cert{const_cast<X509 &>(cert_)};
|
||||
auto &cert{mutable_cast(cert_)};
|
||||
ASN1_TIME *const notBefore{X509_get_notBefore(&cert)};
|
||||
return get_time(*notBefore);
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ ircd::openssl::not_before(const X509 &cert_)
|
|||
time_t
|
||||
ircd::openssl::not_after(const X509 &cert_)
|
||||
{
|
||||
auto &cert{const_cast<X509 &>(cert_)};
|
||||
auto &cert{mutable_cast(cert_)};
|
||||
ASN1_TIME *const notAfter{X509_get_notAfter(&cert)};
|
||||
return get_time(*notAfter);
|
||||
}
|
||||
|
@ -656,7 +656,7 @@ ircd::openssl::subject_common_name(const mutable_buffer &out,
|
|||
{
|
||||
X509_NAME *const subject
|
||||
{
|
||||
X509_get_subject_name(const_cast<X509 *>(&cert))
|
||||
X509_get_subject_name(mutable_cast(&cert))
|
||||
};
|
||||
|
||||
if(!subject)
|
||||
|
@ -701,13 +701,13 @@ ircd::openssl::print_subject(const mutable_buffer &buf,
|
|||
|
||||
const X509_NAME *const subject
|
||||
{
|
||||
X509_get_subject_name(const_cast<X509 *>(&cert))
|
||||
X509_get_subject_name(mutable_cast(&cert))
|
||||
};
|
||||
|
||||
return bio::write(buf, [&subject, &flags]
|
||||
(BIO *const &bio)
|
||||
{
|
||||
X509_NAME_print_ex(bio, const_cast<X509_NAME *>(subject), 0, flags);
|
||||
X509_NAME_print_ex(bio, mutable_cast(subject), 0, flags);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -737,7 +737,7 @@ ircd::openssl::print(const mutable_buffer &buf,
|
|||
return bio::write(buf, [&cert, &flags]
|
||||
(BIO *const &bio)
|
||||
{
|
||||
X509_print_ex(bio, const_cast<X509 *>(&cert), 0, flags);
|
||||
X509_print_ex(bio, mutable_cast(&cert), 0, flags);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -780,7 +780,7 @@ ircd::openssl::write_pem(const mutable_buffer &out,
|
|||
return bio::write(out, [&cert]
|
||||
(BIO *const &bio)
|
||||
{
|
||||
call(::PEM_write_bio_X509, bio, const_cast<X509 *>(&cert));
|
||||
call(::PEM_write_bio_X509, bio, mutable_cast(&cert));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -790,7 +790,7 @@ ircd::openssl::i2d(const mutable_buffer &buf,
|
|||
{
|
||||
auto &cert
|
||||
{
|
||||
const_cast<X509 &>(_cert)
|
||||
mutable_cast(_cert)
|
||||
};
|
||||
|
||||
const int len
|
||||
|
@ -948,7 +948,7 @@ void
|
|||
ircd::openssl::ec_fini()
|
||||
noexcept
|
||||
{
|
||||
EC_GROUP_free(const_cast<EC_GROUP *>(secp256k1));
|
||||
EC_GROUP_free(mutable_cast(secp256k1));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1093,7 +1093,7 @@ ircd::openssl::print(const mutable_buffer &buf,
|
|||
return bio::write(buf, [&rsa, &offset]
|
||||
(BIO *const &bio)
|
||||
{
|
||||
RSA_print(bio, const_cast<RSA *>(&rsa), offset);
|
||||
RSA_print(bio, mutable_cast(&rsa), offset);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1110,7 +1110,7 @@ ircd::openssl::size(const RSA &key)
|
|||
void
|
||||
ircd::openssl::check(const RSA &key)
|
||||
{
|
||||
if(call<error, -1>(::RSA_check_key, const_cast<RSA *>(&key)) == 0)
|
||||
if(call<error, -1>(::RSA_check_key, mutable_cast(&key)) == 0)
|
||||
throw error{"Invalid RSA"};
|
||||
}
|
||||
|
||||
|
@ -1118,7 +1118,7 @@ bool
|
|||
ircd::openssl::check(const RSA &key,
|
||||
const std::nothrow_t)
|
||||
{
|
||||
return RSA_check_key(const_cast<RSA *>(&key)) == 1;
|
||||
return RSA_check_key(mutable_cast(&key)) == 1;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1151,7 +1151,7 @@ ircd::openssl::write_pem_priv(const mutable_buffer &out,
|
|||
pem_password_cb *const pwcb{nullptr};
|
||||
void *const u{nullptr};
|
||||
|
||||
auto *const p{const_cast<EVP_PKEY *>(&evp)};
|
||||
auto *const p{mutable_cast(&evp)};
|
||||
return bio::write(out, [&evp, &p, &enc, &kstr, &klen, &pwcb, &u]
|
||||
(BIO *const &bio)
|
||||
{
|
||||
|
@ -1176,7 +1176,7 @@ ircd::string_view
|
|||
ircd::openssl::write_pem_pub(const mutable_buffer &out,
|
||||
const EVP_PKEY &evp)
|
||||
{
|
||||
auto *const p{const_cast<EVP_PKEY *>(&evp)};
|
||||
auto *const p{mutable_cast(&evp)};
|
||||
return bio::write(out, [&evp, &p]
|
||||
(BIO *const &bio)
|
||||
{
|
||||
|
|
|
@ -3808,7 +3808,7 @@ ircd::server::tag::read_chunk_dynamic_head(const const_buffer &buffer,
|
|||
// Setup the capstan and mark the end of the tape
|
||||
parse::buffer pb
|
||||
{
|
||||
mutable_buffer(const_cast<char *>(data(chunk_head)), size(chunk_head))
|
||||
mutable_buffer(mutable_cast(data(chunk_head)), size(chunk_head))
|
||||
};
|
||||
parse::capstan pc{pb};
|
||||
pc.read += size(chunk_head);
|
||||
|
|
|
@ -283,7 +283,7 @@ ircd::util::string(const size_t &size,
|
|||
std::string ret(alloc_size, char{});
|
||||
const mutable_buffer buf
|
||||
{
|
||||
const_cast<char *>(ret.data()), ret.size()
|
||||
mutable_cast(ret.data()), ret.size()
|
||||
};
|
||||
|
||||
const size_t consumed
|
||||
|
|
|
@ -125,7 +125,7 @@ try
|
|||
m::keys::cache::set(key->verify_keys);
|
||||
|
||||
create(me);
|
||||
const_cast<m::user &>(me).activate();
|
||||
mutable_cast(me).activate();
|
||||
|
||||
create(my_room, me);
|
||||
create(conf_room, me);
|
||||
|
|
|
@ -421,7 +421,7 @@ try
|
|||
}
|
||||
else if(typing && was_typing)
|
||||
{
|
||||
auto &t(const_cast<typist &>(*it));
|
||||
auto &t(mutable_cast(*it));
|
||||
t.timesout = calc_timesout(timeout);
|
||||
}
|
||||
else if(!typing && was_typing)
|
||||
|
|
|
@ -277,7 +277,7 @@ try
|
|||
// We have to set the event_id in the event instance if it didn't come
|
||||
// with the event JSON.
|
||||
if(!opts.edu && !event.event_id)
|
||||
const_cast<m::event &>(event).event_id = eval.room_version == "3"?
|
||||
mutable_cast(event).event_id = eval.room_version == "3"?
|
||||
event::id{event::id::v3{eval.event_id, event}}:
|
||||
event::id{event::id::v4{eval.event_id, event}};
|
||||
|
||||
|
@ -285,7 +285,7 @@ try
|
|||
// it so other contexts don't see an invalid reference.
|
||||
const unwind restore_event_id{[&event]
|
||||
{
|
||||
const_cast<m::event &>(event).event_id = json::get<"event_id"_>(event)?
|
||||
mutable_cast(event).event_id = json::get<"event_id"_>(event)?
|
||||
event.event_id:
|
||||
m::event::id{};
|
||||
}};
|
||||
|
|
Loading…
Reference in a new issue