Skip to content

Commit

Permalink
Verbose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Feb 14, 2022
1 parent 6201661 commit a0db102
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -21,7 +21,7 @@ task :test_all => [:clean, :compile] do
exitcode = 0
status = 0

cmds = "ruby test/tests.rb && ruby test/tests_mimic.rb && ruby test/tests_mimic_addition.rb"
cmds = "ruby test/tests.rb -v && ruby test/tests_mimic.rb -v && ruby test/tests_mimic_addition.rb -v"
STDOUT.syswrite "\n#{'#'*90}\n#{cmds}\n"
Bundler.with_original_env do
status = system(cmds)
Expand Down
2 changes: 2 additions & 0 deletions ext/oj/dump.c
Expand Up @@ -635,6 +635,7 @@ void oj_write_obj_to_file(VALUE obj, const char *path, Options copts) {
}
}

#if !IS_WINDOWS
static void write_ready(int fd) {
struct pollfd pp;
int i;
Expand All @@ -649,6 +650,7 @@ static void write_ready(int fd) {
rb_raise(rb_eIOError, "write failed. %d %s.", errno, strerror(errno));
}
}
#endif

void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts) {
char buf[4096];
Expand Down
4 changes: 2 additions & 2 deletions ext/oj/fast.c
Expand Up @@ -771,7 +771,7 @@ static VALUE parse_json(VALUE clas, char *json, bool given, bool allocated) {
pi.doc = doc;
#if IS_WINDOWS
// assume a 1M stack and give half to ruby
pi.stack_min = (void *)((char *)&pi - (512 * 1024));
pi.stack_min = (void *)((char *)&pi - (512L * 1024L));
#else
{
struct rlimit lim;
Expand Down Expand Up @@ -1720,7 +1720,7 @@ static VALUE doc_not_implemented(VALUE self) {
void oj_init_doc(void) {
oj_doc_class = rb_define_class_under(Oj, "Doc", rb_cObject);
rb_gc_register_address(&oj_doc_class);
// rb_undef_alloc_func(oj_doc_class);
rb_undef_alloc_func(oj_doc_class);

rb_define_singleton_method(oj_doc_class, "open", doc_open, 1);
rb_define_singleton_method(oj_doc_class, "open_file", doc_open_file, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/intern.c
Expand Up @@ -90,7 +90,7 @@ void oj_hash_init(void) {
VALUE cache_class = rb_define_class_under(Oj, "Cache", rb_cObject);

rb_gc_register_address(&cache_class);
// rb_undef_alloc_func(cache_class);
rb_undef_alloc_func(cache_class);

str_cache = cache_create(0, form_str, true, true);
str_cache_obj = Data_Wrap_Struct(cache_class, cache_mark, cache_free, str_cache);
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/oj.c
Expand Up @@ -1752,7 +1752,7 @@ void Init_oj(void) {

oj_cstack_class = rb_define_class_under(Oj, "CStack", rb_cObject);
rb_gc_register_address(&oj_cstack_class);
// rb_undef_alloc_func(oj_cstack_class);
rb_undef_alloc_func(oj_cstack_class);

oj_string_writer_init();
oj_stream_writer_init();
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/parser.c
Expand Up @@ -1510,7 +1510,7 @@ static VALUE parser_validate(VALUE self) {
void oj_parser_init(void) {
parser_class = rb_define_class_under(Oj, "Parser", rb_cObject);
rb_gc_register_address(&parser_class);
// rb_undef_alloc_func(parser_class);
rb_undef_alloc_func(parser_class);

rb_define_module_function(parser_class, "new", parser_new, -1);
rb_define_method(parser_class, "parse", parser_parse, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/rails.c
Expand Up @@ -1182,7 +1182,7 @@ void oj_mimic_rails_init(void) {

encoder_class = rb_define_class_under(rails, "Encoder", rb_cObject);
rb_gc_register_address(&encoder_class);
// rb_undef_alloc_func(encoder_class);
rb_undef_alloc_func(encoder_class);

rb_define_module_function(encoder_class, "new", encoder_new, -1);
rb_define_module_function(rails, "optimize", rails_optimize, -1);
Expand Down
34 changes: 11 additions & 23 deletions ext/oj/saj.c
Expand Up @@ -210,10 +210,7 @@ static void read_hash(ParseInfo pi, const char *key) {
pi->s++;
} else {
if (pi->has_error) {
call_error("invalid format, expected , or } while in an object",
pi,
__FILE__,
__LINE__);
call_error("invalid format, expected , or } while in an object", pi, __FILE__, __LINE__);
}
raise_error("invalid format, expected , or } while in an object", pi->str, pi->s);
}
Expand Down Expand Up @@ -243,10 +240,7 @@ static void read_array(ParseInfo pi, const char *key) {
break;
} else {
if (pi->has_error) {
call_error("invalid format, expected , or ] while in an array",
pi,
__FILE__,
__LINE__);
call_error("invalid format, expected , or ] while in an array", pi, __FILE__, __LINE__);
}
raise_error("invalid format, expected , or ] while in an array", pi->str, pi->s);
}
Expand Down Expand Up @@ -276,7 +270,7 @@ static void read_str(ParseInfo pi, const char *key) {
#endif

static void read_num(ParseInfo pi, const char *key) {
char * start = pi->s;
char *start = pi->s;
int64_t n = 0;
long a = 0;
long div = 1;
Expand Down Expand Up @@ -351,9 +345,7 @@ static void read_num(ParseInfo pi, const char *key) {

*pi->s = '\0';
if (pi->has_add_value) {
call_add_value(pi->handler,
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)),
key);
call_add_value(pi->handler, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)), key);
}
*pi->s = c;
} else {
Expand All @@ -371,9 +363,7 @@ static void read_num(ParseInfo pi, const char *key) {

*pi->s = '\0';
if (pi->has_add_value) {
call_add_value(pi->handler,
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)),
key);
call_add_value(pi->handler, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)), key);
}
*pi->s = c;
} else {
Expand Down Expand Up @@ -505,9 +495,9 @@ static char *unicode_to_chars(ParseInfo pi, char *t, uint32_t code) {
* reached again. Do not read the character after the terminating quote.
*/
static char *read_quoted_value(ParseInfo pi) {
char * value = 0;
char * h = pi->s; /* head */
char * t = h; /* tail */
char *value = 0;
char *h = pi->s; /* head */
char *t = h; /* tail */
uint32_t code;

h++; /* skip quote character */
Expand Down Expand Up @@ -588,15 +578,13 @@ static void saj_parse(VALUE handler, char *json) {
pi.str = json;
pi.s = json;
#if IS_WINDOWS
pi.stack_min = (void *)((char *)&obj -
(512 * 1024)); /* assume a 1M stack and give half to ruby */
pi.stack_min = (void *)((char *)&obj - (512L * 1024L)); /* assume a 1M stack and give half to ruby */
#else
{
struct rlimit lim;

if (0 == getrlimit(RLIMIT_STACK, &lim) && RLIM_INFINITY != lim.rlim_cur) {
pi.stack_min = (void *)((char *)&obj - (lim.rlim_cur / 4 *
3)); /* let 3/4ths of the stack be used only */
pi.stack_min = (void *)((char *)&obj - (lim.rlim_cur / 4 * 3)); /* let 3/4ths of the stack be used only */
} else {
pi.stack_min = 0; /* indicates not to check stack limit */
}
Expand Down Expand Up @@ -633,7 +621,7 @@ static void saj_parse(VALUE handler, char *json) {
*/
VALUE
oj_saj_parse(int argc, VALUE *argv, VALUE self) {
char * json = 0;
char *json = 0;
size_t len = 0;
VALUE input = argv[1];

Expand Down
2 changes: 1 addition & 1 deletion ext/oj/stream_writer.c
Expand Up @@ -318,7 +318,7 @@ static VALUE stream_writer_flush(VALUE self) {
void oj_stream_writer_init(void) {
oj_stream_writer_class = rb_define_class_under(Oj, "StreamWriter", rb_cObject);
rb_gc_register_address(&oj_stream_writer_class);
// rb_undef_alloc_func(oj_stream_writer_class);
rb_undef_alloc_func(oj_stream_writer_class);

rb_define_module_function(oj_stream_writer_class, "new", stream_writer_new, -1);
rb_define_method(oj_stream_writer_class, "push_key", stream_writer_push_key, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/string_writer.c
Expand Up @@ -472,7 +472,7 @@ static VALUE str_writer_as_json(VALUE self) {
void oj_string_writer_init(void) {
oj_string_writer_class = rb_define_class_under(Oj, "StringWriter", rb_cObject);
rb_gc_register_address(&oj_string_writer_class);
// rb_undef_alloc_func(oj_string_writer_class);
rb_undef_alloc_func(oj_string_writer_class);

rb_define_module_function(oj_string_writer_class, "new", str_writer_new, -1);
rb_define_method(oj_string_writer_class, "push_key", str_writer_push_key, 1);
Expand Down

0 comments on commit a0db102

Please sign in to comment.