Skip to content

Move FFI::DataConverter to Ruby#661

Merged
tduehr merged 3 commits into
ffi:masterfrom
eregon:move-data-converter-to-ruby
Jan 22, 2019
Merged

Move FFI::DataConverter to Ruby#661
tduehr merged 3 commits into
ffi:masterfrom
eregon:move-data-converter-to-ruby

Conversation

@eregon

@eregon eregon commented Jan 7, 2019

Copy link
Copy Markdown
Collaborator
  • Include DataConverter in StructByReference in Ruby code to simplify ordering.

See #660 for context.

eregon added 2 commits January 7, 2019 23:36
* Include DataConverter in StructByReference in Ruby code to simplify
  ordering.
@eregon eregon force-pushed the move-data-converter-to-ruby branch from c552400 to 96bf421 Compare January 7, 2019 22:37
Comment thread lib/ffi/data_converter.rb
@eregon

eregon commented Jan 7, 2019

Copy link
Copy Markdown
Collaborator Author

This is now ready for review.

@larskanis

Copy link
Copy Markdown
Member

LGTM

@headius headius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby impl seems to have most of the same behavior as the C code, so I suspect this should be fine.

@eregon

eregon commented Jan 10, 2019

Copy link
Copy Markdown
Collaborator Author

Can we merge this?

@tduehr Could you review?

I think this doesn't touch performance critical-code, but I'm happy to run some benchmarks if you tell me which ones would be relevant for this.

The behavior seems similar to the DataConverter class in JRuby, except that one has the extra reference_required and reference_required? methods.

@tduehr

tduehr commented Jan 10, 2019

Copy link
Copy Markdown
Member

There's more to it than just the module itself. I'll take a look at usage today.

I expect this code is used in converting from ruby to C/JAva and back... Any benchmark covering that should be good.

Can you get the benchmark suite working, or at least find the holes? That'd be awesome too...

@headius

headius commented Jan 10, 2019

Copy link
Copy Markdown
Contributor

@tduehr Even if this is on the hot path it's probably a lateral move changing this code to Ruby. It may even be faster in some cases since the C code (and the Java code, for that matter) does uncached instance variable lookups.

@tduehr

tduehr commented Jan 10, 2019

Copy link
Copy Markdown
Member

The licensing is all over the place. We'll want to consolidate that at some point.

* The same as errno.rb. DataConverter.c was added by Wayne Meissner.
@eregon

eregon commented Jan 10, 2019

Copy link
Copy Markdown
Collaborator Author

I added the license header.

@tduehr tduehr merged commit 353d787 into ffi:master Jan 22, 2019
@eregon

eregon commented Feb 1, 2019

Copy link
Copy Markdown
Collaborator Author

For the record, I checked, and none of the benchmarks, nor the tests ever calls FFI::DataConverter#to_native or FFI::DataConverter#from_native, and DataConverter#native_type is only called during require 'ffi'.

It's easy to adapt bench_chmod.rb to use it by changing :string arguments to :strptr (which is not useful in practice, :strptr is only useful as a return type, but then it overrides from_native which doesn't call in DataConvert anymore), and as expected the performance difference is insignificant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants