Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix State::configure alias and implementation #152

Merged
merged 2 commits into from
Nov 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ext/json/ext/generator/generator.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -522,39 +522,39 @@ static VALUE cState_configure(VALUE self, VALUE opts)
unsigned long len; unsigned long len;
Check_Type(tmp, T_STRING); Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp); len = RSTRING_LEN(tmp);
state->indent = fstrndup(RSTRING_PTR(tmp), len); state->indent = fstrndup(RSTRING_PTR(tmp), len + 1);
state->indent_len = len; state->indent_len = len;
} }
tmp = rb_hash_aref(opts, ID2SYM(i_space)); tmp = rb_hash_aref(opts, ID2SYM(i_space));
if (RTEST(tmp)) { if (RTEST(tmp)) {
unsigned long len; unsigned long len;
Check_Type(tmp, T_STRING); Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp); len = RSTRING_LEN(tmp);
state->space = fstrndup(RSTRING_PTR(tmp), len); state->space = fstrndup(RSTRING_PTR(tmp), len + 1);
state->space_len = len; state->space_len = len;
} }
tmp = rb_hash_aref(opts, ID2SYM(i_space_before)); tmp = rb_hash_aref(opts, ID2SYM(i_space_before));
if (RTEST(tmp)) { if (RTEST(tmp)) {
unsigned long len; unsigned long len;
Check_Type(tmp, T_STRING); Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp); len = RSTRING_LEN(tmp);
state->space_before = fstrndup(RSTRING_PTR(tmp), len); state->space_before = fstrndup(RSTRING_PTR(tmp), len + 1);
state->space_before_len = len; state->space_before_len = len;
} }
tmp = rb_hash_aref(opts, ID2SYM(i_array_nl)); tmp = rb_hash_aref(opts, ID2SYM(i_array_nl));
if (RTEST(tmp)) { if (RTEST(tmp)) {
unsigned long len; unsigned long len;
Check_Type(tmp, T_STRING); Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp); len = RSTRING_LEN(tmp);
state->array_nl = fstrndup(RSTRING_PTR(tmp), len); state->array_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
state->array_nl_len = len; state->array_nl_len = len;
} }
tmp = rb_hash_aref(opts, ID2SYM(i_object_nl)); tmp = rb_hash_aref(opts, ID2SYM(i_object_nl));
if (RTEST(tmp)) { if (RTEST(tmp)) {
unsigned long len; unsigned long len;
Check_Type(tmp, T_STRING); Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp); len = RSTRING_LEN(tmp);
state->object_nl = fstrndup(RSTRING_PTR(tmp), len); state->object_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
state->object_nl_len = len; state->object_nl_len = len;
} }
tmp = ID2SYM(i_max_nesting); tmp = ID2SYM(i_max_nesting);
Expand Down
2 changes: 1 addition & 1 deletion java/src/json/ext/GeneratorState.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private ByteList prepareByteList(ThreadContext context, IRubyObject value) {
* @param vOpts The options hash * @param vOpts The options hash
* @return The receiver * @return The receiver
*/ */
@JRubyMethod @JRubyMethod(alias = "merge")
public IRubyObject configure(ThreadContext context, IRubyObject vOpts) { public IRubyObject configure(ThreadContext context, IRubyObject vOpts) {
OptionsReader opts = new OptionsReader(context, vOpts); OptionsReader opts = new OptionsReader(context, vOpts);


Expand Down
16 changes: 16 additions & 0 deletions tests/test_json_generate.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ def test_gc
end if GC.respond_to?(:stress=) end if GC.respond_to?(:stress=)


if defined?(JSON::Ext::Generator) if defined?(JSON::Ext::Generator)
[:merge, :configure].each do |method|
define_method "test_configure_using_#{method}" do
state = JSON::Ext::Generator::State.new
state.send method, :indent => "1",
:space => '2',
:space_before => '3',
:object_nl => '4',
:array_nl => '5'
assert_equal '1', state.indent
assert_equal '2', state.space
assert_equal '3', state.space_before
assert_equal '4', state.object_nl
assert_equal '5', state.array_nl
end
end

def test_broken_bignum # [ruby-core:38867] def test_broken_bignum # [ruby-core:38867]
pid = fork do pid = fork do
Bignum.class_eval do Bignum.class_eval do
Expand Down