Skip to content

Commit

Permalink
Updated for Ruby 2.3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Dec 31, 2015
1 parent adf6ba1 commit 03592a2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -12,6 +12,7 @@ rvm:
- 2.2.1
- 2.2.2
- 2.2.3
- 2.3.0
- rbx-2

matrix:
Expand Down
3 changes: 2 additions & 1 deletion build_test.sh
Expand Up @@ -7,7 +7,8 @@ for ruby in \
2.2.0\
2.2.1\
2.2.2\
2.2.3
2.2.3\
2.3.0
do
echo "\n********************************************************************************"
echo "Building $ruby\n"
Expand Down
1 change: 1 addition & 0 deletions ext/oj/extconf.rb
Expand Up @@ -34,6 +34,7 @@
'USE_RB_MUTEX' => (is_windows && !('1' == version[0] && '8' == version[1])) ? 1 : 0,
'DATETIME_1_8' => ('ruby' == type && ('1' == version[0] && '8' == version[1])) ? 1 : 0,
'NO_TIME_ROUND_PAD' => ('rubinius' == type) ? 1 : 0,
'HAS_DATA_OBJECT_WRAP' => ('ruby' == type && '2' == version[0] && '3' <= version[1]) ? 1 : 0,
}
# This is a monster hack to get around issues with 1.9.3-p0 on CentOS 5.4. SO
# some reason math.h and string.h contents are not processed. Might be a
Expand Down
4 changes: 4 additions & 0 deletions ext/oj/fast.c
Expand Up @@ -813,7 +813,11 @@ parse_json(VALUE clas, char *json, int given, int allocated) {
}
#endif
// last arg is free func void* func(void*)
#if HAS_DATA_OBJECT_WRAP
doc->self = rb_data_object_wrap(clas, doc, 0, free_doc_cb);
#else
doc->self = rb_data_object_alloc(clas, doc, 0, free_doc_cb);
#endif
rb_gc_register_address(&doc->self);
doc->json = json;
DATA_PTR(doc->self) = doc;
Expand Down
5 changes: 3 additions & 2 deletions ext/oj/reader.c
Expand Up @@ -109,7 +109,7 @@ int
oj_reader_read(Reader reader) {
int err;
size_t shift = 0;

if (0 == reader->read_func) {
return -1;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ rescue_cb(VALUE rbuf, VALUE err) {
if (rb_eTypeError != clas && rb_eEOFError != clas) {
Reader reader = (Reader)rbuf;

rb_raise(err, "at line %d, column %d\n", reader->line, reader->col);
rb_raise(clas, "at line %d, column %d\n", reader->line, reader->col);
}
return Qfalse;
}
Expand All @@ -185,6 +185,7 @@ partial_io_cb(VALUE rbuf) {
}
str = StringValuePtr(rstr);
cnt = RSTRING_LEN(rstr);
//printf("*** partial read %lu bytes, str: '%s'\n", cnt, str);
strcpy(reader->tail, str);
reader->read_end = reader->tail + cnt;

Expand Down
20 changes: 17 additions & 3 deletions test/test_scp.rb
Expand Up @@ -73,6 +73,7 @@ def array_append(a, value)
end # AllHandler

class Closer < AllHandler
attr_accessor :io
def initialize(io)
super()
@io = io
Expand Down Expand Up @@ -340,7 +341,13 @@ def test_pipe_close
[:hash_set, 'one', true]], handler.calls)
else
read_io.close
write_io.write json
write_io.write json[0..11]
sleep(0.1)
begin
write_io.write json[12..-1]
rescue Exception => e
# ignore, should fail to write
end
write_io.close
Process.exit(0)
end
Expand All @@ -357,8 +364,15 @@ def test_socket_close
end
Thread.start(json) do |j|
c = server.accept()
c.puts json
c.close
c.puts json[0..11]
10.times {
break if c.closed?
sleep(0.1)
}
unless c.closed?
c.puts json[12..-1]
c.close
end
end
begin
sock = TCPSocket.new('localhost', 8080)
Expand Down

0 comments on commit 03592a2

Please sign in to comment.