Skip to content
Open
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
6 changes: 4 additions & 2 deletions ext/java/org/msgpack/jruby/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public IRubyObject registerTypeInternal(ThreadContext ctx, IRubyObject type, IRu

extensionRegistry.put(extModule, (int) typeId, recursive, packerProc, unpackerProc);

if (extModule == runtime.getSymbol() && !packerProc.isNil()) {
hasSymbolExtType = true;
if (extModule == runtime.getSymbol()) {
hasSymbolExtType = !packerProc.isNil();
}

if (options != null) {
Expand All @@ -123,6 +123,8 @@ public IRubyObject registerTypeInternal(ThreadContext ctx, IRubyObject type, IRu
} else {
throw runtime.newArgumentError("oversized_integer_extension: true is only for Integer class");
}
} else if (extModule == runtime.getModule("Integer")) {
hasBigIntExtType = false;
}
}

Expand Down
13 changes: 6 additions & 7 deletions ext/msgpack/factory_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ static VALUE Factory_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE

if(ext_module == rb_cSymbol) {
fc->symbol_ext_type = ext_type;
if(NIL_P(options) || RTEST(rb_hash_aref(options, ID2SYM(rb_intern("packer"))))) {
fc->has_symbol_ext_type = true;
}
if(RTEST(options) && RTEST(rb_hash_aref(options, ID2SYM(rb_intern("optimized_symbols_parsing"))))) {
fc->optimized_symbol_ext_type = true;
}
fc->has_symbol_ext_type = NIL_P(options) || RTEST(packer_proc);
fc->optimized_symbol_ext_type = RTEST(options) && RTEST(rb_hash_aref(options, ID2SYM(rb_intern("optimized_symbols_parsing"))));
}

if(ext_module == rb_cInteger) {
fc->has_bigint_ext_type = false;
}

if(RTEST(options)) {
Expand All @@ -250,7 +250,6 @@ static VALUE Factory_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE
rb_raise(rb_eArgError, "oversized_integer_extension: true is only for Integer class");
}
}

if(RTEST(rb_hash_aref(options, ID2SYM(rb_intern("recursive"))))) {
flags |= MSGPACK_EXT_RECURSIVE;
}
Expand Down
20 changes: 12 additions & 8 deletions lib/msgpack/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ def register_type(type, klass, options = { packer: :to_msgpack_ext, unpacker: :f
options[:packer] = packer.to_sym.to_proc
when Method
options[:packer] = packer.to_proc
when packer.respond_to?(:call)
options[:packer] = packer.method(:call).to_proc
else
raise ::TypeError, "expected :packer argument to be a callable object, got: #{packer.inspect}"
if packer.respond_to?(:call)
options[:packer] = packer.method(:call).to_proc
else
raise ::TypeError, "expected :packer argument to be a callable object, got: #{packer.inspect}"
end
end

case unpacker = options[:unpacker]
Expand All @@ -27,10 +29,12 @@ def register_type(type, klass, options = { packer: :to_msgpack_ext, unpacker: :f
options[:unpacker] = klass.method(unpacker).to_proc
when Method
options[:unpacker] = unpacker.to_proc
when packer.respond_to?(:call)
options[:unpacker] = unpacker.method(:call).to_proc
else
raise ::TypeError, "expected :unpacker argument to be a callable object, got: #{unpacker.inspect}"
if unpacker.respond_to?(:call)
options[:unpacker] = unpacker.method(:call).to_proc
else
raise ::TypeError, "expected :unpacker argument to be a callable object, got: #{unpacker.inspect}"
end
end
end

Expand All @@ -51,7 +55,7 @@ def registered_types(selector=:both)
type = ary[0]
packer_proc = ary[1]
unpacker_proc = nil
if unpacker.has_key?(type)
if unpacker.has_key?(type) && unpacker[type][0] == klass
unpacker_proc = unpacker.delete(type)[1]
end
list << {type: type, class: klass, packer: packer_proc, unpacker: unpacker_proc}
Expand Down Expand Up @@ -85,7 +89,7 @@ def registered_types(selector=:both)

def type_registered?(klass_or_type, selector=:both)
case klass_or_type
when Class
when Module
klass = klass_or_type
registered_types(selector).any?{|entry| klass <= entry[:class] }
when Integer
Expand Down
2 changes: 1 addition & 1 deletion lib/msgpack/packer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def registered_types

def type_registered?(klass_or_type)
case klass_or_type
when Class
when Module
klass = klass_or_type
registered_types.any?{|entry| klass <= entry[:class] }
when Integer
Expand Down
2 changes: 1 addition & 1 deletion lib/msgpack/unpacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def registered_types

def type_registered?(klass_or_type)
case klass_or_type
when Class
when Module
klass = klass_or_type
registered_types.any?{|entry| klass == entry[:class] }
when Integer
Expand Down