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
3
votes
1 answer

C++ in Ruby C extensions, pointer problems

I'm tryign to build a Ruby C extension that uses some c++ libraries. Problem is I can't even get a simple "hello world" to work. //hello_world.cpp #include static VALUE tosCore; static VALUE my_function( VALUE self ) { VALUE str =…
noelwarr
  • 117
  • 7
3
votes
1 answer

Ruby-generated makefile doesn't run

Maybe this is a really obvious answer, but I'm trying to extend Ruby using C in a Windows environment and I can't make the extension when I run mingw32-make it gets as far as generating a file called "forktest-i386-mingw32.def" and then says "No…
3
votes
1 answer

Ruby C extension for a function

I have to make a ruby c extension for the following function Abc_NtkCreateNodeAnd: Abc_Obj_t * Abc_NtkCreateNodeAnd( Abc_Ntk_t * pNtk, Vec_Ptr_t * vFanins ) { Abc_Obj_t * pNode; int i; pNode = Abc_NtkCreateNode( pNtk ); return pNode; } Here is…
Nuron
  • 109
  • 8
3
votes
1 answer

Creating Ruby Time objects from C extension

I am writing a C extension for Ruby, which needs to heavily use time objects. The performance is critical for this application. How should I go about creating Time objects from C API for maximum performance? I did not find anything relevant in…
Piotr Turek
  • 346
  • 1
  • 2
  • 11
3
votes
1 answer

Data modified when passing to C from Ruby using NUM2LL and NUM2INT

I have a C module that I am testing with Ruby test by extending ruby with this piece of C code. Any number above 2 ** 24 -1 is being modified. I need to pass 64-bit values back and forth between Ruby and C and it should be bit-precise. Any thoughts…
aalavi
  • 63
  • 5
3
votes
1 answer

Ruby C extension rb_str_new2 seems to return false

I cannot post my actual code due to work copyright, so I will try to show my problem with simple example code. I have a C extension whose simplified version looks like: #include #include #include #include…
mordocai
  • 83
  • 7
3
votes
1 answer

Ruby extension, transferring big data flow to ruby

My C library generates a very big array of POD structs. What is the most efficient way to pass it to Ruby side? On Ruby side a raw array of values is fine for me. My current solution works by storing each element and field separately and it is very…
ShPavel
  • 962
  • 1
  • 10
  • 17
3
votes
1 answer

How to efficiently merge two hashes in Ruby C API?

I am writing a C extension for Ruby that really needs to merge two hashes, however the rb_hash_merge() function is STATIC in Ruby 1.8.6. I have tried instead to use: rb_funcall(hash1, rb_intern("merge"), 1, hash2); but this is much too slow, and…
horseyguy
  • 29,455
  • 20
  • 103
  • 145
3
votes
2 answers

How to Statically Link External Libraries when Compiling a Ruby C Extension

I am building a Ruby C Extension on Windows which requires some external C libraries, specifically libcurl and its dependancies. I have the curllib dll's and .a files. However when I build with extconf.rb it always links the libraries dynamically…
Robin
  • 686
  • 1
  • 9
  • 18
3
votes
1 answer

Testing equality of symbols using the Ruby C API

I am trying to find a way to test symbol equality in the Ruby C API. Consider the following C function: static VALUE test_symbol_equality(VALUE self, VALUE symbol) { if (rb_intern("test") == symbol) { return Qtrue; } else { return…
user2398029
  • 6,699
  • 8
  • 48
  • 80
3
votes
1 answer

How to Compile a Ruby C Extension and link libcurl on Windows

I am trying to build a Ruby C Extensions that uses libcurl. So far I have built it sucessfully on Os X. However I am much less experienced developing in Windows and am not exactly sure how to go about doing this. So far I can compile a Ruby C…
Robin
  • 686
  • 1
  • 9
  • 18
3
votes
1 answer

Ruby C API `defined? SomeConstant` equivalent?

I'm trying to convert an if condition of: unless defined? SomeConstant # do some stuff end Into part of a native C extension. Does anybody know how to do the defined? predicate check in the C API? EDIT | I guess I could…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
3
votes
1 answer

Ruby C Bindings vs. Ruby Wrapper for System Calls

What are the major differences between the execution of Ruby C bindings vs. Ruby wrapper for system calls? To my question into context, I am looking into incorporating Git version control functionality heavily into a Ruby on Rails application. In…
rudolph9
  • 8,021
  • 9
  • 50
  • 80
3
votes
1 answer

How can I make rdoc properly read method arguments from my c extension?

all, I'm using rdoc to generate documentation for my Ruby code which contains C-extensions, but I'm having problems with my method arguments. Rdoc doesn't parse their names correctly and instead uses p1, p2 etc. So, first off, my extensions are…
hyperlogic
  • 7,525
  • 7
  • 39
  • 32
3
votes
3 answers

C library for graphs

Is there a good C library for graph theoretic manipulations? I particularly need to calculate the strongly connected components of a directed graph. I have implemented Tarjan's algorithm in Ruby as follows: def strongly_connected_components…
sawa
  • 165,429
  • 45
  • 277
  • 381