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
2
votes
2 answers

Creating a C extension in Ruby

I am trying to create a C extension for ruby. I am very new to development and have only just became familiar with Ruby, so it im really lost. I have looked at "How to create a C Extension in Ruby in under five minutes" and it makes sense. The…
user1546594
  • 539
  • 1
  • 4
  • 4
2
votes
1 answer

How does ruby represent strings internally?

I ran into some trouble while creating a C-Extension for ruby that got me thinking. I wonder how Ruby (1.9.1) handles strings (and all the encoding-stuff) internally? If I have a string like "o", and I pass the string to a C-Function (as VALUE), I…
DeX3
  • 5,200
  • 6
  • 44
  • 68
2
votes
2 answers

Unwanted warning message with g++

I am trying to write a c++ extension for Ruby. In addition to the main file, I have a file extconf.rb: require "mkmf" $libs += " -lstdc++ " create_makefile("file_name") and, after doing ruby extconf.rb, when I try to compile it with g++ by typing…
sawa
  • 165,429
  • 45
  • 277
  • 381
1
vote
1 answer

ruby extconf.rb example

I am following instructions to http://people.apache.org/~rooneg/talks/ruby-extensions/ruby-extensions.html (page 6) and my make command is only returning make: Nothing to be done for 'all'. Does anyone have any ideas? I am using ruby 1.9.2 and I'm…
Coderama
  • 11,050
  • 12
  • 44
  • 58
1
vote
2 answers

Ruby C Extension: run an event loop concurrently

I'm implementing a simple windowing library as a Ruby C extension. Windows have a handle_events! method that enters their native event loop. The problem is that I want one event loop per window and the method blocks. I'd like the method to return…
Matheus Moreira
  • 17,106
  • 3
  • 68
  • 107
1
vote
1 answer

Segfault in Ruby Extension Code

I'm writing a small Ruby extension in C/C++ that makes boost::dynamic_bitfield available in Ruby. My code does perfectly compile, but when loading the extension and trying to instantiate the class I am getting a segfault. I haven't been able to…
halfdan
  • 33,545
  • 8
  • 78
  • 87
1
vote
1 answer

How to retrieve structure members of a struct type variable in C, passed from ruby script?

I have implemented Ruby C extension(i.e. Invoking C function from ruby script) Following is the function implemented in c from file "cFile.c" #include static VALUE cFunction(VALUE self, VALUE src) { if(TYPE(str) == T_STRUCT) { …
BSalunke
  • 11,499
  • 8
  • 34
  • 68
1
vote
1 answer

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 the issue down to using the following…
derschueddi
  • 113
  • 3
1
vote
1 answer

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")); : rb_define_const(cFoo, "BAR", 7); : That is included in the…
jjg
  • 907
  • 8
  • 18
1
vote
0 answers

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 debugging it with gdb and gdb-ruby gem. I created…
railsmk
  • 23
  • 4
1
vote
1 answer

Can objects made with c extensions instantiate and manage each other?

Right now I have a series of objects that are created using C extensions, so say they are Foo Bar Baz. I have ruby code that instantiates the three of them, calls their functions and processed the results. Let's call that: Manager Well, now…
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114
1
vote
1 answer

Why is my C extension not creating unique instances?

I created a C extension, the purpose of which is to determine if a series of cards will result in a straight or not. The example might be a little more complicated than necessary to show the issue, but essentially foo should be storing inside of it…
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114
1
vote
2 answers

Can we install C gems in ruby 2.7.0

I just upgraded by ruby to 2.7.0. And I tried to install the ibm_db gem in windows platform. Installation works fine. When I try to use the gem(like require 'ibm_db') I get the following error LoadError (126: The specified module could not be found.…
akhil
  • 105
  • 10
1
vote
2 answers

Using curl/libcurl in a C Ruby extension

To preface: I am very new to C, so I am probably missing something obvious but have been running around for days trying to figure out what it is... I am trying to create a Ruby C extension that will work on both Mac and PC and that uses libcurl to…
Dana Woodman
  • 4,148
  • 1
  • 38
  • 35
1
vote
1 answer

Ruby C extension returns report_on_exception is true

I was trying to import server_info api in the ibm_db extension. It worked well in windows but in Linux, it returns tread sleep error. # terminated with exception (report_on_exception is true): Traceback (most recent…
akhil
  • 105
  • 10