jade
0cc285f87b
Fixes:
- Identifiers starting with _ are prohibited
- Some driveby header dependency cleaning which wound up with doing some
extra fixups.
- Fucking C style casts, man. C++ made these 1000% worse by letting you
also do memory corruption with them with references.
- Remove casts to Expr * where ExprBlackHole is an incomplete type by
introducing an explicitly-cast eBlackHoleAddr as Expr *.
- An incredibly illegal cast of the text bytes of the StorePath hash
into a size_t directly. You can't DO THAT.
Replaced with actually parsing the hash so we get 100% of the bits
being entropy, then memcpying the start of the hash. If this shows
up in a profile we should just make the hash parser faster with a
lookup table or something sensible like that.
- This horrendous bit of UB which I thankfully slapped a deprecation
warning on, built, and it didn't trigger anywhere so it was dead
code and I just deleted it. But holy crap you *cannot* do that.
inline void mkString(const Symbol & s)
{
mkString(((const std::string &) s).c_str());
}
- Some wrong lints. Lots of wrong macro lints, one wrong
suspicious-sizeof lint triggered by the template being instantiated
with only pointers, but the calculation being correct for both
pointers and not-pointers.
- Exceptions in destructors strike again. I tried to catch the
exceptions that might actually happen rather than all the exceptions
imaginable. We can let the runtime hard-kill it on other exceptions
imo.
Change-Id: I71761620846cba64d66ee7ca231b20c061e69710
62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
#pragma once
|
|
/**
|
|
* @file
|
|
*
|
|
* Template implementations (as opposed to mere declarations).
|
|
*
|
|
* This file is an exmample of the "impl.hh" pattern. See the
|
|
* contributing guide.
|
|
*/
|
|
|
|
#include "serve-protocol.hh"
|
|
#include "length-prefixed-protocol-helper.hh"
|
|
|
|
namespace nix {
|
|
|
|
/* protocol-agnostic templates */
|
|
|
|
#define SERVE_USE_LENGTH_PREFIX_SERIALISER(TEMPLATE, T) \
|
|
TEMPLATE T ServeProto::Serialise< T >::read(const Store & store, ServeProto::ReadConn conn) \
|
|
{ \
|
|
return LengthPrefixedProtoHelper<ServeProto, T >::read(store, conn); \
|
|
} \
|
|
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
|
|
TEMPLATE [[nodiscard]] WireFormatGenerator ServeProto::Serialise< T >::write(const Store & store, ServeProto::WriteConn conn, const T & t) \
|
|
{ \
|
|
return LengthPrefixedProtoHelper<ServeProto, T >::write(store, conn, t); \
|
|
}
|
|
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::vector<T>)
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::set<T>)
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename... Ts>, std::tuple<Ts...>)
|
|
|
|
#define COMMA_ ,
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(
|
|
template<typename K COMMA_ typename V>,
|
|
std::map<K COMMA_ V>)
|
|
#undef COMMA_
|
|
|
|
/**
|
|
* Use `CommonProto` where possible.
|
|
*/
|
|
template<typename T>
|
|
struct ServeProto::Serialise
|
|
{
|
|
static T read(const Store & store, ServeProto::ReadConn conn)
|
|
{
|
|
return CommonProto::Serialise<T>::read(store,
|
|
CommonProto::ReadConn { .from = conn.from });
|
|
}
|
|
[[nodiscard]]
|
|
static WireFormatGenerator write(const Store & store, ServeProto::WriteConn conn, const T & t)
|
|
{
|
|
return CommonProto::Serialise<T>::write(store,
|
|
CommonProto::WriteConn {},
|
|
t);
|
|
}
|
|
};
|
|
|
|
/* protocol-specific templates */
|
|
|
|
}
|