aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2022-06-01 19:13:37 +0100
committerfanquake <fanquake@gmail.com>2022-06-01 19:13:43 +0100
commit86cc31dab6ba31a406a49f609124bc335c1a4d42 (patch)
treec9698523cb31c2ac7dbddd404ca429949d977082
parentb752dade048ced8227a9d205a708f50d58f99312 (diff)
parentfa0cc61b7f79b1844ac0fb3831e606a1ba861c15 (diff)
Merge bitcoin/bitcoin#25249: Bump univalue subtree
025c6ca509f9e3975505d9fd786a4ca73a3a3a2d Squashed 'src/univalue/' changes from 6c19d050a9..de4f73ddca (MacroFake) 9b50a309ff21b0d5d85ded8b67cb08ae2e75fe84 refactor: Replace get_int by getInt<int> alias (MacroFake) e4e8186ab41c897b8a849dba25ae44475fe60550 refactor: Explicitly convert atomic<int> to int (João Barbosa) Pull request description: This bumps the univalue subtree and changes two lines of our code. Apart from the get_int -> getInt change, this is mostly a rebase of https://github.com/bitcoin/bitcoin/pull/15975, which was closed back then. However, given the numerous UniValue copy bugs and performance regressions in the past years, I think it makes sense to finally go through with the changes and disable potentially expensive implicit UniValue copies, which may cause OOM. The changes here are not strictly required for that, but make future changes less verbose and easier to review. ACKs for top commit: laanwj: Code review ACK fa0cc61b7f79b1844ac0fb3831e606a1ba861c15 fanquake: ACK fa0cc61b7f79b1844ac0fb3831e606a1ba861c15 Tree-SHA512: 9ab9e371e6a745a80c441e99fb9cd407602a8066df883135e0ea7eced7b0c6ef0e9bc88f1d99a2b4804128d636727229f44d72b5615dbf2d70da4af63fa6adec
-rw-r--r--src/rpc/blockchain.cpp2
-rw-r--r--src/rpc/mempool.cpp2
-rw-r--r--src/univalue/TODO10
-rw-r--r--src/univalue/include/univalue.h58
-rw-r--r--src/univalue/test/object.cpp23
5 files changed, 17 insertions, 78 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 03354f39f6..f2186c131f 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -2085,7 +2085,7 @@ static RPCHelpMan scantxoutset()
// no scan in progress
return NullUniValue;
}
- result.pushKV("progress", g_scan_progress);
+ result.pushKV("progress", g_scan_progress.load());
return result;
} else if (request.params[0].get_str() == "abort") {
CoinsViewScanReserver reserver;
diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp
index 01c75bfda3..90dc86cd01 100644
--- a/src/rpc/mempool.cpp
+++ b/src/rpc/mempool.cpp
@@ -616,7 +616,7 @@ static RPCHelpMan gettxspendingprevout()
}, /*fAllowNull=*/false, /*fStrict=*/true);
const uint256 txid(ParseHashO(o, "txid"));
- const int nOutput = find_value(o, "vout").get_int();
+ const int nOutput{find_value(o, "vout").getInt<int>()};
if (nOutput < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
}
diff --git a/src/univalue/TODO b/src/univalue/TODO
deleted file mode 100644
index 5530048e92..0000000000
--- a/src/univalue/TODO
+++ /dev/null
@@ -1,10 +0,0 @@
-
-Rearrange tree for easier 'git subtree' style use
-
-Move towards C++11 etc.
-
-Namespace support - must come up with useful shorthand, avoiding
-long Univalue::Univalue::Univalue usages forced upon library users.
-
-Improve test suite
-
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h
index 35eaa2dd0d..f0d4de2035 100644
--- a/src/univalue/include/univalue.h
+++ b/src/univalue/include/univalue.h
@@ -83,66 +83,10 @@ public:
bool isObject() const { return (typ == VOBJ); }
bool push_back(const UniValue& val);
- bool push_back(const std::string& val_) {
- UniValue tmpVal(VSTR, val_);
- return push_back(tmpVal);
- }
- bool push_back(const char *val_) {
- std::string s(val_);
- return push_back(s);
- }
- bool push_back(uint64_t val_) {
- UniValue tmpVal(val_);
- return push_back(tmpVal);
- }
- bool push_back(int64_t val_) {
- UniValue tmpVal(val_);
- return push_back(tmpVal);
- }
- bool push_back(bool val_) {
- UniValue tmpVal(val_);
- return push_back(tmpVal);
- }
- bool push_back(int val_) {
- UniValue tmpVal(val_);
- return push_back(tmpVal);
- }
- bool push_back(double val_) {
- UniValue tmpVal(val_);
- return push_back(tmpVal);
- }
bool push_backV(const std::vector<UniValue>& vec);
void __pushKV(const std::string& key, const UniValue& val);
bool pushKV(const std::string& key, const UniValue& val);
- bool pushKV(const std::string& key, const std::string& val_) {
- UniValue tmpVal(VSTR, val_);
- return pushKV(key, tmpVal);
- }
- bool pushKV(const std::string& key, const char *val_) {
- std::string _val(val_);
- return pushKV(key, _val);
- }
- bool pushKV(const std::string& key, int64_t val_) {
- UniValue tmpVal(val_);
- return pushKV(key, tmpVal);
- }
- bool pushKV(const std::string& key, uint64_t val_) {
- UniValue tmpVal(val_);
- return pushKV(key, tmpVal);
- }
- bool pushKV(const std::string& key, bool val_) {
- UniValue tmpVal(val_);
- return pushKV(key, tmpVal);
- }
- bool pushKV(const std::string& key, int val_) {
- UniValue tmpVal((int64_t)val_);
- return pushKV(key, tmpVal);
- }
- bool pushKV(const std::string& key, double val_) {
- UniValue tmpVal(val_);
- return pushKV(key, tmpVal);
- }
bool pushKVs(const UniValue& obj);
std::string write(unsigned int prettyIndent = 0,
@@ -185,8 +129,6 @@ public:
}
bool get_bool() const;
const std::string& get_str() const;
- auto get_int() const { return getInt<int>(); };
- auto get_int64() const { return getInt<int64_t>(); };
double get_real() const;
const UniValue& get_obj() const;
const UniValue& get_array() const;
diff --git a/src/univalue/test/object.cpp b/src/univalue/test/object.cpp
index b9697a8cb7..8a35bf914d 100644
--- a/src/univalue/test/object.cpp
+++ b/src/univalue/test/object.cpp
@@ -92,23 +92,30 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
BOOST_CHECK(v1.isNum());
BOOST_CHECK_THROW(v1.get_bool(), std::runtime_error);
+ {
+ UniValue v_negative;
+ BOOST_CHECK(v_negative.setNumStr("-1"));
+ BOOST_CHECK_THROW(v_negative.getInt<uint8_t>(), std::runtime_error);
+ BOOST_CHECK_EQUAL(v_negative.getInt<int8_t>(), -1);
+ }
+
UniValue v2;
BOOST_CHECK(v2.setBool(true));
BOOST_CHECK_EQUAL(v2.get_bool(), true);
- BOOST_CHECK_THROW(v2.get_int(), std::runtime_error);
+ BOOST_CHECK_THROW(v2.getInt<int>(), std::runtime_error);
UniValue v3;
BOOST_CHECK(v3.setNumStr("32482348723847471234"));
- BOOST_CHECK_THROW(v3.get_int64(), std::runtime_error);
+ BOOST_CHECK_THROW(v3.getInt<int64_t>(), std::runtime_error);
BOOST_CHECK(v3.setNumStr("1000"));
- BOOST_CHECK_EQUAL(v3.get_int64(), 1000);
+ BOOST_CHECK_EQUAL(v3.getInt<int64_t>(), 1000);
UniValue v4;
BOOST_CHECK(v4.setNumStr("2147483648"));
- BOOST_CHECK_EQUAL(v4.get_int64(), 2147483648);
- BOOST_CHECK_THROW(v4.get_int(), std::runtime_error);
+ BOOST_CHECK_EQUAL(v4.getInt<int64_t>(), 2147483648);
+ BOOST_CHECK_THROW(v4.getInt<int>(), std::runtime_error);
BOOST_CHECK(v4.setNumStr("1000"));
- BOOST_CHECK_EQUAL(v4.get_int(), 1000);
+ BOOST_CHECK_EQUAL(v4.getInt<int>(), 1000);
BOOST_CHECK_THROW(v4.get_str(), std::runtime_error);
BOOST_CHECK_EQUAL(v4.get_real(), 1000);
BOOST_CHECK_THROW(v4.get_array(), std::runtime_error);
@@ -120,10 +127,10 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
BOOST_CHECK(v5.read("[true, 10]"));
BOOST_CHECK_NO_THROW(v5.get_array());
std::vector<UniValue> vals = v5.getValues();
- BOOST_CHECK_THROW(vals[0].get_int(), std::runtime_error);
+ BOOST_CHECK_THROW(vals[0].getInt<int>(), std::runtime_error);
BOOST_CHECK_EQUAL(vals[0].get_bool(), true);
- BOOST_CHECK_EQUAL(vals[1].get_int(), 10);
+ BOOST_CHECK_EQUAL(vals[1].getInt<int>(), 10);
BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error);
}