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

Ruby C extension gem doesn't compile at installation

I have a little project that I want to share via a gem. This extension must be compiled on the user system. So the compilation must be done when the gem is installed. My project is simple: tree …
cedlemo
  • 3,205
  • 3
  • 32
  • 50
1
vote
1 answer

How do you fully initialize an embedded ruby VM in a C++ application?

I am embedding ruby version 2.1.2 into a wxWidgets application, compiling on - and targeting - Windows. Linking to msvcrt-ruby210.dll and calling ruby_sysinit(&argc, &argv); RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); is enough to get me…
jared
  • 151
  • 2
  • 9
1
vote
3 answers

How does capitalize work?

I'm trying to understand how String#capitalize! works internally. I can create a hash. Given string foo = "the", foo[0] is "t", look up the lower_case "t", and match it with upper case "T" value. In fact, Ruby source shows: static…
MrPizzaFace
  • 7,807
  • 15
  • 79
  • 123
1
vote
0 answers

Ruby C extension dependencies

Problem I have an intuitive understanding of the difference between dynamic and static libraries. That said, I'm trying to write a C Extension that makes use of a third party library. I have compiled this library both statically and dynamically and…
1
vote
0 answers

Integer( :foo ) and NUM2INT( :foo ) work unexpectedly in 1.8.7

I make use of Integer( param ) in Ruby and NUM2INT( param ) in native extensions as a way of accepting any param that could be cast to an Integer in my public interfaces. Recently I came across a difference in behaviour between Ruby 1.8 and 1.9…
Neil Slater
  • 26,512
  • 6
  • 76
  • 94
1
vote
1 answer

Ruby C-Extension for manipulating Binary Data

I need to interface Ruby with a C-function which does low-level byte operations on a fixed-sized buffer (16 bytes length). I should also mention that I am using Ruby 1.8.7 for this, so no headaches with Ruby trying to figure out encodings. void…
Tilo
  • 33,354
  • 5
  • 79
  • 106
1
vote
2 answers

Should I use ALLOCA_N if I'm going to release the memory myself?

From the pickaxe: You may sometimes need to allocate memory in an extension tha t won’t be used for object storage—perhaps you have a giant bitmap for a Bloom filter, an image, or a whole bunch of little structures that Ruby doesn’t use…
fotanus
  • 19,618
  • 13
  • 77
  • 111
1
vote
1 answer

ruby c extension internal structure

readme.ext, which is linked in ruby guides as one of the main resources to develop ruby extensions, states the following: Notice Ruby does not allow arbitrary pointer values to be a VALUE. They should be pointers to the structures which Ruby…
fotanus
  • 19,618
  • 13
  • 77
  • 111
1
vote
0 answers

Is there any lock mechanism in ruby's C extension for thread safety?

Anything like python's Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS?
makisfan
  • 135
  • 1
  • 9
1
vote
1 answer

How do I convert a Proc to a block in a Ruby C extension?

I am storing an array of procs in a Ruby C extension and I need to go through and instance_eval each proc. The problem is that instance_eval only accepts blocks, not procs. This is not an issue in Ruby where I can simply go: proc_list.each {…
horseyguy
  • 29,455
  • 20
  • 103
  • 145
1
vote
1 answer

#include It's not working

I've made several attempts to find this information on the internet via google, this site, and a few others; I can't seem to find a good tutorial and/or answer on/for it. How would I go about using the Ruby C API in Visual C++ 2010? I've added Ruby…
FenixFyreX
  • 35
  • 3
1
vote
1 answer

How are local references to Ruby objects prevented from being collected

I'm in the situation, that I have to construct some larger ruby data structures in C++ code from within ruby threads and not ruby threads. Does ruby objects created on the stack have to be specially treated to not get collected by the ruby GC? Does…
Torsten Robitzki
  • 3,041
  • 1
  • 21
  • 35
1
vote
3 answers

Best way to extend Rails 3.2

I've got my custom controller, model, bunch of views, helpers and other stuff that encapsulates specific amount of User management functionality sufficient for rails apps my work involves. What I want is to create some kind of extension to be able…
imir
  • 11
  • 1
1
vote
1 answer

C++ std::string to Ruby VALUE

How can I convert a C++ std::string object into a Ruby VALUE object? I tried rb_str_new2(c_string), but it did not work. I have a function VALUE foo(){return rb_str_new2(c_string);}; and that gives an error message: cannot convert ‘std::string {aka…
sawa
  • 165,429
  • 45
  • 277
  • 381
1
vote
1 answer

How to convert a string taken out from a Ruby array into a C/C++ String

I rm writing a C++ extension for Ruby, and am trying to extract a Ruby string object out of a Ruby array object, and convert it to a C/C++ string object. I have foo.cpp: #include #include VALUE bar_func(VALUE self, VALUE ary){ …
sawa
  • 165,429
  • 45
  • 277
  • 381