More fixing.

This commit is contained in:
Daniel Lemire 2018-12-10 22:21:03 -05:00
parent 058eb917d1
commit e8d3d784ab
9 changed files with 14 additions and 5 deletions

View File

@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
}
BEST_TIME("json_parse despaced", json_parse((const u8*)buffer, minisize, pj2), true, memcpy(buffer, minibuffer, p.size()), repeat, volume, true);
free((void*)p.data());
free(buffer);
free(ast_buffer);
free(minibuffer);

View File

@ -229,6 +229,7 @@ int main(int argc, char *argv[]) {
if(dump) {
isok = isok && pj.dump_raw_tape(std::cout);
}
free((void*)p.data());
if (!isok) {
printf(" Parsing failed. \n ");
return EXIT_FAILURE;

View File

@ -121,6 +121,7 @@ int main(int argc, char *argv[]) {
void *state;
if(all) BEST_TIME("ultrajson ", (UJDecode(buffer, p.size(), NULL, &state) == NULL), false, memcpy(buffer, p.data(), p.size()), repeat, volume, true);
BEST_TIME("memcpy ", (memcpy(buffer, p.data(), p.size()) == buffer), true, , repeat, volume, true);
free((void*)p.data());
free(ast_buffer);
free(buffer);
}

View File

@ -26,12 +26,13 @@ char * allocate_padded_buffer(size_t length);
// throws exceptions in case of failure
// first element of the pair is a string (null terminated)
// whereas the second element is the length.
// caller is responsible to free (free std::pair<u8 *, size_t>.first)
// caller is responsible to free (free((void*)result.data())))
//
// throws an exception if the file cannot be opened, use try/catch
// try {
// p = get_corpus(filename);
// } catch (const std::exception& e) {
// free((void*)p.data());
// std::cout << "Could not load the file " << filename << std::endl;
// }
std::string_view get_corpus(std::string filename);

View File

@ -25,9 +25,12 @@ std::string_view get_corpus(std::string filename) {
throw std::runtime_error("could not allocate memory");
}
std::rewind(fp);
std::fread(buf, 1, len, fp);
//buf[len] = '\0';// no need
size_t readb = std::fread(buf, 1, len, fp);
std::fclose(fp);
if(readb != len) {
free(buf);
throw std::runtime_error("could not read the data");
}
return std::string_view(buf,len);
}
throw std::runtime_error("could not load corpus");

View File

@ -108,7 +108,7 @@ int main(int argc, char *argv[]) {
printf("fastjson : %s \n", fastjson_correct ? "correct":"invalid");
printf("gason : %s \n", gason_correct ? "correct":"invalid");
printf("ultrajson : %s \n", ultrajson_correct ? "correct":"invalid");
free((void*)p.data());
free(buffer);
return EXIT_SUCCESS;
}

View File

@ -75,6 +75,7 @@ bool validate(const char *dirname) {
}
++howmany;
bool isok = json_parse(p, pj);
free((void*)p.data());
printf("%s\n", isok ? "ok" : "invalid");
if(contains("EXCLUDE",name)) {
// skipping

View File

@ -154,6 +154,7 @@ bool validate(const char *dirname) {
float_count, invalid_count,
int_count + float_count + invalid_count);
}
free((void*)p.data());
free(fullpath);
}
}

View File

@ -343,6 +343,7 @@ bool validate(const char *dirname) {
total_string_length = 0;
empty_string = 0;
bool isok = json_parse(p, pj);
free((void*)p.data());
if (good_string > 0) {
printf("File %40s %s --- bad strings: %10zu \tgood strings: %10zu\t "
"empty strings: %10zu "