Skip to content

Commit 8e2c06c

Browse files
committed
Compile with -fno-exceptions
1 parent 1a5d8f1 commit 8e2c06c

File tree

16 files changed

+279
-139
lines changed

16 files changed

+279
-139
lines changed

.drone.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,48 @@ steps:
4949
commands: [ make slowtests ]
5050
---
5151
kind: pipeline
52+
name: x64-noexceptions-quicktests
53+
54+
platform:
55+
os: linux
56+
arch: amd64
57+
58+
steps:
59+
- name: quicktests
60+
image: gcc:8
61+
environment:
62+
EXTRA_FLAGS: -fno-exceptions
63+
commands: [ make quicktests ]
64+
---
65+
kind: pipeline
66+
name: x64-noexceptions-build
67+
68+
platform:
69+
os: linux
70+
arch: amd64
71+
72+
steps:
73+
- name: build
74+
image: gcc:8
75+
environment:
76+
EXTRA_FLAGS: -fno-exceptions
77+
commands: [ make, make amalgamate ]
78+
---
79+
kind: pipeline
80+
name: x64-noexceptions-slowtests
81+
82+
platform:
83+
os: linux
84+
arch: amd64
85+
86+
steps:
87+
- name: slowtests
88+
image: gcc:8
89+
environment:
90+
EXTRA_FLAGS: -fno-exceptions
91+
commands: [ make slowtests ]
92+
---
93+
kind: pipeline
5294
name: arm64-quicktests
5395

5496
platform:

benchmark/benchmarker.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,6 @@ struct json_stats {
182182
}
183183
};
184184

185-
padded_string load_json(const char *filename) {
186-
try {
187-
verbose() << "[verbose] loading " << filename << endl;
188-
padded_string json = padded_string::load(filename);
189-
verbose() << "[verbose] loaded " << filename << " (" << json.size() << " bytes)" << endl;
190-
return json;
191-
} catch (const exception &) { // caught by reference to base
192-
exit_error(string("Could not load the file ") + filename);
193-
exit(EXIT_FAILURE); // This is not strictly necessary but removes the warning
194-
}
195-
}
196-
197185
struct progress_bar {
198186
int max_value;
199187
int total_ticks;
@@ -253,7 +241,7 @@ const char* benchmark_stage_name(BenchmarkStage stage) {
253241

254242
struct benchmarker {
255243
// JSON text from loading the file. Owns the memory.
256-
const padded_string json;
244+
padded_string json;
257245
// JSON filename
258246
const char *filename;
259247
// Event collector that can be turned on to measure cycles, missed branches, etc.
@@ -272,7 +260,15 @@ struct benchmarker {
272260
event_aggregate allocate_stage;
273261

274262
benchmarker(const char *_filename, event_collector& _collector)
275-
: json(load_json(_filename)), filename(_filename), collector(_collector), stats(NULL) {}
263+
: filename(_filename), collector(_collector), stats(NULL) {
264+
verbose() << "[verbose] loading " << filename << endl;
265+
simdjson::error_code error;
266+
std::tie(this->json, error) = padded_string::load(filename);
267+
if (error) {
268+
exit_error(string("Could not load the file ") + filename);
269+
}
270+
verbose() << "[verbose] loaded " << filename << endl;
271+
}
276272

277273
~benchmarker() {
278274
if (stats) {

benchmark/distinctuseridcompetition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ simdjson_just_dom(simdjson::document &doc) {
5959
__attribute__((noinline)) std::vector<int64_t>
6060
simdjson_compute_stats(const simdjson::padded_string &p) {
6161
std::vector<int64_t> answer;
62-
simdjson::document doc = simdjson::document::parse(p);
62+
auto [doc, error] = simdjson::document::parse(p);
6363
simdjson_scan(answer, doc);
6464
remove_duplicates(answer);
6565
return answer;
@@ -319,7 +319,7 @@ int main(int argc, char *argv[]) {
319319
volume, !just_data);
320320
BEST_TIME("sasjon (just parse) ", sasjon_just_parse(p), false, , repeat,
321321
volume, !just_data);
322-
simdjson::document dsimdjson = simdjson::document::parse(p);
322+
auto [dsimdjson, dsimdjson_error] = simdjson::document::parse(p);
323323
BEST_TIME("simdjson (just dom) ", simdjson_just_dom(dsimdjson).size(), size,
324324
, repeat, volume, !just_data);
325325
char *buffer = (char *)malloc(p.size());

benchmark/get_corpus_benchmark.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ never_inline
88
double bench(std::string filename, simdjson::padded_string& p) {
99
std::chrono::time_point<std::chrono::steady_clock> start_clock =
1010
std::chrono::steady_clock::now();
11-
simdjson::get_corpus(filename).swap(p);
11+
simdjson::padded_string::load(filename).first.swap(p);
1212
std::chrono::time_point<std::chrono::steady_clock> end_clock =
1313
std::chrono::steady_clock::now();
1414
std::chrono::duration<double> elapsed = end_clock - start_clock;
@@ -34,17 +34,21 @@ int main(int argc, char *argv[]) {
3434
double minval = 10000;
3535
std::cout << "file size: "<< (p.size() / (1024. * 1024 * 1024.)) << " GB" <<std::endl;
3636
size_t times = p.size() > 1024*1024*1024 ? 5 : 50;
37+
#if __cpp_exceptions
3738
try {
39+
#endif
3840
for(size_t i = 0; i < times; i++) {
3941
double tval = bench(filename, p);
4042
if(maxval < tval) maxval = tval;
4143
if(minval > tval) minval = tval;
4244
meanval += tval;
4345
}
46+
#if __cpp_exceptions
4447
} catch (const std::exception &) { // caught by reference to base
4548
std::cerr << "Could not load the file " << filename << std::endl;
4649
return EXIT_FAILURE;
4750
}
51+
#endif
4852
std::cout << "average speed: " << meanval / times << " GB/s"<< std::endl;
4953
std::cout << "min speed : " << minval << " GB/s" << std::endl;
5054
std::cout << "max speed : " << maxval << " GB/s" << std::endl;

dependencies/jsoncppdist/jsoncpp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,10 +2652,18 @@ char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
26522652
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
26532653
LogicError::LogicError(String const& msg) : Exception(msg) {}
26542654
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
2655+
#if __cpp_exceptions
26552656
throw RuntimeError(msg);
2657+
#else
2658+
abort();
2659+
#endif
26562660
}
26572661
JSONCPP_NORETURN void throwLogicError(String const& msg) {
2662+
#if __cpp_exceptions
26582663
throw LogicError(msg);
2664+
#else
2665+
abort();
2666+
#endif
26592667
}
26602668

26612669
// //////////////////////////////////////////////////////////////////

include/simdjson/common_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace simdjson {
88

99
#ifndef SIMDJSON_EXCEPTIONS
10-
#ifdef __cpp_exceptions
10+
#if __cpp_exceptions
1111
#define SIMDJSON_EXCEPTIONS 1
1212
#else
1313
#define SIMDJSON_EXCEPTIONS 0

include/simdjson/document.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,9 @@ inline std::ostream& operator<<(std::ostream& out, const document::object &value
16421642
* @throw if there is an error with the underlying output stream. simdjson itself will not throw.
16431643
*/
16441644
inline std::ostream& operator<<(std::ostream& out, const document::key_value_pair &value) { return out << minify(value); }
1645+
1646+
#if SIMDJSON_EXCEPTIONS
1647+
16451648
/**
16461649
* Print JSON to an output stream.
16471650
*
@@ -1703,6 +1706,8 @@ inline std::ostream& operator<<(std::ostream& out, const document::array_result
17031706
*/
17041707
inline std::ostream& operator<<(std::ostream& out, const document::object_result &value) noexcept(false) { return out << minify(value); }
17051708

1709+
#endif
1710+
17061711
} // namespace simdjson
17071712

17081713
#endif // SIMDJSON_DOCUMENT_H

include/simdjson/error.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SIMDJSON_ERROR_H
22
#define SIMDJSON_ERROR_H
33

4+
#include "simdjson/common_defs.h"
45
#include <string>
56
#include <utility>
67

@@ -76,6 +77,13 @@ struct simdjson_error : public std::exception {
7677
*/
7778
template<typename T>
7879
struct simdjson_result : public std::pair<T, error_code> {
80+
/**
81+
* The error.
82+
*/
83+
error_code error() const { return this->second; }
84+
85+
#if SIMDJSON_EXCEPTIONS
86+
7987
/**
8088
* The value of the function.
8189
*
@@ -86,18 +94,15 @@ struct simdjson_result : public std::pair<T, error_code> {
8694
return this->first;
8795
};
8896

89-
/**
90-
* The error.
91-
*/
92-
error_code error() const { return this->second; }
93-
9497
/**
9598
* Cast to the value (will throw on error).
9699
*
97100
* @throw simdjson_error if there was an error.
98101
*/
99102
operator T() noexcept(false) { return get(); }
100103

104+
#endif // SIMDJSON_EXCEPTIONS
105+
101106
/**
102107
* Create a new error result.
103108
*/
@@ -128,6 +133,8 @@ struct simdjson_move_result : std::pair<T, error_code> {
128133
*/
129134
error_code error() const { return this->second; }
130135

136+
#if SIMDJSON_EXCEPTIONS
137+
131138
/**
132139
* The value of the function.
133140
*
@@ -145,6 +152,8 @@ struct simdjson_move_result : std::pair<T, error_code> {
145152
*/
146153
operator T() noexcept(false) { return move(); }
147154

155+
#endif
156+
148157
/**
149158
* Create a new error result.
150159
*/

include/simdjson/inline/document.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,8 @@ inline std::ostream& minify<document::key_value_pair>::print(std::ostream& out)
991991
return out << '"' << internal::escape_json_string(value.key) << "\":" << value.value;
992992
}
993993

994+
#if SIMDJSON_EXCEPTIONS
995+
994996
template<>
995997
inline std::ostream& minify<document::doc_move_result>::print(std::ostream& out) {
996998
if (value.error()) { throw simdjson_error(value.error()); }
@@ -1017,6 +1019,8 @@ inline std::ostream& minify<document::object_result>::print(std::ostream& out) {
10171019
return out << minify<document::object>(value.first);
10181020
}
10191021

1022+
#endif
1023+
10201024
} // namespace simdjson
10211025

10221026
#endif // SIMDJSON_INLINE_DOCUMENT_H

include/simdjson/inline/document_iterator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ bool document_iterator<max_depth>::move_to(const char *pointer,
328328
uint32_t new_length = 0;
329329
for (uint32_t i = 1; i < length; i++) {
330330
if (pointer[i] == '%' && pointer[i + 1] == 'x') {
331+
#if __cpp_exceptions
331332
try {
333+
#endif
332334
int fragment =
333335
std::stoi(std::string(&pointer[i + 2], 2), nullptr, 16);
334336
if (fragment == '\\' || fragment == '"' || (fragment <= 0x1F)) {
@@ -338,10 +340,12 @@ bool document_iterator<max_depth>::move_to(const char *pointer,
338340
}
339341
new_pointer[new_length] = fragment;
340342
i += 3;
343+
#if __cpp_exceptions
341344
} catch (std::invalid_argument &) {
342345
delete[] new_pointer;
343346
return false; // the fragment is invalid
344347
}
348+
#endif
345349
} else {
346350
new_pointer[new_length] = pointer[i];
347351
}

0 commit comments

Comments
 (0)