Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3 compatibility #66

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ rvm:
- 2.2.6
- 2.3.3
- 2.4.0
- 2.5
- 2.6
- 2.7
- 3.0.0

before_install:
- sudo apt-get update -qq
- sudo apt-get install -y libgsl0-dev
- gem update bundler
- bundle install
- gem install bundler:1.17.3
- bundle _1.17.3_ install
- bundle exec rake compile
- bundle exec rake test
1 change: 1 addition & 0 deletions ext/gsl_native/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def create_conf_h(file) #:nodoc:

# FIXME: Find a better way to do this:
hfile.puts "#define RUBY_2 1" if RUBY_VERSION >= '2.0'
hfile.puts "#define RUBY_3 1" if RUBY_VERSION >= '3.0'

for line in $defs
line =~ /^-D(.*)/
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/gsl_narray.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ gsl_matrix_int_view* na_to_gm_int_view(VALUE nna)
}

#include <gsl/gsl_histogram.h>
EXTERN VALUE cgsl_histogram;
extern VALUE cgsl_histogram;
static VALUE rb_gsl_narray_histogram(int argc, VALUE *argv, VALUE obj)
{
double *ptr, *ptr_range;
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/include/rb_gsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void Init_tensor_int_init(VALUE module);

void Init_gsl_dirac(VALUE module);

EXTERN VALUE cGSL_Object;
extern VALUE cGSL_Object;

void Init_tamu_anova(VALUE module);

Expand Down
60 changes: 30 additions & 30 deletions ext/gsl_native/include/rb_gsl_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,41 @@
typedef gsl_permutation gsl_index;

#ifdef HAVE_NARRAY_H
EXTERN VALUE cNArray;
extern VALUE cNArray;
#endif

#ifdef HAVE_NMATRIX_H
EXTERN VALUE cNMatrix;
extern VALUE cNMatrix;
#endif

EXTERN VALUE cgsl_block, cgsl_block_int;
EXTERN VALUE cgsl_block_uchar;
EXTERN VALUE cgsl_block_complex;
EXTERN VALUE cgsl_vector, cgsl_vector_complex;
EXTERN VALUE cgsl_vector_col;
EXTERN VALUE cgsl_vector_col_view;
EXTERN VALUE cgsl_vector_complex_col;
EXTERN VALUE cgsl_vector_complex_col_view;
EXTERN VALUE cgsl_vector_view, cgsl_vector_complex_view;
EXTERN VALUE cgsl_vector_view_ro, cgsl_vector_col_view_ro;
EXTERN VALUE cgsl_vector_complex_view_ro;

EXTERN VALUE cgsl_vector_int, cgsl_vector_int_col;
EXTERN VALUE cgsl_vector_int_view, cgsl_vector_int_col_view;
EXTERN VALUE cgsl_vector_int_view_ro, cgsl_vector_int_col_view_ro;

EXTERN VALUE cgsl_matrix, cgsl_matrix_complex;
EXTERN VALUE cgsl_matrix_view_ro;
EXTERN VALUE cgsl_matrix_complex_view_ro;
EXTERN VALUE cgsl_matrix_view, cgsl_matrix_complex_view;
EXTERN VALUE cgsl_matrix_int, cgsl_matrix_int_view;
EXTERN VALUE cgsl_matrix_int_view_ro;
EXTERN VALUE cgsl_permutation;
EXTERN VALUE cgsl_index;
EXTERN VALUE cgsl_function;
EXTERN VALUE mgsl_narray;

EXTERN VALUE mDirac;
extern VALUE cgsl_block, cgsl_block_int;
extern VALUE cgsl_block_uchar;
extern VALUE cgsl_block_complex;
extern VALUE cgsl_vector, cgsl_vector_complex;
extern VALUE cgsl_vector_col;
extern VALUE cgsl_vector_col_view;
extern VALUE cgsl_vector_complex_col;
extern VALUE cgsl_vector_complex_col_view;
extern VALUE cgsl_vector_view, cgsl_vector_complex_view;
extern VALUE cgsl_vector_view_ro, cgsl_vector_col_view_ro;
extern VALUE cgsl_vector_complex_view_ro;

extern VALUE cgsl_vector_int, cgsl_vector_int_col;
extern VALUE cgsl_vector_int_view, cgsl_vector_int_col_view;
extern VALUE cgsl_vector_int_view_ro, cgsl_vector_int_col_view_ro;

extern VALUE cgsl_matrix, cgsl_matrix_complex;
extern VALUE cgsl_matrix_view_ro;
extern VALUE cgsl_matrix_complex_view_ro;
extern VALUE cgsl_matrix_view, cgsl_matrix_complex_view;
extern VALUE cgsl_matrix_int, cgsl_matrix_int_view;
extern VALUE cgsl_matrix_int_view_ro;
extern VALUE cgsl_permutation;
extern VALUE cgsl_index;
extern VALUE cgsl_function;
extern VALUE mgsl_narray;

extern VALUE mDirac;

gsl_matrix_view* gsl_matrix_view_alloc();
void gsl_matrix_view_free(gsl_matrix_view * mv);
Expand Down
9 changes: 6 additions & 3 deletions ext/gsl_native/include/rb_gsl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#include <gsl/gsl_ieee_utils.h>
#include "rb_gsl_with_narray.h"
#include "rb_gsl_with_nmatrix.h"
#include "gsl_config.h"

EXTERN ID rb_gsl_id_beg, rb_gsl_id_end, rb_gsl_id_excl, rb_gsl_id_to_a;
extern ID rb_gsl_id_beg, rb_gsl_id_end, rb_gsl_id_excl, rb_gsl_id_to_a;

#ifndef CHECK_FIXNUM
#define CHECK_FIXNUM(x) if(!FIXNUM_P(x)) rb_raise(rb_eTypeError,"Fixnum expected");
Expand Down Expand Up @@ -292,7 +293,9 @@ EXTERN ID rb_gsl_id_beg, rb_gsl_id_end, rb_gsl_id_excl, rb_gsl_id_to_a;
#endif

#ifndef RBGSL_SET_CLASS
#ifdef RB_OBJ_WRITE
#if defined(RUBY_3)
#define RBGSL_SET_CLASS0(obj0, cls) RB_OBJ_WRITE(obj0, &(RBASIC(obj0)->klass), cls)
#elif defined(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
Expand Down Expand Up @@ -349,5 +352,5 @@ VALUE rb_gsl_nary_eval1(VALUE ary, double (*f)(double));
VALUE rb_gsl_nmatrix_eval1(VALUE ary, double (*f)(double));
#endif

EXTERN VALUE cGSL_Object;
extern VALUE cGSL_Object;
#endif
2 changes: 1 addition & 1 deletion ext/gsl_native/include/rb_gsl_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <gsl/gsl_complex.h>
#include <gsl/gsl_complex_math.h>

EXTERN VALUE cgsl_complex;
extern VALUE cgsl_complex;
VALUE rb_gsl_complex_pow(int argc, VALUE *argv, VALUE obj);
VALUE rb_gsl_complex_pow_real(int argc, VALUE *argv, VALUE obj);

Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/include/rb_gsl_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#include <gsl/gsl_const_cgsm.h>
#include <gsl/gsl_const_num.h>

EXTERN VALUE mgsl_const_mks, mgsl_const_cgs;
extern VALUE mgsl_const_mks, mgsl_const_cgs;

#endif
12 changes: 6 additions & 6 deletions ext/gsl_native/include/rb_gsl_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ enum {
RB_GSL_FFT_COPY,
};

EXTERN VALUE mgsl_fft;
EXTERN VALUE cgsl_fft_wavetable;
EXTERN VALUE cgsl_fft_wavetable_factor;
EXTERN VALUE cgsl_fft_complex_wavetable, cgsl_fft_complex_workspace;
EXTERN VALUE cgsl_fft_real_wavetable, cgsl_fft_halfcomplex_wavetable;
EXTERN VALUE cgsl_fft_real_workspace;
extern VALUE mgsl_fft;
extern VALUE cgsl_fft_wavetable;
extern VALUE cgsl_fft_wavetable_factor;
extern VALUE cgsl_fft_complex_wavetable, cgsl_fft_complex_workspace;
extern VALUE cgsl_fft_real_wavetable, cgsl_fft_halfcomplex_wavetable;
extern VALUE cgsl_fft_real_workspace;

#endif
2 changes: 1 addition & 1 deletion ext/gsl_native/include/rb_gsl_fit.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#include <gsl/gsl_multifit_nlin.h>
#include "rb_gsl_array.h"

EXTERN VALUE mgsl_multifit;
extern VALUE mgsl_multifit;

#endif
4 changes: 2 additions & 2 deletions ext/gsl_native/include/rb_gsl_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include "rb_gsl.h"

EXTERN VALUE cgsl_function;
EXTERN VALUE cgsl_function_fdf;
extern VALUE cgsl_function;
extern VALUE cgsl_function_fdf;
extern ID RBGSL_ID_call, RBGSL_ID_arity;
void gsl_function_mark(gsl_function *f);
void gsl_function_free(gsl_function *f);
Expand Down
10 changes: 5 additions & 5 deletions ext/gsl_native/include/rb_gsl_histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include <gsl/gsl_histogram2d.h>
#include "rb_gsl.h"

EXTERN VALUE cgsl_histogram;
EXTERN VALUE cgsl_histogram_range;
EXTERN VALUE cgsl_histogram_bin;
EXTERN VALUE cgsl_histogram2d;
EXTERN VALUE cgsl_histogram2d_view;
extern VALUE cgsl_histogram;
extern VALUE cgsl_histogram_range;
extern VALUE cgsl_histogram_bin;
extern VALUE cgsl_histogram2d;
extern VALUE cgsl_histogram2d_view;

typedef struct {
gsl_histogram h;
Expand Down
12 changes: 6 additions & 6 deletions ext/gsl_native/include/rb_gsl_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "rb_gsl_complex.h"
#include "rb_gsl_array.h"

EXTERN VALUE cgsl_poly;
EXTERN VALUE cgsl_poly_int;
EXTERN VALUE cgsl_poly_dd;
EXTERN VALUE cgsl_poly_taylor;
EXTERN VALUE cgsl_poly_workspace;
EXTERN VALUE cgsl_rational;
extern VALUE cgsl_poly;
extern VALUE cgsl_poly_int;
extern VALUE cgsl_poly_dd;
extern VALUE cgsl_poly_taylor;
extern VALUE cgsl_poly_workspace;
extern VALUE cgsl_rational;

typedef gsl_vector gsl_poly;
typedef gsl_vector_int gsl_poly_int;
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/include/rb_gsl_rng.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
#include <gsl/gsl_rng.h>
#include "rb_gsl.h"

EXTERN VALUE cgsl_rng;
extern VALUE cgsl_rng;

#endif
4 changes: 2 additions & 2 deletions ext/gsl_native/include/rb_gsl_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <gsl/gsl_roots.h>
#include "rb_gsl.h"

EXTERN VALUE cgsl_fsolver;
EXTERN VALUE cgsl_fdfsolver;
extern VALUE cgsl_fsolver;
extern VALUE cgsl_fdfsolver;

#endif
2 changes: 1 addition & 1 deletion ext/gsl_native/include/rb_gsl_sf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <gsl/gsl_sf_mathieu.h>
#include "rb_gsl.h"

EXTERN VALUE cgsl_sf_result, cgsl_sf_result_e10;
extern VALUE cgsl_sf_result, cgsl_sf_result_e10;

VALUE rb_gsl_sf_result_new(VALUE klass);

Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/include/rb_gsl_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "rb_gsl.h"
#include <tensor/tensor.h>

EXTERN VALUE cgsl_tensor, cgsl_tensor_int;
extern VALUE cgsl_tensor, cgsl_tensor_int;

enum {
TENSOR_ADD,
Expand Down
5 changes: 5 additions & 0 deletions ext/gsl_native/include/templates_off.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@
#undef NAME
#undef STRING
#undef EXPAND

#ifdef RUBY_3
#undef memcpy
#define memcpy ruby_nonempty_memcpy
#endif
6 changes: 6 additions & 0 deletions ext/gsl_native/include/templates_on.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,9 @@
#define STRING(x) #x
#define EXPAND(x) STRING(x)
#define NAME(x) EXPAND(GSL_TYPE(x))

// Ruby 3 redefines memcpy as ruby_nonempty_memcpy, breaking everything if memcpy is used in preprocessor
#ifdef RUBY_3
#undef memcpy
#define memcpy memcpy
#endif
2 changes: 1 addition & 1 deletion ext/gsl_native/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "include/rb_gsl_interp.h"

VALUE cgsl_interp_accel; /* this is used also in spline.c */
EXTERN VALUE cgsl_vector, cgsl_matrix;
extern VALUE cgsl_vector, cgsl_matrix;

static void rb_gsl_interp_free(rb_gsl_interp *sp);

Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/interp2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "include/rb_gsl_interp2d.h"

VALUE cgsl_interp2d_accel; /* this is used also in spline2d.c */
EXTERN VALUE cgsl_vector, cgsl_matrix;
extern VALUE cgsl_vector, cgsl_matrix;

static VALUE rb_gsl_interp2d_alloc(int argc, VALUE *argv, VALUE self)
{
Expand Down
4 changes: 2 additions & 2 deletions ext/gsl_native/linalg_complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "include/rb_gsl_common.h"
#include "include/rb_gsl_linalg.h"

EXTERN VALUE mgsl_linalg;
EXTERN VALUE cgsl_complex;
extern VALUE mgsl_linalg;
extern VALUE cgsl_complex;

static VALUE cgsl_matrix_complex_LU;
static VALUE cgsl_matrix_complex_C;
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/matrix_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ static int FUNCTION(mygsl_matrix,equal)(GSL_TYPE(gsl_matrix) *a, GSL_TYPE(gsl_ma
}

#ifdef HAVE_TENSOR_TENSOR_H
EXTERN VALUE cgsl_tensor, cgsl_tensor_int;
extern VALUE cgsl_tensor, cgsl_tensor_int;
VALUE rb_gsl_tensor_equal(int argc, VALUE *argv, VALUE obj);
VALUE rb_gsl_tensor_int_equal(int argc, VALUE *argv, VALUE obj);
#ifdef BASE_DOUBLE
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/monte.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static VALUE cgsl_monte_miser;
static VALUE cgsl_monte_vegas;
static VALUE cgsl_monte_function;
static VALUE cgsl_monte_miser_params, cgsl_monte_vegas_params;
EXTERN VALUE cgsl_vector;
extern VALUE cgsl_vector;

enum {
GSL_MONTE_PLAIN_STATE = 1,
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "include/rb_gsl_function.h"
#include "include/rb_gsl_root.h"

EXTERN VALUE cgsl_function_fdf;
extern VALUE cgsl_function_fdf;

enum {
GSL_ROOT_FSOLVER_BISECTION,
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/sf_bessel.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

#include "include/rb_gsl_sf.h"
EXTERN VALUE cgsl_vector;
extern VALUE cgsl_vector;

/* Cylindrical Bessel Functions */
static VALUE rb_gsl_sf_bessel_J0(VALUE obj, VALUE x)
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/sf_coulomb.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

#include "include/rb_gsl_sf.h"
EXTERN VALUE cgsl_vector;
extern VALUE cgsl_vector;

static VALUE rb_gsl_sf_hydrogenicR_1(VALUE obj, VALUE Z, VALUE r)
{
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/sf_legendre.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include "include/rb_gsl_sf.h"
EXTERN VALUE cgsl_vector;
extern VALUE cgsl_vector;

static VALUE rb_gsl_sf_legendre_P1(VALUE obj, VALUE x)
{
Expand Down
4 changes: 2 additions & 2 deletions ext/gsl_native/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <gsl/gsl_heapsort.h>
#include <gsl/gsl_sort.h>

EXTERN ID RBGSL_ID_call;
EXTERN VALUE cgsl_complex;
extern ID RBGSL_ID_call;
extern VALUE cgsl_complex;

int rb_gsl_comparison_double(const void *aa, const void *bb);
int rb_gsl_comparison_complex(const void *aa, const void *bb);
Expand Down
2 changes: 1 addition & 1 deletion ext/gsl_native/spline.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "include/rb_gsl_interp.h"

EXTERN VALUE cgsl_interp_accel; /* defined in interp.c */
extern VALUE cgsl_interp_accel; /* defined in interp.c */

static void rb_gsl_spline_free(rb_gsl_spline *sp);

Expand Down
Loading