1

I'm running into a rather strange bug when I use Ruby 3's C API in my C# program. I've been using Ruby 2.7 in my program for quite a while without any issues (in fact, the entire program depends on the fact that Ruby works), but it has stopped working since upgrading to Ruby 3. In particular, some methods that should exist, no longer exist. One example of such a method is String#unpack.

I know the issue can't be in how I've compiled the library, though, because if I use the command line and try ruby -e "p 'hi'.unpack('b*')" just as a tester, it gives a proper output and not an error. That makes me think something has changed in what needs to be initialized or loaded in terms of extensions or libraries, but I wouldn't have a clue what.

I initialize Ruby with ruby_sysinit and then ruby_init. Everything else works from this point onwards; I can load files, I can serialize/deserialize data with Marshal and use Zlib, but String#unpack suddenly no longer exists. I use rb_funcallv to call this method as I'm not aware of any simple alternatives exposed by Ruby's C API, but such a method would also suffice if it exists (and is available).

This issue has started happening only in Ruby 3, as I can compile and use Ruby 2.7 fine. Moreover, I have compiled Ruby 3.0 and Ruby 3.1 on both Windows and Ubuntu, and I have the same bug on both platforms.

The full source code for the library responsible for loading and initializing Ruby can be found at https://github.com/Marin-MK/rubydotnet if more information is required (initialization and setup is in Ruby.cs). After Ruby is loaded, $LOAD_PATH is appended with lib/ruby/3.1.0 and lib/ruby/3.1.0/x86_64-linux on Linux (or mingw-64 on Windows) to be able to use extensions. These are present and functional, as seen by the fact that Zlib works properly.

The full crash log when evaluating Ruby directly (so using rb_eval_string_protect, which has the same issue) with p 'Hello world!'.unpack('B*') on Ubuntu with Ruby 3.1.2 can be found here: https://www.dropbox.com/s/ddeects3k4fw8zf/log.txt?dl=1

Would anyone know why this String#unpack method has become unavailable through rb_funcallv since upgrading to Ruby 3? Is it something that went wrong during compilation, or is it something wrong with setup or requiring dependencies?

M3rein
  • 187
  • 1
  • 13

0 Answers0