Skip to content

Commit 3d9f028

Browse files
committed
Squashed 'src/univalue/' changes from dac5296..98261b1
98261b1 Merge bitcoin#22: Clamp JSON object depth to PHP limit 54c4015 Clamp JSON object depth to PHP limit 5a58a46 Merge bitcoin#21: Remove hand-coded UniValue destructor. b4cdfc4 Remove hand-coded UniValue destructor. 7fba60b Merge bitcoin#17: [docs] Update readme 4577454 Merge #13: Fix typo ac7e73c [docs] Update readme 7890db9 Merge #11: Remove deprecated std pair wrappers 40e3485 Merge #14: Cleaned up namespace imports to reduce symbol collisions 4a49647 Fix typo 85052a4 Remove deprecated std::pair wrappers 51d3ab3 Merge #10: Add pushKV(key, boolean) function (replaces #5) 129bad9 [tests] test pushKV for boolean values b3c44c9 Pushing boolean value to univalue correctly 07947ff Merge #9: [tests] Fix BOOST_CHECK_THROW macro ec849d9 [tests] Fix BOOST_CHECK_THROW macro d208f98 Cleaned up namespace imports to reduce symbol collisions 31bc9f5 Merge #8: Remove unused Homebrew workaround fa04209 Remove HomeBrew workaround a523e08 Merge #7: Declare single-argument (non-converting) constructors "explicit" a9e53b3 Merge #4: Pull upstream fe805ea Declare single-argument (non-converting) constructors "explicit" 8a2d6f1 Merge pull request bitcoin#41 from jgarzik/get-obj-map ba341a2 Add getObjMap() helper method. Also, constify checkObject(). ceb1194 Handle .pushKV() and .checkObject() edge cases. 107db98 Add ::push_back(double) method for feature parity. d415300 Move one-line implementation of UniValue::read() to header. 52e85b3 Move exception-throwing get_* methods into separate implementation module. 16a1f7f Merge #3: Pull upstream daf1285 Merge pull request #2 from jgarzik/master f32df99 Merge branch '2016_04_unicode' into bitcoin 280b191 Merge remote-tracking branch 'jgarzik/master' into bitcoin 2740c4f Merge branch '2015_11_escape_plan' into bitcoin git-subtree-dir: src/univalue git-subtree-split: 98261b1
1 parent ef1718b commit 3d9f028

File tree

14 files changed

+283
-272
lines changed

14 files changed

+283
-272
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ addons:
2525
- pkg-config
2626

2727
before_script:
28-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew uninstall libtool; brew install libtool; fi
2928
- if [ -n "$USE_SHELL" ]; then export CONFIG_SHELL="$USE_SHELL"; fi
3029
- test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh
3130

Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pkgconfig_DATA = pc/libunivalue.pc
1212

1313
libunivalue_la_SOURCES = \
1414
lib/univalue.cpp \
15+
lib/univalue_get.cpp \
1516
lib/univalue_read.cpp \
1617
lib/univalue_write.cpp
1718

@@ -94,6 +95,7 @@ TEST_FILES = \
9495
$(TEST_DATA_DIR)/fail41.json \
9596
$(TEST_DATA_DIR)/fail42.json \
9697
$(TEST_DATA_DIR)/fail44.json \
98+
$(TEST_DATA_DIR)/fail45.json \
9799
$(TEST_DATA_DIR)/fail3.json \
98100
$(TEST_DATA_DIR)/fail4.json \
99101
$(TEST_DATA_DIR)/fail5.json \
@@ -104,6 +106,7 @@ TEST_FILES = \
104106
$(TEST_DATA_DIR)/pass1.json \
105107
$(TEST_DATA_DIR)/pass2.json \
106108
$(TEST_DATA_DIR)/pass3.json \
109+
$(TEST_DATA_DIR)/pass4.json \
107110
$(TEST_DATA_DIR)/round1.json \
108111
$(TEST_DATA_DIR)/round2.json \
109112
$(TEST_DATA_DIR)/round3.json \

README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,10 @@ an arbitrary depth.
1212
This class is aligned with the JSON standard, [RFC
1313
7159](https://tools.ietf.org/html/rfc7159.html).
1414

15-
## Installation
15+
## Library usage
1616

17-
This project is a standard GNU
18-
[autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html)
19-
project. Build and install instructions are available in the `INSTALL`
20-
file provided with GNU autotools.
21-
22-
```
23-
$ ./autogen.sh
24-
$ ./configure
25-
$ make
26-
```
27-
28-
## Design
29-
30-
UniValue provides a single dynamic RAII C++ object class,
31-
and minimizes template use (contra json_spirit).
17+
This is a fork of univalue used by Bitcoin Core. It is not maintained for usage
18+
by other projects. Notably, the API may break in non-backward-compatible ways.
3219

20+
Other projects looking for a maintained library should use the upstream
21+
univalue at https://github.com/jgarzik/univalue.

gen/gen.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <string.h>
1313
#include "univalue.h"
1414

15-
using namespace std;
16-
1715
static bool initEscapes;
1816
static std::string escapes[256];
1917

include/univalue.h

Lines changed: 13 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
#define __UNIVALUE_H__
88

99
#include <stdint.h>
10+
#include <string.h>
1011

1112
#include <string>
1213
#include <vector>
1314
#include <map>
1415
#include <cassert>
1516

1617
#include <sstream> // .get_int64()
17-
#include <utility> // std::pair
1818

1919
class UniValue {
2020
public:
@@ -47,7 +47,6 @@ class UniValue {
4747
std::string s(val_);
4848
setStr(s);
4949
}
50-
~UniValue() {}
5150

5251
void clear();
5352

@@ -69,7 +68,8 @@ class UniValue {
6968
size_t size() const { return values.size(); }
7069

7170
bool getBool() const { return isTrue(); }
72-
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes);
71+
void getObjMap(std::map<std::string,UniValue>& kv) const;
72+
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
7373
const UniValue& operator[](const std::string& key) const;
7474
const UniValue& operator[](size_t index) const;
7575
bool exists(const std::string& key) const { size_t i; return findKey(key, i); }
@@ -104,8 +104,13 @@ class UniValue {
104104
UniValue tmpVal(val_);
105105
return push_back(tmpVal);
106106
}
107+
bool push_back(double val_) {
108+
UniValue tmpVal(val_);
109+
return push_back(tmpVal);
110+
}
107111
bool push_backV(const std::vector<UniValue>& vec);
108112

113+
void __pushKV(const std::string& key, const UniValue& val);
109114
bool pushKV(const std::string& key, const UniValue& val);
110115
bool pushKV(const std::string& key, const std::string& val_) {
111116
UniValue tmpVal(VSTR, val_);
@@ -123,6 +128,10 @@ class UniValue {
123128
UniValue tmpVal(val_);
124129
return pushKV(key, tmpVal);
125130
}
131+
bool pushKV(const std::string& key, bool val_) {
132+
UniValue tmpVal((bool)val_);
133+
return pushKV(key, tmpVal);
134+
}
126135
bool pushKV(const std::string& key, int val_) {
127136
UniValue tmpVal((int64_t)val_);
128137
return pushKV(key, tmpVal);
@@ -137,7 +146,7 @@ class UniValue {
137146
unsigned int indentLevel = 0) const;
138147

139148
bool read(const char *raw, size_t len);
140-
bool read(const char *raw);
149+
bool read(const char *raw) { return read(raw, strlen(raw)); }
141150
bool read(const std::string& rawStr) {
142151
return read(rawStr.data(), rawStr.size());
143152
}
@@ -166,76 +175,9 @@ class UniValue {
166175
const UniValue& get_array() const;
167176

168177
enum VType type() const { return getType(); }
169-
bool push_back(std::pair<std::string,UniValue> pear) {
170-
return pushKV(pear.first, pear.second);
171-
}
172178
friend const UniValue& find_value( const UniValue& obj, const std::string& name);
173179
};
174180

175-
//
176-
// The following were added for compatibility with json_spirit.
177-
// Most duplicate other methods, and should be removed.
178-
//
179-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, const char *cVal)
180-
{
181-
std::string key(cKey);
182-
UniValue uVal(cVal);
183-
return std::make_pair(key, uVal);
184-
}
185-
186-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, std::string strVal)
187-
{
188-
std::string key(cKey);
189-
UniValue uVal(strVal);
190-
return std::make_pair(key, uVal);
191-
}
192-
193-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, uint64_t u64Val)
194-
{
195-
std::string key(cKey);
196-
UniValue uVal(u64Val);
197-
return std::make_pair(key, uVal);
198-
}
199-
200-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, int64_t i64Val)
201-
{
202-
std::string key(cKey);
203-
UniValue uVal(i64Val);
204-
return std::make_pair(key, uVal);
205-
}
206-
207-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, bool iVal)
208-
{
209-
std::string key(cKey);
210-
UniValue uVal(iVal);
211-
return std::make_pair(key, uVal);
212-
}
213-
214-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, int iVal)
215-
{
216-
std::string key(cKey);
217-
UniValue uVal(iVal);
218-
return std::make_pair(key, uVal);
219-
}
220-
221-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, double dVal)
222-
{
223-
std::string key(cKey);
224-
UniValue uVal(dVal);
225-
return std::make_pair(key, uVal);
226-
}
227-
228-
static inline std::pair<std::string,UniValue> Pair(const char *cKey, const UniValue& uVal)
229-
{
230-
std::string key(cKey);
231-
return std::make_pair(key, uVal);
232-
}
233-
234-
static inline std::pair<std::string,UniValue> Pair(std::string key, const UniValue& uVal)
235-
{
236-
return std::make_pair(key, uVal);
237-
}
238-
239181
enum jtokentype {
240182
JTOK_ERR = -1,
241183
JTOK_NONE = 0, // eof

0 commit comments

Comments
 (0)