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

Ruby C API - From ruby array to C array

I am passing an array (matrix) from Ruby to a C function. At the moment I am using the following code VALUE matmat_mul(VALUE self, VALUE matrixA, VALUE matrixB) { int rowsA = RARRAY_LEN(matrixA); VALUE firstElement = rb_ary_entry(matrixA,…
Rojj
  • 1,170
  • 1
  • 12
  • 32
2
votes
0 answers

"object allocation during garbage collection phase" Ruby C extension with openmp

I am creating a ruby c extension gem which uses openmp. What I am attempting to do is quite simple, just create a parallel for that will initialize a ruby array on each iteration. so, my gem files are: Visualize_helper.c which defines the…
Raphael Ottoni
  • 506
  • 3
  • 14
2
votes
1 answer

Can I pass information to my Rakefile from my extconf.rb?

I have a Ruby gem with a native extension that I am building with a Rake compiler ExtensionTask. I would like to take some action after the extension is built based on information calculated in extconf.rb. I tried writing the information to global…
murgatroid99
  • 19,007
  • 10
  • 60
  • 95
2
votes
0 answers

Memory management in ruby C extensions

I've started working with ruby C extensions. I'm having trouble understanding what the GC picks up and what not, and if you can actually manually free 'native' ruby objects (like Ruby arrays/strings) created in some C snippet earlier on. Lets look…
2
votes
1 answer

Ruby 1.9.1-p378 C Extension rb_block_call Weirdness

I'm working with what should be a fairly basic iteration. I understand that I could accomplish it with Ruby code, but I am working already in a C extension, so I would prefer to keep this function in C with the rest of the code- especially since…
Asher
  • 1,195
  • 1
  • 11
  • 19
2
votes
1 answer

ruby extension for clang crash with segfault when GC delete Index object

I am trying to write a little ruby extension for the c interface of clang. I am focusing on the CXIndex structure that I wrapp in a Clangc::Index class. I am able to compile it, load the module and create some Clangc::Index class like in this…
cedlemo
  • 3,205
  • 3
  • 32
  • 50
2
votes
1 answer

extconf.rb how to define the sources files to use

I have a little projet of a ruby extension which was organized like this : ./ Rakefile ext/ mymodule/ extconf.rb mymodule.rb mymodule.cpp source1.h source1.cpp source2.h source2.cpp Everything…
cedlemo
  • 3,205
  • 3
  • 32
  • 50
2
votes
1 answer

calling IO Operations from thread in ruby c extension will cause ruby to hang

I have a problem with using threads in a C Extension to run ruby code async. I have the following C code: struct DATA { VALUE callback; pthread_t watchThread; void *ptr; }; void *executer(void *ptr) { struct DATA *data = (struct DATA *)…
Racer
  • 534
  • 1
  • 6
  • 11
2
votes
1 answer

Dropping down in Assembly from Ruby by way of C?

Since Ruby lets you drop down into C for any bits where performance is critical and plain Ruby is not up to the task, and since C lets you drop down into assembly for the same sort of circumstance, I've always wondered if it would be possible to…
iconoclast
  • 21,213
  • 15
  • 102
  • 138
2
votes
0 answers

Call a proc in Ruby C extension

I have the following struct: typedef struct{ int a; int (*init)(void); } tObj; I am wrapping this into an object 'ObjExt' in Ruby. Ruby initialization method gets a Proc 'cb' that shall be run anytime 'init' function is called somewhere to…
aalavi
  • 63
  • 5
2
votes
0 answers

Error finding opencv shared libraries with Rice (Ruby) on Ubuntu 12.04

I'm trying to correctly link OpenCV shared libraries to a ruby c++ extension and for some reason any call to have_library() is failing for the opencv libraries. I installed opencv to /usr/local so the header files are all in /usr/local/include and…
aembke
  • 21
  • 2
2
votes
1 answer

Why does gem not auto compile my C extension

I build a Ruby gem, which needs some C extension. This one - once compiled - is bound via Ruby FFI into the gem. My setup: I use bundle for the gem scaffolding. Inside my gems folder I have a subfolder ext. This one includes a static Makefile,…
GeorgieF
  • 2,687
  • 5
  • 29
  • 43
2
votes
0 answers

How do I wrap a C function and pass it parameters?

I have to wrap this C function Abc_NtkCreateNodeAnd using Ruby: Abc_Obj_t * Abc_NtkCreateNodeAnd( Abc_Ntk_t * pNtk, Vec_Ptr_t * vFanins ) { Abc_Obj_t * pNode; int i; assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsNetlist(pNtk) ); pNode =…
Nuron
  • 109
  • 8
2
votes
1 answer

pg_ext throws 'C extension initialized against invalid ruby runtime' on jruby (rvm)

I have a project working on Ruby-1.9.3-p392 and i try to load it with Jruby (jruby-head installed with rvm, it is currently jruby 1.7.4.dev (1.9.3p392)) All rake tasks fail with the following trace bundle exec rake -T rake aborted! load error:…
Nox
  • 395
  • 3
  • 22
2
votes
2 answers

Ruby C extension, how to recover from segmentation fault

I've written a simple Ruby C extension. A method expects the second parameter to be a string-ish VALUE. VALUE method_foo(VALUE self, VALUE key) { puts(RSTRING(key)->ptr); return key; } Its very easy to cause a segmentation fault by passing…
Josh Petitt
  • 9,371
  • 12
  • 56
  • 104