Bug #19086
closedDir#entries and Dir#glob fail in stand-alone CRuby app
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
Updated by mame (Yusuke Endoh) about 2 years 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) about 2 years ago
mame (Yusuke Endoh) wrote in #note-1:
I guess you need to call
ruby_init
andruby_options
instead ofruby_setup
. I thinkDir.glob
is defined inruby_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...
Updated by jeremyevans0 (Jeremy Evans) about 2 years ago
- Status changed from Open to Closed