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

How do I add link targets to Ruby mkmf?

In my Ruby extension, the code is organized into directories, with extconf.rb sitting at the root of the tree among the main library files. The problem with this setup is that all files inside directories are not being linked against my library.…
Matheus Moreira
  • 17,106
  • 3
  • 68
  • 107
1
vote
1 answer

What is the C++ equivalent of binary.write in Golang?

I am working on project in C++ that adopts many ideas from a golang project. I don't properly understand how this binary.write works from the documentation and how I can replicate it in C++. I am stuck at this line in my…
ArafatK
  • 740
  • 6
  • 25
1
vote
2 answers

How do I create a Date object in a Ruby C extension?

I'm trying to do something like this but I'm having trouble understanding how to use Ruby internals in my C code. static VALUE func_get_date_object(VALUE self, VALUE vdate){ VALUE rb_date; VALUE date; rb_date = rb_funcall(rb_intern("Date"),…
Douglas G. Allen
  • 2,203
  • 21
  • 20
1
vote
1 answer

How do you fully Reinitialize an embedded ruby VM in a C (actually swift) application?

I'm using the C Ruby Interface to embed a ruby interpreter in a swift application (though, that I'm using swift is irrelevant Imo) I feel like Ruby must have some way of completely reinitializing itself. I'm initializing the vm like so: var…
Joe Daniels
  • 1,646
  • 1
  • 11
  • 9
1
vote
1 answer

How do I compile/create a ruby extension that uses c?

I want to create a ruby extension that uses c. But when I compile it with gcc, I am getting this error: gcc rubyext.c -orubyext -I /usr/local/include/ruby-1.9.1/ In file included from rubyext.c:1: /usr/local/include/ruby-1.9.1/ruby/ruby.h:25:25:…
Joshua Partogi
  • 16,167
  • 14
  • 53
  • 75
1
vote
1 answer

C - Allocate a struct within a function using the struct pointer as argument

I am working with the Ruby C API. I need to create a struct from within a function but I think I am making some allocation error. This is my code #include #include #include typedef struct { double *matrix; …
Rojj
  • 1,170
  • 1
  • 12
  • 32
1
vote
1 answer

Ruby C Extensions - Add System Frameworks

I am building a C extension that uses the Mac OSX Accelerate Framework. When I compile normal C code I include the header #include and compile with llvm-gcc -framework Accelerate code.c -o code The flag takes care of…
Rojj
  • 1,170
  • 1
  • 12
  • 32
1
vote
1 answer

Ruby Global Interpreter Lock (GIL) - rb_thread_call_without_gvl

I am struggling to pass arguments to rb_thread_call_without_gvl. This is the simple code I am using. #include #include #include VALUE summa(VALUE self, VALUE x) { double result; result = NUM2DBL(x) +…
Rojj
  • 1,170
  • 1
  • 12
  • 32
1
vote
1 answer

Is the usage of rb_protect mandatory when we use rb_funcall

I have started to write a ruby module for the clang-c library. I wrapp in my clang c module this unsigned clang_visitChildren(CXCursor parent, CXCursorVisitor visitor, CXClientData…
cedlemo
  • 3,205
  • 3
  • 32
  • 50
1
vote
2 answers

How do I get info from g++ COLLECT_LTO_WRAPPER into a make generated .so file?

When I compile a c++ program using g++ from the command line and then do ldd a.out ldd is able to find libstdc++.a(libstdc++.so.6) When I build a c++ ruby extension ldd myext.so cannot find libstdc++.a(libstdc++.so.6), and require 'myext' fails to…
nPn
  • 16,254
  • 9
  • 35
  • 58
1
vote
1 answer

Ruby C(++) Extension not finding init function symbol in .so file

So right now I'm just trying out C/C++ extensions in Ruby and I'm having troubles while using the rake-compile gem. Right now all I'm trying to do is define a module, and it won't load the Init_* function because it says the symbol is undefined. But…
SeedyROM
  • 2,203
  • 1
  • 18
  • 22
1
vote
1 answer

Ruby Gems C extension example not working

I am trying to follow this tutorial on building c extension in ruby gems http://guides.rubygems.org/gems-with-extensions/. I have the following files: ext/my_malloc/extconf.rb require "mkmf" abort "missing malloc()" unless have_func "malloc" abort…
Daniel Nill
  • 5,539
  • 10
  • 45
  • 63
1
vote
1 answer

Ruby C Extension using Singleton

I only wanted to allow one instance of my C extension class to be made, so I wanted to include the singleton module. void Init_mousetest() { VALUE mouseclass = rb_define_class("MyMouse",rb_cObject); rb_require("singleton"); VALUE…
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
1
vote
0 answers

How do I set c flags in the Rakefile for compilation of extensions via extension task?

I have a Rakefile on Github: require 'rubygems' require 'rubygems/package_task' require 'bundler' Bundler::GemHelper.install_tasks require 'rake' require 'rake/extensiontask' Rake::ExtensionTask.new do |ext| ext.name = 'symengine' …
1
vote
1 answer

Unit testing with Rspec and C extensions

Every body seems to be talking about TDD and BDD these days so i thought i give it a try on a smallish home project. A short backgrund I am developing a class Device in a C extension that interacts with a native C API for controlling remote devices…
Patrik
  • 255
  • 3
  • 11