Repository navigation
Conversation
Installing and running real C extension gems turned up functions the spec suite never
calls:
- rb_ext_ractor_safe (RB_EXT_RACTOR_SAFE), which most current extensions call
first thing in Init_ (jaro_winkler, msgpack, oj...). It was a stub that raised,
so the extension failed to load. The rest of ruby/ractor.h comes along:
- The Ractor's stdin, stdout and stderr are $stdin & co.
- rb_ractor_make_shareable(_copy) and the rb_ractor_shareable_p fallback go to
Ractor.
- Ractor-local storage keys hold one value each, since an extension only runs
in the main Ractor here.
- rb_obj_freeze_inline (RB_OBJ_FREEZE) and rb_must_asciicompat: bigdecimal, oj.
- rb_hash_size_num (RHASH_SIZE): msgpack.
- rb_opts_exception_p, object.c's handling of the exception: keyword, which
bigdecimal looks for with have_func: bigdecimal, oj.
- rb_memhash: oj.
With these, and the two commits that follow, these gems build with `gem install`,
load and give the same results as on CRuby 4.0 for a script exercising each:
- fast_blank, redcarpet, jaro_winkler, escape_utils, racc (cparse),
digest-murmurhash and unf_ext (C++).
- With IRONRUBY_NATIVE_GEMS: bigdecimal, msgpack, bcrypt and oj.
spec/optional/capi still passes in full.
IronRuby raised TypeError "Cannot undefine 'initialize' method". CRuby 4.0 allows it. `undef`/undef_method warn "undefining 'initialize' may cause serious problems", as they do for object_id and __send__, and C's rb_undef_method says nothing. racc's C parser does it in its Init (rb_undef_method(CparseParams, "initialize")), so racc/cparse failed to load. new on such a class allocates the object and calls #initialize anyway, which ends in method_missing: NoMethodError "undefined method 'initialize' for an instance of D" unless the class defines method_missing, as in CRuby. Object construction had asserted that initialize always resolves; it now builds that call when it does not. Scenario_RubyInitializers6 asserted the old TypeError and now checks CRuby's behaviour and its warning. IronRuby.Tests, spec/language, spec/core/class, spec/core/module and spec/core/basicobject pass, apart from the known into/to wording errors.
Two problems with installing real C extension gems: - Gem::Specification#build_extensions was redefined in the class body, with a `super` meant for RubyGems' own method. That method was what it replaced, so `super` reached BasicSpecification, which has none. `gem install oj` failed with NoMethodError as soon as it got to oj's installed bigdecimal dependency. The override is now a prepended module, as the installer's already was. - With IRONRUBY_NATIVE_GEMS naming msgpack (or oj, or bcrypt), the gem was activated ahead of IronRuby's built-in on $LOAD_PATH, and its compiled extension still never loaded: `require "msgpack/msgpack"` takes a .rb from anywhere on the load path before a .so, as CRuby's does, and Src/StdLib/ironruby/msgpack/msgpack.rb is IronRuby's implementation under the extension's name. The three built-in files that sit under an extension's name (msgpack/msgpack.rb, oj/oj.rb, bcrypt_ext.rb) now ask Gem.ironruby_native_extension_for first, and load the native gem's .so instead when there is one. Without IRONRUBY_NATIVE_GEMS the lookup returns at once and nothing changes. Checked by installing msgpack, oj and bcrypt with IRONRUBY_NATIVE_GEMS='*' and comparing a script that exercises them with CRuby 4.0, and by running the same script without the variable (the built-ins load as before). The C API README lists the gems tried.
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.
Installing real C extension gems with
gem install --platform rubyand running a script exercising each against CRuby 4.0 turned up a few gaps. With this branch these build, load and give CRuby's results (Linux x64):IRONRUBY_NATIVE_GEMS: bigdecimal, msgpack (ext types included), bcrypt and oj (compat and object mode)Three commits:
rb_ext_ractor_safewas a stub that raised, and most current extensions call it first inInit_. The rest of ruby/ractor.h comes along. Also added:rb_obj_freeze_inline,rb_hash_size_num,rb_opts_exception_p,rb_must_asciicompatandrb_memhash.undefandundef_methodnow warn as CRuby does, andnewthen ends in NoMethodError through method_missing.Scenario_RubyInitializers6now checks CRuby's behaviour.Specification#build_extensionsis a prepended module now. Before, itssuperreached BasicSpecification, sogem install ojfailed.msgpack/msgpack.rb,oj/oj.rb,bcrypt_ext.rb) load the gem's.sowhenIRONRUBY_NATIVE_GEMSselects that gem. Without that, a.rbon the load path always wins over a.so.Checked: IronRuby.Tests and spec/optional/capi (1660 examples) all pass, and spec/language, core/class, core/module and core/basicobject show only the known into/to errors. Without
IRONRUBY_NATIVE_GEMS, the built-in msgpack, oj and bcrypt load and behave as before.