Questions tagged [ruby-c-extension]

Loadable modules written in C which provide additional functionality for the Ruby language.

C extensions are shared objects that can be loaded by the MRI at runtime. They are typically created in order to allow Ruby to interface with low-level code, but can also used to improve the speed of expensive computations.

Many modules in the Ruby standard library are implemented as C extensions in order to optimize for speed or reuse existing libraries.

176 questions
0
votes
1 answer

rb_class_new_instance raises "ArgumentError: wrong type" - why?

From my Ruby C Extension I wanted to create a new Geom::Vector3d instance from the Google SketchUp Ruby API: https://developers.google.com/sketchup/docs/ourdoc/vector3d My initial code was this: static inline VALUE vector_to_sketchup( Point3d vector…
thomthom
  • 2,854
  • 1
  • 23
  • 53
0
votes
1 answer

Python module semantics vs. Ruby module semantics in their C-APIs

I've been using Python for a long time and I've just started to toy around with Ruby, but I'm finding the differences between modules in the two languages really confusing, especially when viewed through their C-APIs. For example, here is a small…
dcolish
  • 22,727
  • 1
  • 24
  • 25
0
votes
1 answer

What is extension of ruby Exception class object in c?

HI i have following code in c which is invoked from a ruby script, static VALUE myMethod(VALUE self, VALUE exc) { int a = TYPE(exc); printf(" %d ", a ); // Some process on exc } void Init_myRuby() { VALUE mRuby =…
Prajkata
  • 65
  • 6
0
votes
1 answer

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 using the shell command: gcc -c -fPIC rcsv.c -o…
Ashvith Shetty
  • 90
  • 2
  • 11
0
votes
1 answer

"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 library version". If I install the exact same gem via…
ioev
  • 78
  • 6
0
votes
1 answer

Is there something wrong with how I'm referencing my instances in this C extension?

I'm having some issues where when if I run this C extension outside of a Rails environment it works, but when I run inside Rails it gives me a stack dump. I get this error message: NoMethodError Exception: undefined method `evaluate' for…
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114
0
votes
2 answers

Why am I able to directly use some of the ruby C extension array methods, but not others?

I am using many of the array methods found in array.c of the ruby codebase, but when trying to call VALUE rIntersection = rb_ary_and(rAry1, rAry2); I got this error: dyld: lazy symbol binding failed: Symbol not found: _rb_ary_and Referenced…
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114
0
votes
1 answer

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 to get the class using VALUE…
dom
  • 414
  • 3
  • 12
0
votes
2 answers

How do I not share an external variable across instances?

EDIT: this is a rewrite of the question since it was so unspecific before. So I'm having a problem solving the issue of variables being shared across instances in C extensions. Here is an example of what I'm encountering. >> t =…
0
votes
1 answer

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 me into undefined behavior. What is the correct…
Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
0
votes
0 answers

Ruby C Extension - TypeError on TypedData_Get_Struct call that is no type error

I am working on a Ruby C/C++ Extension and thus far it has been going quite well. However I came across an error that I don't know what to do about it. I have defined the following ruby data types: static const rb_data_type_t SmartLib_File_type = { …
Vapire
  • 4,568
  • 3
  • 24
  • 41
0
votes
1 answer

my ruby c extension works in ruby 2.2 and does not work in ruby 2.6.5

I have been searching a lot and unable to find the exact solution to my problem. I have installed ruby c extension on ruby 2.2 and it works fine. when I have updated my ruby to 2.6.5 it fails saying that .so file is not found Error:- in ruby…
akhil
  • 105
  • 10
0
votes
2 answers

Ruby extension link error

I keep getting this fairly obscure link error whenever I try to link my Ruby extension: /usr/bin/ld: Mg.o: relocation R_X86_64_PC32 against undefined symbol `init_window_class_under' can not be used when making a shared object; recompile with…
Matheus Moreira
  • 17,106
  • 3
  • 68
  • 107
0
votes
1 answer

Ruby (2.0) c extension return array of arrays from c function

I am writing a Ruby c extension to perform linear algebra calculations using the Accelerate macos framework. In order to use all the cores available I am also using rb_thread_call_without_gvl to unlock the global VM lock. I am not a c expert so…
Rojj
  • 1,170
  • 1
  • 12
  • 32
0
votes
1 answer

Ruby C extension : How do I know that a ruby VALUE generated in my C code will be correctly cleaned by GC?

I'm trying to write a really small C extension. So I don't want to make a whole ruby class, with initializer, allocator, and so forth. All I want to do is add a static method to an existing class, method which will run an algorithm and return a…
Quentin
  • 1,085
  • 1
  • 11
  • 29