Skip to content

Commit 80b4dd2

Browse files
authored
Removing all stdout, stderr from main library. (simdjson#455)
* Removing all stdout,stderr from main library.
1 parent 48530b8 commit 80b4dd2

File tree

10 files changed

+33
-123
lines changed

10 files changed

+33
-123
lines changed

benchmark/json_parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ jsonparse_functype* get_jsonparse_func(const Architecture architecture) {
107107

108108
struct json_parser {
109109
const Architecture architecture;
110-
const stage1_functype *stage1_func;
111-
const stage2_functype *stage2_func;
112-
const jsonparse_functype *jsonparse_func;
110+
stage1_functype *stage1_func;
111+
stage2_functype *stage2_func;
112+
jsonparse_functype *jsonparse_func;
113113

114114
json_parser(const Architecture _architecture) : architecture(_architecture) {
115115
this->stage1_func = get_stage1_func(architecture);

extra/dumpbits.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef DUMPBITS_H
2+
#define DUMPBITS_H
3+
#include <iostream>
4+
5+
// dump bits low to high
6+
inline void dumpbits_always(uint64_t v, const std::string &msg) {
7+
for (uint32_t i = 0; i < 64; i++) {
8+
std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) ? "1" : "_");
9+
}
10+
std::cout << " " << msg.c_str() << "\n";
11+
}
12+
13+
inline void dumpbits32_always(uint32_t v, const std::string &msg) {
14+
for (uint32_t i = 0; i < 32; i++) {
15+
std::cout << (((v >> i) & 0x1ULL) ? "1" : "_");
16+
}
17+
std::cout << " " << msg.c_str() << "\n";
18+
}
19+
#endif

include/simdjson/jsonformatutils.h

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,11 @@
11
#ifndef SIMDJSON_JSONFORMATUTILS_H
22
#define SIMDJSON_JSONFORMATUTILS_H
33

4-
#include <cstdio>
54
#include <iomanip>
65
#include <iostream>
76

87
namespace simdjson {
9-
// ends with zero char
10-
static inline void print_with_escapes(const unsigned char *src) {
11-
while (*src) {
12-
switch (*src) {
13-
case '\b':
14-
putchar('\\');
15-
putchar('b');
16-
break;
17-
case '\f':
18-
putchar('\\');
19-
putchar('f');
20-
break;
21-
case '\n':
22-
putchar('\\');
23-
putchar('n');
24-
break;
25-
case '\r':
26-
putchar('\\');
27-
putchar('r');
28-
break;
29-
case '\"':
30-
putchar('\\');
31-
putchar('"');
32-
break;
33-
case '\t':
34-
putchar('\\');
35-
putchar('t');
36-
break;
37-
case '\\':
38-
putchar('\\');
39-
putchar('\\');
40-
break;
41-
default:
42-
if (*src <= 0x1F) {
43-
printf("\\u%04x", *src);
44-
} else {
45-
putchar(*src);
46-
}
47-
}
48-
src++;
49-
}
50-
}
8+
519

5210
// ends with zero char
5311
static inline void print_with_escapes(const unsigned char *src,
@@ -96,49 +54,6 @@ static inline void print_with_escapes(const unsigned char *src,
9654
}
9755
}
9856

99-
// print len chars
100-
static inline void print_with_escapes(const unsigned char *src, size_t len) {
101-
const unsigned char *finalsrc = src + len;
102-
while (src < finalsrc) {
103-
switch (*src) {
104-
case '\b':
105-
putchar('\\');
106-
putchar('b');
107-
break;
108-
case '\f':
109-
putchar('\\');
110-
putchar('f');
111-
break;
112-
case '\n':
113-
putchar('\\');
114-
putchar('n');
115-
break;
116-
case '\r':
117-
putchar('\\');
118-
putchar('r');
119-
break;
120-
case '\"':
121-
putchar('\\');
122-
putchar('"');
123-
break;
124-
case '\t':
125-
putchar('\\');
126-
putchar('t');
127-
break;
128-
case '\\':
129-
putchar('\\');
130-
putchar('\\');
131-
break;
132-
default:
133-
if (*src <= 0x1F) {
134-
printf("\\u%04x", *src);
135-
} else {
136-
putchar(*src);
137-
}
138-
}
139-
src++;
140-
}
141-
}
14257

14358
// print len chars
14459
static inline void print_with_escapes(const unsigned char *src,

include/simdjson/parsedjson.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "simdjson/common_defs.h"
55
#include "simdjson/simdjson.h"
66
#include <cstring>
7-
#include <iostream>
87
#include <memory>
98

109
#define JSON_VALUE_MASK 0xFFFFFFFFFFFFFF
@@ -53,7 +52,7 @@ class ParsedJson {
5352
// this should be called when parsing (right before writing the tapes)
5453
void init();
5554

56-
// print the json to stdout (should be valid)
55+
// print the json to std::ostream (should be valid)
5756
// return false if the tape is likely wrong (e.g., you did not parse a valid
5857
// JSON).
5958
WARN_UNUSED
@@ -137,19 +136,6 @@ class ParsedJson {
137136

138137
};
139138

140-
// dump bits low to high
141-
inline void dumpbits_always(uint64_t v, const std::string &msg) {
142-
for (uint32_t i = 0; i < 64; i++) {
143-
std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) ? "1" : "_");
144-
}
145-
std::cout << " " << msg.c_str() << "\n";
146-
}
147139

148-
inline void dumpbits32_always(uint32_t v, const std::string &msg) {
149-
for (uint32_t i = 0; i < 32; i++) {
150-
std::cout << (((v >> i) & 0x1ULL) ? "1" : "_");
151-
}
152-
std::cout << " " << msg.c_str() << "\n";
153-
}
154140
} // namespace simdjson
155141
#endif

include/simdjson/portability.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <cstddef>
55
#include <cstdint>
6-
#include <cstdio>
76
#include <cstdlib>
87
#ifdef _MSC_VER
98
#include <iso646.h>

src/generic/stage1_find_marks.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,6 @@ really_inline void json_structural_scanner::scan(const uint8_t *buf, const size_
369369
template<size_t STEP_SIZE>
370370
int find_structural_bits(const uint8_t *buf, size_t len, simdjson::ParsedJson &pj, bool streaming) {
371371
if (unlikely(len > pj.byte_capacity)) {
372-
std::cerr << "Your ParsedJson object only supports documents up to "
373-
<< pj.byte_capacity << " bytes but you are trying to process "
374-
<< len << " bytes" << std::endl;
375372
return simdjson::CAPACITY;
376373
}
377374
utf8_checker utf8_checker{};

src/jsonparser.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int json_parse_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj,
7575
break;
7676
#endif
7777
default:
78-
std::cerr << "The processor is not supported by simdjson." << std::endl;
78+
// The processor is not supported by simdjson.
7979
return simdjson::UNEXPECTED_ERROR;
8080
}
8181

@@ -91,9 +91,7 @@ ParsedJson build_parsed_json(const uint8_t *buf, size_t len,
9191
bool ok = pj.allocate_capacity(len);
9292
if (ok) {
9393
json_parse(buf, len, pj, realloc);
94-
} else {
95-
std::cerr << "failure during memory allocation " << std::endl;
96-
}
94+
}
9795
return pj;
9896
}
9997
} // namespace simdjson

src/jsonstream.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ void find_the_best_supported_implementation() {
232232
return;
233233
}
234234
#endif
235-
std::cerr << "The processor is not supported by simdjson." << std::endl;
236235
// we throw an exception since this should not be recoverable
237236
throw new std::runtime_error("unsupported architecture");
238237
}

src/parsedjson.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool ParsedJson::allocate_capacity(size_t len, size_t max_depth) {
4545
if (!string_buf || !tape ||
4646
!containing_scope_offset || !ret_address ||
4747
!structural_indexes) {
48-
std::cerr << "Could not allocate memory" << std::endl;
48+
// Could not allocate memory
4949
return false;
5050
}
5151
/*
@@ -102,13 +102,11 @@ bool ParsedJson::print_json(std::ostream &os) const {
102102
if (type == 'r') {
103103
how_many = tape_val & JSON_VALUE_MASK;
104104
} else {
105-
fprintf(stderr, "Error: no starting root node?");
105+
// Error: no starting root node?
106106
return false;
107107
}
108108
if (how_many > tape_capacity) {
109-
fprintf(
110-
stderr,
111-
"We may be exceeding the tape capacity. Is this a valid document?\n");
109+
// We may be exceeding the tape capacity. Is this a valid document?
112110
return false;
113111
}
114112
tape_idx++;
@@ -195,10 +193,10 @@ bool ParsedJson::print_json(std::ostream &os) const {
195193
os << ']';
196194
break;
197195
case 'r': // we start and end with the root node
198-
fprintf(stderr, "should we be hitting the root node?\n");
196+
// should we be hitting the root node?
199197
return false;
200198
default:
201-
fprintf(stderr, "bug %c\n", type);
199+
// bug?
202200
return false;
203201
}
204202
}
@@ -220,7 +218,7 @@ bool ParsedJson::dump_raw_tape(std::ostream &os) const {
220218
if (type == 'r') {
221219
how_many = tape_val & JSON_VALUE_MASK;
222220
} else {
223-
fprintf(stderr, "Error: no starting root node?");
221+
// Error: no starting root node?
224222
return false;
225223
}
226224
os << "\t// pointing to " << how_many << " (right after last node)\n";
@@ -288,7 +286,7 @@ bool ParsedJson::dump_raw_tape(std::ostream &os) const {
288286
<< " (start of the scope) \n";
289287
break;
290288
case 'r': // we start and end with the root node
291-
fprintf(stderr, "should we be hitting the root node?\n");
289+
// should we be hitting the root node?
292290
return false;
293291
default:
294292
return false;

src/stage2_build_tape.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <cassert>
22
#include <cstring>
3-
#include <iostream>
43

54
#include "simdjson/portability.h"
65
#include "simdjson/common_defs.h"

0 commit comments

Comments
 (0)