Skip to content

Commit 86cc31d

Browse files
committed
Merge bitcoin/bitcoin#25249: Bump univalue subtree
025c6ca Squashed 'src/univalue/' changes from 6c19d050a9..de4f73ddca (MacroFake) 9b50a30 refactor: Replace get_int by getInt<int> alias (MacroFake) e4e8186 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 bitcoin/bitcoin#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 fa0cc61 fanquake: ACK fa0cc61 Tree-SHA512: 9ab9e371e6a745a80c441e99fb9cd407602a8066df883135e0ea7eced7b0c6ef0e9bc88f1d99a2b4804128d636727229f44d72b5615dbf2d70da4af63fa6adec
2 parents b752dad + fa0cc61 commit 86cc31d

File tree

5 files changed

+17
-78
lines changed

5 files changed

+17
-78
lines changed

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ static RPCHelpMan scantxoutset()
20852085
// no scan in progress
20862086
return NullUniValue;
20872087
}
2088-
result.pushKV("progress", g_scan_progress);
2088+
result.pushKV("progress", g_scan_progress.load());
20892089
return result;
20902090
} else if (request.params[0].get_str() == "abort") {
20912091
CoinsViewScanReserver reserver;

src/rpc/mempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ static RPCHelpMan gettxspendingprevout()
616616
}, /*fAllowNull=*/false, /*fStrict=*/true);
617617

618618
const uint256 txid(ParseHashO(o, "txid"));
619-
const int nOutput = find_value(o, "vout").get_int();
619+
const int nOutput{find_value(o, "vout").getInt<int>()};
620620
if (nOutput < 0) {
621621
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
622622
}

src/univalue/TODO

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/univalue/include/univalue.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -83,66 +83,10 @@ class UniValue {
8383
bool isObject() const { return (typ == VOBJ); }
8484

8585
bool push_back(const UniValue& val);
86-
bool push_back(const std::string& val_) {
87-
UniValue tmpVal(VSTR, val_);
88-
return push_back(tmpVal);
89-
}
90-
bool push_back(const char *val_) {
91-
std::string s(val_);
92-
return push_back(s);
93-
}
94-
bool push_back(uint64_t val_) {
95-
UniValue tmpVal(val_);
96-
return push_back(tmpVal);
97-
}
98-
bool push_back(int64_t val_) {
99-
UniValue tmpVal(val_);
100-
return push_back(tmpVal);
101-
}
102-
bool push_back(bool val_) {
103-
UniValue tmpVal(val_);
104-
return push_back(tmpVal);
105-
}
106-
bool push_back(int val_) {
107-
UniValue tmpVal(val_);
108-
return push_back(tmpVal);
109-
}
110-
bool push_back(double val_) {
111-
UniValue tmpVal(val_);
112-
return push_back(tmpVal);
113-
}
11486
bool push_backV(const std::vector<UniValue>& vec);
11587

11688
void __pushKV(const std::string& key, const UniValue& val);
11789
bool pushKV(const std::string& key, const UniValue& val);
118-
bool pushKV(const std::string& key, const std::string& val_) {
119-
UniValue tmpVal(VSTR, val_);
120-
return pushKV(key, tmpVal);
121-
}
122-
bool pushKV(const std::string& key, const char *val_) {
123-
std::string _val(val_);
124-
return pushKV(key, _val);
125-
}
126-
bool pushKV(const std::string& key, int64_t val_) {
127-
UniValue tmpVal(val_);
128-
return pushKV(key, tmpVal);
129-
}
130-
bool pushKV(const std::string& key, uint64_t val_) {
131-
UniValue tmpVal(val_);
132-
return pushKV(key, tmpVal);
133-
}
134-
bool pushKV(const std::string& key, bool val_) {
135-
UniValue tmpVal(val_);
136-
return pushKV(key, tmpVal);
137-
}
138-
bool pushKV(const std::string& key, int val_) {
139-
UniValue tmpVal((int64_t)val_);
140-
return pushKV(key, tmpVal);
141-
}
142-
bool pushKV(const std::string& key, double val_) {
143-
UniValue tmpVal(val_);
144-
return pushKV(key, tmpVal);
145-
}
14690
bool pushKVs(const UniValue& obj);
14791

14892
std::string write(unsigned int prettyIndent = 0,
@@ -185,8 +129,6 @@ class UniValue {
185129
}
186130
bool get_bool() const;
187131
const std::string& get_str() const;
188-
auto get_int() const { return getInt<int>(); };
189-
auto get_int64() const { return getInt<int64_t>(); };
190132
double get_real() const;
191133
const UniValue& get_obj() const;
192134
const UniValue& get_array() const;

src/univalue/test/object.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,30 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
9292
BOOST_CHECK(v1.isNum());
9393
BOOST_CHECK_THROW(v1.get_bool(), std::runtime_error);
9494

95+
{
96+
UniValue v_negative;
97+
BOOST_CHECK(v_negative.setNumStr("-1"));
98+
BOOST_CHECK_THROW(v_negative.getInt<uint8_t>(), std::runtime_error);
99+
BOOST_CHECK_EQUAL(v_negative.getInt<int8_t>(), -1);
100+
}
101+
95102
UniValue v2;
96103
BOOST_CHECK(v2.setBool(true));
97104
BOOST_CHECK_EQUAL(v2.get_bool(), true);
98-
BOOST_CHECK_THROW(v2.get_int(), std::runtime_error);
105+
BOOST_CHECK_THROW(v2.getInt<int>(), std::runtime_error);
99106

100107
UniValue v3;
101108
BOOST_CHECK(v3.setNumStr("32482348723847471234"));
102-
BOOST_CHECK_THROW(v3.get_int64(), std::runtime_error);
109+
BOOST_CHECK_THROW(v3.getInt<int64_t>(), std::runtime_error);
103110
BOOST_CHECK(v3.setNumStr("1000"));
104-
BOOST_CHECK_EQUAL(v3.get_int64(), 1000);
111+
BOOST_CHECK_EQUAL(v3.getInt<int64_t>(), 1000);
105112

106113
UniValue v4;
107114
BOOST_CHECK(v4.setNumStr("2147483648"));
108-
BOOST_CHECK_EQUAL(v4.get_int64(), 2147483648);
109-
BOOST_CHECK_THROW(v4.get_int(), std::runtime_error);
115+
BOOST_CHECK_EQUAL(v4.getInt<int64_t>(), 2147483648);
116+
BOOST_CHECK_THROW(v4.getInt<int>(), std::runtime_error);
110117
BOOST_CHECK(v4.setNumStr("1000"));
111-
BOOST_CHECK_EQUAL(v4.get_int(), 1000);
118+
BOOST_CHECK_EQUAL(v4.getInt<int>(), 1000);
112119
BOOST_CHECK_THROW(v4.get_str(), std::runtime_error);
113120
BOOST_CHECK_EQUAL(v4.get_real(), 1000);
114121
BOOST_CHECK_THROW(v4.get_array(), std::runtime_error);
@@ -120,10 +127,10 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
120127
BOOST_CHECK(v5.read("[true, 10]"));
121128
BOOST_CHECK_NO_THROW(v5.get_array());
122129
std::vector<UniValue> vals = v5.getValues();
123-
BOOST_CHECK_THROW(vals[0].get_int(), std::runtime_error);
130+
BOOST_CHECK_THROW(vals[0].getInt<int>(), std::runtime_error);
124131
BOOST_CHECK_EQUAL(vals[0].get_bool(), true);
125132

126-
BOOST_CHECK_EQUAL(vals[1].get_int(), 10);
133+
BOOST_CHECK_EQUAL(vals[1].getInt<int>(), 10);
127134
BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error);
128135
}
129136

0 commit comments

Comments
 (0)