Removing all stdout, stderr from main library. (#455)

* Removing all stdout,stderr from main library.
This commit is contained in:
Daniel Lemire 2020-01-20 16:03:15 -05:00 committed by GitHub
parent 48530b89ea
commit 80b4dd2e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 123 deletions

View File

@ -107,9 +107,9 @@ jsonparse_functype* get_jsonparse_func(const Architecture architecture) {
struct json_parser { struct json_parser {
const Architecture architecture; const Architecture architecture;
const stage1_functype *stage1_func; stage1_functype *stage1_func;
const stage2_functype *stage2_func; stage2_functype *stage2_func;
const jsonparse_functype *jsonparse_func; jsonparse_functype *jsonparse_func;
json_parser(const Architecture _architecture) : architecture(_architecture) { json_parser(const Architecture _architecture) : architecture(_architecture) {
this->stage1_func = get_stage1_func(architecture); this->stage1_func = get_stage1_func(architecture);

19
extra/dumpbits.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef DUMPBITS_H
#define DUMPBITS_H
#include <iostream>
// dump bits low to high
inline void dumpbits_always(uint64_t v, const std::string &msg) {
for (uint32_t i = 0; i < 64; i++) {
std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) ? "1" : "_");
}
std::cout << " " << msg.c_str() << "\n";
}
inline void dumpbits32_always(uint32_t v, const std::string &msg) {
for (uint32_t i = 0; i < 32; i++) {
std::cout << (((v >> i) & 0x1ULL) ? "1" : "_");
}
std::cout << " " << msg.c_str() << "\n";
}
#endif

View File

@ -1,53 +1,11 @@
#ifndef SIMDJSON_JSONFORMATUTILS_H #ifndef SIMDJSON_JSONFORMATUTILS_H
#define SIMDJSON_JSONFORMATUTILS_H #define SIMDJSON_JSONFORMATUTILS_H
#include <cstdio>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
namespace simdjson { namespace simdjson {
// ends with zero char
static inline void print_with_escapes(const unsigned char *src) {
while (*src) {
switch (*src) {
case '\b':
putchar('\\');
putchar('b');
break;
case '\f':
putchar('\\');
putchar('f');
break;
case '\n':
putchar('\\');
putchar('n');
break;
case '\r':
putchar('\\');
putchar('r');
break;
case '\"':
putchar('\\');
putchar('"');
break;
case '\t':
putchar('\\');
putchar('t');
break;
case '\\':
putchar('\\');
putchar('\\');
break;
default:
if (*src <= 0x1F) {
printf("\\u%04x", *src);
} else {
putchar(*src);
}
}
src++;
}
}
// ends with zero char // ends with zero char
static inline void print_with_escapes(const unsigned char *src, static inline void print_with_escapes(const unsigned char *src,
@ -96,49 +54,6 @@ static inline void print_with_escapes(const unsigned char *src,
} }
} }
// print len chars
static inline void print_with_escapes(const unsigned char *src, size_t len) {
const unsigned char *finalsrc = src + len;
while (src < finalsrc) {
switch (*src) {
case '\b':
putchar('\\');
putchar('b');
break;
case '\f':
putchar('\\');
putchar('f');
break;
case '\n':
putchar('\\');
putchar('n');
break;
case '\r':
putchar('\\');
putchar('r');
break;
case '\"':
putchar('\\');
putchar('"');
break;
case '\t':
putchar('\\');
putchar('t');
break;
case '\\':
putchar('\\');
putchar('\\');
break;
default:
if (*src <= 0x1F) {
printf("\\u%04x", *src);
} else {
putchar(*src);
}
}
src++;
}
}
// print len chars // print len chars
static inline void print_with_escapes(const unsigned char *src, static inline void print_with_escapes(const unsigned char *src,

View File

@ -4,7 +4,6 @@
#include "simdjson/common_defs.h" #include "simdjson/common_defs.h"
#include "simdjson/simdjson.h" #include "simdjson/simdjson.h"
#include <cstring> #include <cstring>
#include <iostream>
#include <memory> #include <memory>
#define JSON_VALUE_MASK 0xFFFFFFFFFFFFFF #define JSON_VALUE_MASK 0xFFFFFFFFFFFFFF
@ -53,7 +52,7 @@ public:
// this should be called when parsing (right before writing the tapes) // this should be called when parsing (right before writing the tapes)
void init(); void init();
// print the json to stdout (should be valid) // print the json to std::ostream (should be valid)
// return false if the tape is likely wrong (e.g., you did not parse a valid // return false if the tape is likely wrong (e.g., you did not parse a valid
// JSON). // JSON).
WARN_UNUSED WARN_UNUSED
@ -137,19 +136,6 @@ public:
}; };
// dump bits low to high
inline void dumpbits_always(uint64_t v, const std::string &msg) {
for (uint32_t i = 0; i < 64; i++) {
std::cout << (((v >> static_cast<uint64_t>(i)) & 0x1ULL) ? "1" : "_");
}
std::cout << " " << msg.c_str() << "\n";
}
inline void dumpbits32_always(uint32_t v, const std::string &msg) {
for (uint32_t i = 0; i < 32; i++) {
std::cout << (((v >> i) & 0x1ULL) ? "1" : "_");
}
std::cout << " " << msg.c_str() << "\n";
}
} // namespace simdjson } // namespace simdjson
#endif #endif

View File

@ -3,7 +3,6 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <cstdlib> #include <cstdlib>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <iso646.h> #include <iso646.h>

View File

@ -369,9 +369,6 @@ really_inline void json_structural_scanner::scan(const uint8_t *buf, const size_
template<size_t STEP_SIZE> template<size_t STEP_SIZE>
int find_structural_bits(const uint8_t *buf, size_t len, simdjson::ParsedJson &pj, bool streaming) { int find_structural_bits(const uint8_t *buf, size_t len, simdjson::ParsedJson &pj, bool streaming) {
if (unlikely(len > pj.byte_capacity)) { if (unlikely(len > pj.byte_capacity)) {
std::cerr << "Your ParsedJson object only supports documents up to "
<< pj.byte_capacity << " bytes but you are trying to process "
<< len << " bytes" << std::endl;
return simdjson::CAPACITY; return simdjson::CAPACITY;
} }
utf8_checker utf8_checker{}; utf8_checker utf8_checker{};

View File

@ -75,7 +75,7 @@ int json_parse_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj,
break; break;
#endif #endif
default: default:
std::cerr << "The processor is not supported by simdjson." << std::endl; // The processor is not supported by simdjson.
return simdjson::UNEXPECTED_ERROR; return simdjson::UNEXPECTED_ERROR;
} }
@ -91,9 +91,7 @@ ParsedJson build_parsed_json(const uint8_t *buf, size_t len,
bool ok = pj.allocate_capacity(len); bool ok = pj.allocate_capacity(len);
if (ok) { if (ok) {
json_parse(buf, len, pj, realloc); json_parse(buf, len, pj, realloc);
} else { }
std::cerr << "failure during memory allocation " << std::endl;
}
return pj; return pj;
} }
} // namespace simdjson } // namespace simdjson

View File

@ -232,7 +232,6 @@ void find_the_best_supported_implementation() {
return; return;
} }
#endif #endif
std::cerr << "The processor is not supported by simdjson." << std::endl;
// we throw an exception since this should not be recoverable // we throw an exception since this should not be recoverable
throw new std::runtime_error("unsupported architecture"); throw new std::runtime_error("unsupported architecture");
} }

View File

@ -45,7 +45,7 @@ bool ParsedJson::allocate_capacity(size_t len, size_t max_depth) {
if (!string_buf || !tape || if (!string_buf || !tape ||
!containing_scope_offset || !ret_address || !containing_scope_offset || !ret_address ||
!structural_indexes) { !structural_indexes) {
std::cerr << "Could not allocate memory" << std::endl; // Could not allocate memory
return false; return false;
} }
/* /*
@ -102,13 +102,11 @@ bool ParsedJson::print_json(std::ostream &os) const {
if (type == 'r') { if (type == 'r') {
how_many = tape_val & JSON_VALUE_MASK; how_many = tape_val & JSON_VALUE_MASK;
} else { } else {
fprintf(stderr, "Error: no starting root node?"); // Error: no starting root node?
return false; return false;
} }
if (how_many > tape_capacity) { if (how_many > tape_capacity) {
fprintf( // We may be exceeding the tape capacity. Is this a valid document?
stderr,
"We may be exceeding the tape capacity. Is this a valid document?\n");
return false; return false;
} }
tape_idx++; tape_idx++;
@ -195,10 +193,10 @@ bool ParsedJson::print_json(std::ostream &os) const {
os << ']'; os << ']';
break; break;
case 'r': // we start and end with the root node case 'r': // we start and end with the root node
fprintf(stderr, "should we be hitting the root node?\n"); // should we be hitting the root node?
return false; return false;
default: default:
fprintf(stderr, "bug %c\n", type); // bug?
return false; return false;
} }
} }
@ -220,7 +218,7 @@ bool ParsedJson::dump_raw_tape(std::ostream &os) const {
if (type == 'r') { if (type == 'r') {
how_many = tape_val & JSON_VALUE_MASK; how_many = tape_val & JSON_VALUE_MASK;
} else { } else {
fprintf(stderr, "Error: no starting root node?"); // Error: no starting root node?
return false; return false;
} }
os << "\t// pointing to " << how_many << " (right after last node)\n"; os << "\t// pointing to " << how_many << " (right after last node)\n";
@ -288,7 +286,7 @@ bool ParsedJson::dump_raw_tape(std::ostream &os) const {
<< " (start of the scope) \n"; << " (start of the scope) \n";
break; break;
case 'r': // we start and end with the root node case 'r': // we start and end with the root node
fprintf(stderr, "should we be hitting the root node?\n"); // should we be hitting the root node?
return false; return false;
default: default:
return false; return false;

View File

@ -1,6 +1,5 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <iostream>
#include "simdjson/portability.h" #include "simdjson/portability.h"
#include "simdjson/common_defs.h" #include "simdjson/common_defs.h"