Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Aug 2, 2024
1 parent 559433b commit a825563
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 3.16.5 - unreleased

- Fixed Oj::Parser so that block procedures work correctly.

## 3.16.4 - 2024-06-08

- Fixed Oj::Parse EOF issue on larger stream input.
Expand Down
11 changes: 4 additions & 7 deletions ext/oj/usual.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,13 @@ static void close_object(ojParser p) {
rb_hash_bulk_insert(d->vtail - head, head, obj);
d->ktail = d->khead + c->ki;

// printf("*** close %ld - %d\n", head - d->vhead, rb_block_given_p());
if (1 == head - d->vhead && rb_block_given_p()) {
rb_yield(obj);
// TBD decrement vtail?
d->vtail--;
return;
}
d->vtail = head;
head--;
*head = obj;
if (1 == d->vtail - d->vhead && rb_block_given_p()) {
d->vtail = d->vhead;
rb_yield(obj);
}
}

static void close_object_class(ojParser p) {
Expand Down
2 changes: 1 addition & 1 deletion lib/oj/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Oj
# Current version of the module.
VERSION = '3.16.4'
VERSION = '3.16.5b'
end
31 changes: 20 additions & 11 deletions test/test_parser_usual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,28 @@ def test_decimal
assert_equal(Float, doc.class)
end

def test_multi
def test_multi_parse
p = Oj::Parser.new(:usual)
#puts p.parse('{"b":{"x":2}}')
#puts p.parse('{"a":1}{"b":{"x":2}} {"c":3}') { |j| puts j }

reader, writer = IO.pipe
writer.write('{"a":1}')
writer.write('{"b":{"x":2}}')
writer.write('{"c":3}')
writer.close
out = []
p.parse('{"a":1}{"b":{"x":2}} {"c":3}') { |j| out.push(j) }
assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
end

p.load(reader) { |data| puts data }
reader.close
def test_multi_load
p = Oj::Parser.new(:usual)
out = []
r, w = IO.pipe
thread = Thread.new do
['{"a":1}', '{"b":{"x"', ':2}}{"c":', '3}'].each { |seg|
w.write(seg)
sleep(0.1)
}
w.close
end
p.load(r) { |j| out.push(j) }
r.close
thread.join
assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
end

def test_omit_null
Expand Down

0 comments on commit a825563

Please sign in to comment.