Move C and Java code to Ruby and fix #133#135
Merged
tagomoris merged 17 commits intomsgpack:masterfrom Jun 13, 2017
Merged
Conversation
This commit allows us to pass the `DefaultFactory` object in to the C code so that we don't need to use a C global for storing the factory object.
This commit pulls the is-a checks up in to Ruby, constructs the unpacker, then passes that unpacker in to the _load function so the C code doesn't need to know about the `DefaultFactory` object.
We shouldn't need to reference the C global anymore
tenderlove
added a commit
to github/ruby
that referenced
this pull request
Mar 10, 2017
This is a work around for a bug in msgpack. It should be fixed by: * msgpack/msgpack-ruby#134 * msgpack/msgpack-ruby#135
d6ef970 to
9feb40f
Compare
Member
|
private void checkType(ThreadContext ctx, IRubyObject obj, Class<? extends IRubyObject> expectedType) {
if (!expectedType.isInstance(obj)) {
String expectedName = expectedType.getName().substring("org.jruby.Ruby".length());
throw ctx.runtime.newTypeError(String.format("wrong argument type %s (expected %s)", obj.getMetaClass().toString(), expectedName));
}
}
@JRubyMethod(name = "write_float")
public IRubyObject writeFloat(ThreadContext ctx, IRubyObject obj) {
checkType(ctx, obj, RubyFloat.class);
return write(ctx, obj);
} |
RagunovichVlad
approved these changes
Apr 2, 2017
Member
|
@tenderlove How do you think about JRuby 1.7.x support mentioned by @iconara 's comment? |
Contributor
Author
|
I'm going to update this patch to use @iconara's code. I've just been a little busy. I'll update the PR this week. Thank you! |
Contributor
Author
lexmag
reviewed
Apr 7, 2017
lib/msgpack/core_ext.rb
Outdated
| def to_msgpack(packer_or_io = nil) | ||
| if packer_or_io | ||
| if packer_or_io.is_a?(MessagePack::Packer) | ||
| _to_msgpack packer_or_io |
There was a problem hiding this comment.
Maybe name _to_msgpack –> to_msgpack_with_packer? And perhaps make it private? ![]()
Member
iconara
approved these changes
Apr 12, 2017
Member
|
I'm so sorry that I missed to merge this patch. |
Contributor
Author
|
@tagomoris no problem at all, thank you!! 😊 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
This PR moves lots of the encoding / decoding logic from C to Ruby. It fixes #133 because the C code doesn't need to reference the class anymore. I prefer this PR over #134 because it removes lots of C code.
I've run the benchmarks to compare this branch against the master branch, and benchmark times don't change (as I expected) even though we are using more Ruby code.
Here are the benchmarks from master running on Ruby 2.4:
Here are the benchmarks run against this PR using Ruby 2.4:
They look almost the same. We are able to move the C code to Ruby, prevent SEGV, and performance stays the same.
I'm sorry the patch is so large. 🙍