Page MenuHomePhabricator

D2932.diff
No OneTemporary

D2932.diff

diff --git a/src/addrman.h b/src/addrman.h
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -55,7 +55,7 @@
template <typename Stream, typename Operation>
inline void SerializationOp(Stream &s, Operation ser_action) {
- READWRITE(*static_cast<CAddress *>(this));
+ READWRITEAS(CAddress, *this);
READWRITE(source);
READWRITE(nLastSuccess);
READWRITE(nAttempts);
diff --git a/src/primitives/block.h b/src/primitives/block.h
--- a/src/primitives/block.h
+++ b/src/primitives/block.h
@@ -77,7 +77,7 @@
template <typename Stream, typename Operation>
inline void SerializationOp(Stream &s, Operation ser_action) {
- READWRITE(*static_cast<CBlockHeader *>(this));
+ READWRITEAS(CBlockHeader, *this);
READWRITE(vtx);
}
diff --git a/src/protocol.h b/src/protocol.h
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -396,7 +396,7 @@
uint64_t nServicesInt = nServices;
READWRITE(nServicesInt);
nServices = static_cast<ServiceFlags>(nServicesInt);
- READWRITE(*static_cast<CService *>(this));
+ READWRITEAS(CService, *this);
}
// TODO: make private (improves encapsulation)
diff --git a/src/script/script.h b/src/script/script.h
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -433,7 +433,7 @@
template <typename Stream, typename Operation>
inline void SerializationOp(Stream &s, Operation ser_action) {
- READWRITE(static_cast<CScriptBase &>(*this));
+ READWRITEAS(CScriptBase, *this);
}
CScript &operator+=(const CScript &b) {
diff --git a/src/serialize.h b/src/serialize.h
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -152,7 +152,18 @@
SER_GETHASH = (1 << 2),
};
+//! Convert the reference base type to X, without changing constness or
+//! reference type.
+template <typename X> X &ReadWriteAsHelper(X &x) {
+ return x;
+}
+template <typename X> const X &ReadWriteAsHelper(const X &x) {
+ return x;
+}
+
#define READWRITE(...) (::SerReadWriteMany(s, ser_action, __VA_ARGS__))
+#define READWRITEAS(type, obj) \
+ (::SerReadWriteMany(s, ser_action, ReadWriteAsHelper<type>(obj)))
/**
* Implement three methods for serializable objects. These are actually wrappers
diff --git a/src/txdb.h b/src/txdb.h
--- a/src/txdb.h
+++ b/src/txdb.h
@@ -50,7 +50,7 @@
template <typename Stream, typename Operation>
inline void SerializationOp(Stream &s, Operation ser_action) {
- READWRITE(*static_cast<CDiskBlockPos *>(this));
+ READWRITEAS(CDiskBlockPos, *this);
READWRITE(VARINT(nTxOffset));
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -386,7 +386,7 @@
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
}
- s << *static_cast<const CMerkleTx *>(this);
+ s << static_cast<const CMerkleTx &>(*this);
//!< Used to be vtxPrev
std::vector<CMerkleTx> vUnused;
s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime
@@ -397,7 +397,7 @@
Init(nullptr);
char fSpent;
- s >> *static_cast<CMerkleTx *>(this);
+ s >> static_cast<CMerkleTx &>(*this);
//!< Used to be vtxPrev
std::vector<CMerkleTx> vUnused;
s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >>

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 26, 11:36 (16 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5570853
Default Alt Text
D2932.diff (3 KB)

Event Timeline