182 questions
1 vote
2 answers
87 views
How to "require" a third party module in C code when trying to call ruby methods from C?
I have the following code here: #include <ruby.h> int main(int argc, char* argv[]) { /* construct the VM */ ruby_init(); /* Ruby goes here */ int state; VALUE result; ...
3 votes
0 answers
182 views
How to call "unpack" on a string in ruby C-api?
I am trying to use the ruby C-api to call unpack on a ruby string. Here is my current code: #include "ruby.h" #include <stdio.h> #include <unistd.h> VALUE dangerous_func(...
0 votes
0 answers
62 views
How to compile & run Ruby c (/c++) extension with OpenMP (undefined symbol error)
I'm trying to do a simple parfor loop in a Ruby c/c++ extension using openmp #pragma omp parallel for for (int j = 0; j < 100; j++) { } extconf.rb: require 'mkmf' extension_name = 'stridx' $CFLAGS ...
1 vote
1 answer
89 views
How to call a method of a module properly in ruby C-api?
I am trying to write a fuzzing harness for this open source regex library , but I am running into a problem that I do not know how to call a module in the ruby C-api properly. My current harness code ...
0 votes
1 answer
143 views
Linker not finding ruby symbols (such as ruby_init) when trying to compile C program which uses libruby.so
I followed these instructions to compile ruby: https://docs.ruby-lang.org/en/master/contributing/building_ruby_md.html#label-Quick+start+guide Then I made this simple C program which uses the ruby ...
3 votes
1 answer
117 views
Ruby C Api handling exceptions
I am running a ruby script through C as follows: #include <ruby.h> int main(void) { ruby_init(); int status; rb_load_protect(rb_str_new2("./test.rb"), 0, &status); if (...
2 votes
1 answer
249 views
Ruby and C API: rb_funcall_with_block on global method? How to call ruby global method with block from C?
I want to call a global method in ruby from my C API code. So in ruby: def giveMeABlock(*args) puts "Starting giveMeABlock with #{args.inspect}" yield if block_given? end As I've since ...
1 vote
1 answer
62 views
Ruby in C using Singleton module crashes
I was trying to implement a project using Ruby's C API which led me to the following problem. I have a script that requires the Singleton module and noticed that my program always crashes, so I boiled ...
0 votes
1 answer
280 views
How to access a shared library file with mkmf in Ruby?
I am trying to work with libcsv here. The header file csv.h is in /usr/include directory, and the shared library file libcsv.so in /usr/lib64 (Fedora 35). For now, I was able to make the gem file work ...
1 vote
1 answer
221 views
Ruby constants in singleton methods
I have a Ruby C extension; I call that class FooC defined in ext/foo/foo.c, in that file I have void Init_foo(void) { VALUE cFoo = rb_const_get(rb_cObject, rb_intern("FooC")); : ...
1 vote
0 answers
267 views
Debugging Ruby C Extension gem
I've been trying to debug ruby gem made with Ruby C Extension to figure out how it works, so I can modify it to my own use. It's quite an advanced gem and printing values isn't enough. So I started ...
0 votes
1 answer
345 views
"incompatible library version" when building ruby extension vs gem install
I'm trying to build the ruby-odbc gem from source to debug an issue. I can successfully compile odbc.so and odbc_utf8.so, but when I include the gem in my Gemfile via :path I get "incompatible ...
0 votes
1 answer
63 views
How to use class in Ruby extension written in C defined in other C file?
I create an extension for Ruby in C and I am currently struggling with calling constructor on class I defined also in C. Code for class definition is called before the class is being used. I am trying ...
0 votes
1 answer
164 views
free string after rb_raise
I'm writing a Ruby C extension, and need to call rb_raise() and pass it a char *. I also need to free that given char *. My current behavior won't free anything, and another approach I've tried lead ...
2 votes
0 answers
50 views
Document methods in a ruby c extension [closed]
I've been working on some ruby libraries with C extensions now. And I want to give users access to the irb#help method, e.g: > help("Array#empty?") # Prints documentation for the method. ...