ruby-c-extension

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

核能气质少年 提交于 2020-01-03 03:00:39
问题 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 *) ptr; char oldVal[20] = "1"; char newVal[20] = "1"; pthread_cleanup_push(&threadGarbageCollector, data); while(1) { if(triggerReceived) { rb_funcall(data->callback, rb_intern("call"), 0); } } pthread_cleanup_pop(1); return NULL; } VALUE spawn_thread(VALUE self)

How do I access a ruby array from my c extension?

对着背影说爱祢 提交于 2019-12-21 05:55:13
问题 I'm getting this error ev.c:11: error: subscripted value is neither array nor pointer for this line printf("%d\n", pairs[0][0]); In this code static VALUE EV; static VALUE PairCounter; static VALUE sort_pairs_2(VALUE self) { VALUE pairs; pairs = rb_ivar_get(self, rb_intern("pairs")); printf("%d\n", pairs[0][0]); return Qnil; } void Init_ev() { rb_eval_string("require './lib/ev/pair_counter'"); VALUE PairCounter = rb_path2class("EV::PairCounter"); rb_define_method(PairCounter, "sort_pairs_2",

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

守給你的承諾、 提交于 2019-12-18 04:28:07
问题 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 Extensions using extconf.rb and nmake from the Visual Studio Command Prompt more or less by following these instructions http://blogs.law.harvard.edu/hoanga/2006/12/14/getting-a-ruby-c-extension-to-compile-on-windows/ However my Extension links libcurl,

pg_ext.so: undefined symbol: rb_thread_select

我的梦境 提交于 2019-12-12 07:01:23
问题 bash-4.2# rake db:create /opt/rubystack-2.3.1-0/ruby/bin/.ruby.bin: symbol lookup error: /opt/rubystack-2.3.1-0/ruby/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.so: undefined symbol: rb_thread_select bash-4.2# ruby -v ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux] bash-4.2# rails -v Rails 4.2.6 bash-4.2# gem list pg *** LOCAL GEMS *** pg (0.18.4, 0.15.1) what's the problem? it's bitnami's ruby stack. NOTE: It's NOT pg version's bug? Please check my log! Ruby version 2.3.1, pg

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

谁都会走 提交于 2019-12-08 05:13:12
问题 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: error: ruby/config.h: No such file or directory In file included from rubyext.c:1: /usr/local/include/ruby-1.9.1/ruby/ruby.h:107: error: ‘SIZEOF_INT’ undeclared here (not in a function) /usr/local/include/ruby-1.9.1/ruby/ruby.h:108: error: ‘SIZEOF

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

情到浓时终转凉″ 提交于 2019-12-07 23:38:26
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 *) ptr; char oldVal[20] = "1"; char newVal[20] = "1"; pthread_cleanup_push(&threadGarbageCollector, data); while(1) { if(triggerReceived) { rb_funcall(data->callback, rb_intern("call"), 0); } } pthread_cleanup_pop(1); return NULL; } VALUE spawn_thread(VALUE self) { VALUE block; struct DATA *data; Data_Get_Struct(self, struct DATA, data); block = rb_block_proc();

Passing ruby array values into a C array

与世无争的帅哥 提交于 2019-12-06 04:43:23
问题 I'm trying to make a standalone FFT extension for ruby in C, based on this recipe I've noted several methods for passing different values between ruby and c. However im fairly new to both ruby and C and can't work out how to copy an array from a VALUE ruby object into a C array. The compilation error: SimpleFFT.c:47: error: subscripted value is neither array nor pointer And the code: #include "ruby.h" #include "fft.c" // the c file I wish to wrap in ruby VALUE SimpleFFT = Qnil; void Init

Passing ruby array values into a C array

故事扮演 提交于 2019-12-04 11:35:20
I'm trying to make a standalone FFT extension for ruby in C, based on this recipe I've noted several methods for passing different values between ruby and c. However im fairly new to both ruby and C and can't work out how to copy an array from a VALUE ruby object into a C array. The compilation error: SimpleFFT.c:47: error: subscripted value is neither array nor pointer And the code: #include "ruby.h" #include "fft.c" // the c file I wish to wrap in ruby VALUE SimpleFFT = Qnil; void Init_simplefft(); VALUE method_rfft(VALUE self, VALUE anObject); void Init_simplefft() { SimpleFFT = rb_define

Native extensions fallback to pure Ruby if not supported on gem install

穿精又带淫゛_ 提交于 2019-12-03 12:13:42
问题 I am developing a gem, which is currently pure Ruby, but I have also been developing a faster C variant for one of the features. The feature is usable, but sometimes slow, in pure Ruby. The slowness would only impact some of the potential users (depends which features they need, and how they use them), so it makes sense to have the gem available with graceful fallback to Ruby-only functions if it cannot compile on a target system. I would like to maintain the Ruby and C variants of the

Ruby C extensions API questions

这一生的挚爱 提交于 2019-12-03 03:54:49
问题 So, recently I had the unfortunate need to make a C extension for Ruby (because of performance). Since I was having problems with understanding VALUE (and still do), so I looked into the Ruby source and found: typedef unsigned long VALUE; (Link to Source, but you will notice that there are a few other 'ways' it's done, but I think it's essentially a long ; correct me if I'm wrong). So, while investigating this further I found an interesting blog post, which says: "...in some cases the VALUE