blackwinter / rb-gsl

Ruby interface to the GNU Scientific Library [Ruby 2.x and GSL 1.16 compatible fork of the gsl gem]
https://blackwinter.github.io/rb-gsl
Other
27 stars 7 forks source link

Rubinius support #28

Open edmundhighcock opened 9 years ago

edmundhighcock commented 9 years ago

Hi all,

Thanks for your continued work on this very useful gem.

Just out of interest, has anyone had a look at making this Rubinius compatible? How much work would it be? I'm interested in looking at it at some point, but just wanted to see what, if anything had been attemped.

A quick attempt to build it in Rubinius seems to a show a lot of the source files building without a hitch (see below), so maybe it's not too bad.

Edmund

compiling alf.c                                                            
compiling array.c                                                          
compiling array_complex.c                                                  
compiling blas.c                                                           
compiling blas1.c                                                          
compiling blas2.c                                                          
compiling blas3.c                                                          
compiling block.c                                                          
compiling bspline.c                                                        
compiling bundle.c                                                         
compiling cdf.c                                                            
compiling cheb.c                                                           
compiling combination.c                                                    
compiling common.c                                                         
compiling complex.c                                                        
compiling const.c                                                          
compiling const_additional.c                                               
compiling cqp.c                                                            
compiling deriv.c                                                          
compiling dht.c                                                            
compiling diff.c                                                           
compiling dirac.c                                                          
compiling eigen.c                                                          
compiling error.c                                                          
compiling fcmp.c                                                           
compiling fft.c                                                            
compiling fit.c                                                            
compiling fresnel.c                                                        
fresnel.c:17:21: warning: unused variable 'sqrt_pi_2' [-Wunused-const-variable]                                                                       
static const double sqrt_pi_2   = 1.2533141373155002512078826424; /* sqrt(pi/2) */                                                                    
                    ^                                                      
1 warning generated.                                                       
compiling function.c                                                       
compiling geometry.c                                                       
compiling graph.c                                                          
compiling gsl.c                                                            
compiling gsl_narray.c                                                     
compiling histogram.c                                                      
compiling histogram2d.c                                                    
histogram2d.c:481:36: warning: incompatible pointer to integer conversion passing 'gsl_histogram2d *' to parameter of type 'intptr_t' (aka 'long') [-Wint-conversion]                                                            
  return Data_Wrap_Struct(CLASS_OF(h1), 0, gsl_histogram2d_free, hnew);    
                                   ^~                                      
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:851:27: note: expanded from macro 'Data_Wrap_Struct'                           
    rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))                                                                
                          ^                                                
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:1119:26: note: passing argument to parameter 'object' here                     
  VALUE   CLASS_OF(VALUE object);                                          
                         ^                                                 
histogram2d.c:496:36: warning: incompatible pointer to integer conversion passing 'gsl_histogram2d *' to parameter of type 'intptr_t' (aka 'long') [-Wint-conversion]                                                            
  return Data_Wrap_Struct(CLASS_OF(h1), 0, gsl_histogram2d_free, hnew);    
                                   ^~                                      
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:851:27: note: expanded from macro 'Data_Wrap_Struct'                           
    rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))                                                                
                          ^                                                
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:1119:26: note: passing argument to parameter 'object' here                     
  VALUE   CLASS_OF(VALUE object);                                          
                         ^                                                 
histogram2d.c:511:36: warning: incompatible pointer to integer conversion passing 'gsl_histogram2d *' to parameter of type 'intptr_t' (aka 'long') [-Wint-conversion]                                                            
  return Data_Wrap_Struct(CLASS_OF(h1), 0, gsl_histogram2d_free, hnew);    
                                   ^~                                      
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:851:27: note: expanded from macro 'Data_Wrap_Struct'                           
    rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))                                                                
                          ^                                                
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:1119:26: note: passing argument to parameter 'object' here                     
  VALUE   CLASS_OF(VALUE object);                                          
                         ^                                                 
histogram2d.c:526:36: warning: incompatible pointer to integer conversion passing 'gsl_histogram2d *' to parameter of type 'intptr_t' (aka 'long') [-Wint-conversion]                                                            
  return Data_Wrap_Struct(CLASS_OF(h1), 0, gsl_histogram2d_free, hnew);    
                                   ^~                                      
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:851:27: note: expanded from macro 'Data_Wrap_Struct'                           
    rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))                                                                
                          ^                                                
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:1119:26: note: passing argument to parameter 'object' here                     
  VALUE   CLASS_OF(VALUE object);                                          
                         ^                                                 
histogram2d.c:536:36: warning: incompatible pointer to integer conversion passing 'gsl_histogram2d *' to parameter of type 'intptr_t' (aka 'long') [-Wint-conversion]                                                            
  return Data_Wrap_Struct(CLASS_OF(h1), 0, gsl_histogram2d_free, hnew);    
                                   ^~                                      
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:851:27: note: expanded from macro 'Data_Wrap_Struct'                           
    rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))                                                                
                          ^                                                
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:1119:26: note: passing argument to parameter 'object' here                     
  VALUE   CLASS_OF(VALUE object);                                          
                         ^                                                 
histogram2d.c:546:36: warning: incompatible pointer to integer conversion passing 'gsl_histogram2d *' to parameter of type 'intptr_t' (aka 'long') [-Wint-conversion]                                                            
  return Data_Wrap_Struct(CLASS_OF(h1), 0, gsl_histogram2d_free, hnew);    
                                   ^~                                      
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:851:27: note: expanded from macro 'Data_Wrap_Struct'                           
    rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))                                                                
                          ^                                                
/home/edmundhighcock/.rvm/rubies/rbx-2.5.2/vm/include/capi/ruby/ruby.h:1119:26: note: passing argument to parameter 'object' here                     
  VALUE   CLASS_OF(VALUE object);                                          
                         ^                                                 
6 warnings generated.                                                      
compiling histogram3d.c                                                    
compiling histogram3d_source.c                                             
compiling histogram_find.c                                                 
compiling histogram_oper.c                                                 
compiling ieee.c                                                           
compiling integration.c                                                    
compiling interp.c                                                         
compiling jacobi.c                                                         
compiling linalg.c                                                         
linalg.c:73:5: warning: implicit declaration of function 'RBASIC' is invalid in C99 [-Wimplicit-function-declaration]                                 
    RBGSL_SET_CLASS(omatrix, cgsl_matrix_LU);                              
    ^                                                                      
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS' 
  RBGSL_SET_CLASS0(_obj_, cls); \                                          
  ^                                                                        
include/rb_gsl_common.h:301:37: note: expanded from macro 'RBGSL_SET_CLASS0'                                                                          
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls              
                                    ^                                      
linalg.c:73:5: error: member reference type 'int' is not a pointer         
    RBGSL_SET_CLASS(omatrix, cgsl_matrix_LU);                              
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                               
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS' 
  RBGSL_SET_CLASS0(_obj_, cls); \                                          
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~                                             
include/rb_gsl_common.h:301:51: note: expanded from macro 'RBGSL_SET_CLASS0'                                                                          
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls              
                                    ~~~~~~~~~~~~  ^                        
linalg.c:694:5: error: member reference type 'int' is not a pointer        
    RBGSL_SET_CLASS(mdecomp, cgsl_matrix_QR);                              
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                               
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS' 
  RBGSL_SET_CLASS0(_obj_, cls); \                                          
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~                                             
include/rb_gsl_common.h:301:51: note: expanded from macro 'RBGSL_SET_CLASS0'                                                                          
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls              
                                    ~~~~~~~~~~~~  ^                        
linalg.c:706:5: error: member reference type 'int' is not a pointer        
    RBGSL_SET_CLASS(mdecomp, cgsl_matrix_LQ);                              
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                               
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS' 
  RBGSL_SET_CLASS0(_obj_, cls); \                                          
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~                                             
include/rb_gsl_common.h:301:51: note: expanded from macro 'RBGSL_SET_CLASS0'                                                                          
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls              
                                    ~~~~~~~~~~~~  ^                        
linalg.c:733:7: error: member reference type 'int' is not a pointer        
      RBGSL_SET_CLASS(argv[itmp], cgsl_vector_tau);                        
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                         
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS' 
  RBGSL_SET_CLASS0(_obj_, cls); \                                          
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~                                             
include/rb_gsl_common.h:301:51: note: expanded from macro 'RBGSL_SET_CLASS0'                                                                          
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls              
                                    ~~~~~~~~~~~~  ^                        
linalg.c:742:7: error: member reference type 'int' is not a pointer        
      RBGSL_SET_CLASS(argv[itmp], cgsl_vector_tau);                        
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                         
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS' 
  RBGSL_SET_CLASS0(_obj_, cls); \                                          
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~                                             
include/rb_gsl_common.h:301:51: note: expanded from macro 'RBGSL_SET_CLASS0'                                                                          
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls              
                                    ~~~~~~~~~~~~  ^                        
linalg.c:1630:5: error: member reference type 'int' is not a pointer       
    RBGSL_SET_CLASS(vA, cgsl_matrix_QRPT);                                 
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                  
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS' 
  RBGSL_SET_CLASS0(_obj_, cls); \                                          
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~                                             
include/rb_gsl_common.h:301:51: note: expanded from macro 'RBGSL_SET_CLASS0'
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls
                                    ~~~~~~~~~~~~  ^
linalg.c:1637:5: error: member reference type 'int' is not a pointer
    RBGSL_SET_CLASS(vA, cgsl_matrix_PTLQ);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/rb_gsl_common.h:305:3: note: expanded from macro 'RBGSL_SET_CLASS'
  RBGSL_SET_CLASS0(_obj_, cls); \
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/rb_gsl_common.h:301:51: note: expanded from macro 'RBGSL_SET_CLASS0'
#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls
                                    ~~~~~~~~~~~~  ^
1 warning and 7 errors generated.
Makefile:205: recipe for target 'linalg.o' failed
make: *** [linalg.o] Error 1

make failed, exit code 2
edmundhighcock commented 9 years ago

I have also posted in the Rubinius forums to try and get help from the rbx developers.

https://github.com/rubinius/rubinius/issues/2006#issuecomment-114057943

edmundhighcock commented 9 years ago

The patch below was sufficient to allow rake compile to work with rubinius... the RBASIC macro is now deprecated in 2.x according to this page:

http://docs.ruby-lang.org/en/2.1.0/README_EXT.html

However, of course, I'm not sure if rb_obj_hide and rb_obj_reveal are supported in 1.x.

diff --git a/ext/gsl_native/include/rb_gsl_common.h b/ext/gsl_native/include/rb_gsl_common.h
index 39c3330..f290583 100644
--- a/ext/gsl_native/include/rb_gsl_common.h
+++ b/ext/gsl_native/include/rb_gsl_common.h
@@ -290,11 +290,12 @@ EXTERN ID rb_gsl_id_beg, rb_gsl_id_end, rb_gsl_id_excl, rb_gsl_id_to_a;
     rb_raise(rb_eTypeError, "wrong argument type (GSL::Histogram expected)");
 #endif

+
 #ifndef RBGSL_SET_CLASS
 #ifdef RB_OBJ_WRITE
 #define RBGSL_SET_CLASS0(obj0, cls) RB_OBJ_WRITE(obj0, &(RBASIC_CLASS(obj0)), cls)
 #else
-#define RBGSL_SET_CLASS0(obj0, cls) RBASIC(obj0)->klass = cls
+#define RBGSL_SET_CLASS0(obj0, cls) rb_obj_hide(obj0); rb_obj_reveal(obj0,cls)
 #endif
 #define RBGSL_SET_CLASS(obj, cls) do { \
     VALUE _obj_ = (obj); \
edmundhighcock commented 9 years ago

So rake compile works with rbx 2.0.

rake test gives the error below, which is something I've not seen before, coming from MRI. Google doesn't reveal anything on it.

An exception occurred running /home/edmundhighcock/.rvm/gems/rbx-2.5.2@global/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:

wrong number of arguments (ArgumentError)

Backtrace:

         Rubinius.open_module_under at kernel/delta/rubinius.rb:37
                  Object#__script__ at lib/gsl/oper.rb:1
       Rubinius::CodeLoader.require at kernel/common/code_loader.rb:247
             Kernel(Object)#require at kernel/common/kernel.rb:755
                  Object#__script__ at lib/gsl.rb:8
       Rubinius::CodeLoader.require at kernel/common/code_loader.rb:247
             Kernel(Object)#require at kernel/common/kernel.rb:755
                  Object#__script__ at test/test_helper.rb:2
       Rubinius::CodeLoader.require at kernel/common/code_loader.rb:247
             Kernel(Object)#require at kernel/common/kernel.rb:755
                  Object#__script__ at test/gsl_test.rb:1
       Rubinius::CodeLoader.require at kernel/common/code_loader.rb:247
             Kernel(Object)#require at kernel/common/kernel.rb:755
          { } in Object#__script__ at /home/edmundhighcock/.rvm/gems
                                      /rbx-2.5.2@global/gems/rake-10.4.2
                                      /lib/rake/rake_test_loader.rb:15
  { } in Enumerable(Array)#find_all at kernel/common/enumerable.rb:465
                         Array#each at kernel/bootstrap/array.rb:76
  Enumerable(Array)#select (find_all) at kernel/common/enumerable.rb:463
                 Object#__script__ at /home/edmundhighcock/.rvm/gems
                                      /rbx-2.5.2@global/gems/rake-10.4.2
                                      /lib/rake/rake_test_loader.rb:4
   Rubinius::CodeLoader#load_script at kernel/delta/code_loader.rb:66
   Rubinius::CodeLoader.load_script at kernel/delta/code_loader.rb:152
            Rubinius::Loader#script at kernel/loader.rb:655
              Rubinius::Loader#main at kernel/loader.rb:809
rake aborted!