Project

General

Profile

Actions

Bug #19086

closed

Dir#entries and Dir#glob fail in stand-alone CRuby app

Added by kyonides (Edwin Acuña) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]
[ruby-core:110518]

Description

Whenever I call Dir.entries or Dir.glob using an app compiled against Ruby 3.0 on Ubuntu 22.04, I expect to get a list of files or directories present there. This does not happen if you are calling it from a stand-alone app like the one I attached to this bug report.

It does not matter if I call it by evaluating some C string or by depending on a rb_funcall, it will certainly fail to do anything.

First Result: the application will segfault in no time.

Second Result: if calling rb_eval_string_protect function to evaluate the string, calling Dir#entries or Dir#glob methods, you get the following output.

NoMethodError raised!
undefined method `glob' for Dir:Class

TypeError raised!
wrong argument type File (expected dir)
eval:1:in `entries'

Dir#entries treats the tmp directory that the test code had created via Dir#mkdir as a file...

I have also tried compiling the same CRuby app against Ruby 2.7 and everything works fine. I suspect that the introduction of Primitive is causing this issue. CRuby 3.0 is unable to find the context of Primitive or any default Ruby script installed on the target machine that may call Primitive at some point.

The expected result should be to be able to get both methods return all of the files and directories as it used to do in earlier versions of Ruby.


Files

main.cpp (2.12 KB) main.cpp CRuby Test Code kyonides (Edwin Acuña), 10/26/2022 07:01 PM
ruby30 output.txt (464 Bytes) ruby30 output.txt Output using rb_eval_string_protect kyonides (Edwin Acuña), 10/26/2022 07:11 PM

Updated by mame (Yusuke Endoh) over 1 year ago

I guess you need to call ruby_init and ruby_options instead of ruby_setup. I think Dir.glob is defined in ruby_options.

Updated by kyonides (Edwin Acuña) over 1 year ago

mame (Yusuke Endoh) wrote in #note-1:

I guess you need to call ruby_init and ruby_options instead of ruby_setup. I think Dir.glob is defined in ruby_options.

=_=¡ I was hoping the solution wouldn't be that simple because it would mean that I was making a mistake by using ruby_setup instead or the ruby_init and ruby_options functions. Curiously, ruby_options does load Dir.entries and Dir.glob so this report can be closed safely now. Thanks for the heads up, Endoh!

EDIT: What I DON'T LIKE about this procedure is that I will need to pass the app name plus -e and an empty C string as parameters to make it work if compiled against Ruby 3.x...

Actions #3

Updated by jeremyevans0 (Jeremy Evans) over 1 year ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like1Like0Like0