Created
April 17, 2014 13:50
-
-
Save terceiro/10985008 to your computer and use it in GitHub Desktop.
port ruby-gsl to Ruby 2.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- a/ext/linalg.c | |
| +++ b/ext/linalg.c | |
| @@ -14,6 +14,7 @@ | |
| #include "rb_gsl_array.h" | |
| #include "rb_gsl_common.h" | |
| #include "rb_gsl_linalg.h" | |
| +#include "porting.h" | |
| static VALUE cgsl_matrix_LU; | |
| static VALUE cgsl_matrix_QR; | |
| @@ -71,7 +72,7 @@ static VALUE rb_gsl_linalg_LU_decomposit | |
| Data_Get_Struct(omatrix, gsl_matrix, mtmp); | |
| if (flag == LINALG_DECOMP_BANG) { | |
| m = mtmp; | |
| - RBASIC(omatrix)->klass = cgsl_matrix_LU; | |
| + rb_obj_reveal(omatrix, cgsl_matrix_LU); | |
| objm = omatrix; | |
| } else { | |
| m = make_matrix_clone(mtmp); | |
| @@ -692,7 +693,7 @@ static VALUE rb_gsl_linalg_QR_LQ_decompo | |
| fdecomp = &gsl_linalg_QR_decomp; | |
| m = mtmp; | |
| mdecomp = omatrix; | |
| - RBASIC(mdecomp)->klass = cgsl_matrix_QR; | |
| + rb_obj_reveal(mdecomp, cgsl_matrix_QR); | |
| break; | |
| #ifdef GSL_1_6_LATER | |
| case LINALG_LQ_DECOMP: | |
| @@ -704,7 +705,7 @@ static VALUE rb_gsl_linalg_QR_LQ_decompo | |
| fdecomp = &gsl_linalg_LQ_decomp; | |
| m = mtmp; | |
| mdecomp = omatrix; | |
| - RBASIC(mdecomp)->klass = cgsl_matrix_LQ; | |
| + rb_obj_reveal(mdecomp, cgsl_matrix_LQ); | |
| break; | |
| #endif | |
| default: | |
| @@ -731,7 +732,7 @@ static VALUE rb_gsl_linalg_QR_LQ_decompo | |
| vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau); | |
| return rb_ary_new3(2, mdecomp, vtau); | |
| } else { | |
| - RBASIC(argv[itmp])->klass = cgsl_vector_tau; | |
| + rb_obj_reveal(argv[itmp], cgsl_vector_tau); | |
| return mdecomp; | |
| } | |
| break; | |
| @@ -740,7 +741,7 @@ static VALUE rb_gsl_linalg_QR_LQ_decompo | |
| if (argc == itmp) { | |
| return Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau); | |
| } else { | |
| - RBASIC(argv[itmp])->klass = cgsl_vector_tau; | |
| + rb_obj_reveal(argv[itmp], cgsl_vector_tau); | |
| return INT2FIX(status); | |
| } | |
| break; | |
| @@ -1628,14 +1629,14 @@ static VALUE rb_gsl_linalg_QRLQPT_decomp | |
| norm = gsl_vector_alloc(size0); | |
| switch (flag) { | |
| case LINALG_QRPT: | |
| - RBASIC(vA)->klass = cgsl_matrix_QRPT; | |
| + rb_obj_reveal(vA, cgsl_matrix_QRPT); | |
| vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau); | |
| vp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p); | |
| gsl_linalg_QRPT_decomp(A, tau, p, &signum, norm); | |
| break; | |
| #ifdef GSL_1_6_LATER | |
| case LINALG_PTLQ: | |
| - RBASIC(vA)->klass = cgsl_matrix_PTLQ; | |
| + rb_obj_reveal(vA, cgsl_matrix_PTLQ); | |
| vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau); | |
| vp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p); | |
| gsl_linalg_PTLQ_decomp(A, tau, p, &signum, norm); | |
| --- a/ext/linalg_complex.c | |
| +++ b/ext/linalg_complex.c | |
| @@ -14,6 +14,7 @@ | |
| #include "rb_gsl_array.h" | |
| #include "rb_gsl_common.h" | |
| #include "rb_gsl_linalg.h" | |
| +#include "porting.h" | |
| EXTERN VALUE mgsl_linalg; | |
| EXTERN VALUE cgsl_complex; | |
| @@ -51,8 +52,8 @@ VALUE rb_gsl_linalg_complex_LU_decomp(in | |
| case 0: | |
| p = gsl_permutation_alloc(size); | |
| gsl_linalg_complex_LU_decomp(m, p, &signum); | |
| - if (itmp == 1) RBASIC(argv[0])->klass = cgsl_matrix_complex_LU; | |
| - else RBASIC(obj)->klass = cgsl_matrix_complex_LU; | |
| + if (itmp == 1) rb_obj_reveal(argv[0], cgsl_matrix_complex_LU); | |
| + else rb_obj_reveal(obj, cgsl_matrix_complex_LU); | |
| obj2 = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p); | |
| return rb_ary_new3(2, obj2, INT2FIX(signum)); | |
| break; | |
| @@ -60,8 +61,8 @@ VALUE rb_gsl_linalg_complex_LU_decomp(in | |
| CHECK_PERMUTATION(argv[itmp]); | |
| Data_Get_Struct(argv[itmp], gsl_permutation, p); | |
| gsl_linalg_complex_LU_decomp(m, p, &signum); | |
| - if (itmp == 1) RBASIC(argv[0])->klass = cgsl_matrix_complex_LU; | |
| - else RBASIC(obj)->klass = cgsl_matrix_complex_LU; | |
| + if (itmp == 1) rb_obj_reveal(argv[0], cgsl_matrix_complex_LU); | |
| + else rb_obj_reveal(obj, cgsl_matrix_complex_LU); | |
| return INT2FIX(signum); | |
| break; | |
| default: | |
| --- a/ext/ool.c | |
| +++ b/ext/ool.c | |
| @@ -2,6 +2,7 @@ | |
| #include "rb_gsl.h" | |
| #include "rb_gsl_array.h" | |
| #include <ool/ool_conmin.h> | |
| +#include "porting.h" | |
| static VALUE cool_conmin_function; | |
| static VALUE cool_conmin_constraint; | |
| @@ -770,7 +771,7 @@ static VALUE rb_ool_conmin_pgrad_paramet | |
| VALUE ary; | |
| ool_conmin_parameters_default(ool_conmin_minimizer_pgrad, (void*) &P); | |
| ary = create_parameters_ary_pgrad(&P); | |
| - RBASIC(ary)->klass = cool_conmin_pgrad_parameters; | |
| + rb_obj_reveal(ary, cool_conmin_pgrad_parameters); | |
| return ary; | |
| } | |
| @@ -780,7 +781,7 @@ static VALUE rb_ool_conmin_spg_parameter | |
| VALUE ary; | |
| ool_conmin_parameters_default(ool_conmin_minimizer_spg, (void*) &P); | |
| ary = create_parameters_ary_spg(&P); | |
| - RBASIC(ary)->klass = cool_conmin_spg_parameters; | |
| + rb_obj_reveal(ary, cool_conmin_spg_parameters); | |
| return ary; | |
| } | |
| @@ -790,7 +791,7 @@ static VALUE rb_ool_conmin_gencan_parame | |
| VALUE ary; | |
| ool_conmin_parameters_default(ool_conmin_minimizer_gencan, (void*) &P); | |
| ary = create_parameters_ary_gencan(&P); | |
| - RBASIC(ary)->klass = cool_conmin_gencan_parameters; | |
| + rb_obj_reveal(ary, cool_conmin_gencan_parameters); | |
| return ary; | |
| } | |
| --- /dev/null | |
| +++ b/ext/porting.h | |
| @@ -0,0 +1,5 @@ | |
| +#include <ruby/version.h> | |
| + | |
| +#if RUBY_API_VERSION_CODE < 20100 | |
| + #define rb_obj_reveal(o,k) RBASIC(o)->klass = k | |
| +#endif | |
| --- a/ext/vector_complex.c | |
| +++ b/ext/vector_complex.c | |
| @@ -11,6 +11,7 @@ | |
| #include "rb_gsl_config.h" | |
| #include "rb_gsl_array.h" | |
| #include "rb_gsl_complex.h" | |
| +#include "porting.h" | |
| EXTERN VALUE cgsl_complex; | |
| static VALUE rb_gsl_vector_complex_inner_product(int argc, VALUE *argv, VALUE obj); | |
| @@ -939,9 +940,9 @@ static VALUE rb_gsl_vector_complex_trans | |
| static VALUE rb_gsl_vector_complex_trans2(VALUE obj) | |
| { | |
| if (CLASS_OF(obj) == cgsl_vector_complex) | |
| - RBASIC(obj)->klass = cgsl_vector_complex_col; | |
| + rb_obj_reveal(obj, cgsl_vector_complex_col); | |
| else if (CLASS_OF(obj) == cgsl_vector_complex_col) | |
| - RBASIC(obj)->klass = cgsl_vector_complex; | |
| + rb_obj_reveal(obj, cgsl_vector_complex); | |
| else { | |
| rb_raise(rb_eRuntimeError, "method trans! for %s is forbidden", | |
| rb_class2name(CLASS_OF(obj))); | |
| --- a/ext/vector_source.c | |
| +++ b/ext/vector_source.c | |
| @@ -36,6 +36,8 @@ | |
| #define VEC_VIEW_P VECTOR_INT_VIEW_P | |
| #endif | |
| +#include "porting.h" | |
| + | |
| void FUNCTION(get_range,beg_en_n)(VALUE range, BASE *beg, BASE *en, size_t *n, int *step); | |
| void get_range_beg_en_n_for_size(VALUE range, | |
| @@ -673,15 +675,15 @@ static VALUE FUNCTION(rb_gsl_vector,tran | |
| static VALUE FUNCTION(rb_gsl_vector,trans_bang)(VALUE obj) | |
| { | |
| #ifdef BASE_DOUBLE | |
| - if (CLASS_OF(obj) == cgsl_vector) RBASIC(obj)->klass = cgsl_vector_col; | |
| - else if (CLASS_OF(obj) == cgsl_vector_col) RBASIC(obj)->klass = cgsl_vector; | |
| + if (CLASS_OF(obj) == cgsl_vector) rb_obj_reveal(obj, cgsl_vector_col); | |
| + else if (CLASS_OF(obj) == cgsl_vector_col) rb_obj_reveal(obj, cgsl_vector); | |
| else { | |
| rb_raise(rb_eRuntimeError, "method trans! for %s is not permitted.", | |
| rb_class2name(CLASS_OF(obj))); | |
| } | |
| #elif defined(BASE_INT) | |
| - if (CLASS_OF(obj) == cgsl_vector_int) RBASIC(obj)->klass = cgsl_vector_int_col; | |
| - else if (CLASS_OF(obj) == cgsl_vector_int_col) RBASIC(obj)->klass = cgsl_vector_int; | |
| + if (CLASS_OF(obj) == cgsl_vector_int) rb_obj_reveal(obj, cgsl_vector_int_col); | |
| + else if (CLASS_OF(obj) == cgsl_vector_int_col) rb_obj_reveal(obj, cgsl_vector_int); | |
| else { | |
| rb_raise(rb_eRuntimeError, "method trans! for %s is not permitted.", | |
| rb_class2name(CLASS_OF(obj))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment