From: Lucas Kanashiro <kanashiro@ubuntu.com>
Date: Thu, 4 Nov 2021 16:26:57 -0300
Subject: Ruby 3 compatibility

Origin: backport, https://github.com/SciRuby/rb-gsl/commit/452d4d8cfc40dd2e2d
                  https://github.com/SciRuby/rb-gsl/commit/ffad8643cc3b576370
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=996237
---
 ext/gsl_native/extconf.rb                 |  1 +
 ext/gsl_native/gsl_narray.c               |  2 +-
 ext/gsl_native/include/rb_gsl.h           |  2 +-
 ext/gsl_native/include/rb_gsl_array.h     | 60 +++++++++++++++----------------
 ext/gsl_native/include/rb_gsl_common.h    |  9 +++--
 ext/gsl_native/include/rb_gsl_complex.h   |  2 +-
 ext/gsl_native/include/rb_gsl_const.h     |  2 +-
 ext/gsl_native/include/rb_gsl_fft.h       | 12 +++----
 ext/gsl_native/include/rb_gsl_fit.h       |  2 +-
 ext/gsl_native/include/rb_gsl_function.h  |  4 +--
 ext/gsl_native/include/rb_gsl_histogram.h | 10 +++---
 ext/gsl_native/include/rb_gsl_poly.h      | 12 +++----
 ext/gsl_native/include/rb_gsl_rng.h       |  2 +-
 ext/gsl_native/include/rb_gsl_root.h      |  4 +--
 ext/gsl_native/include/rb_gsl_sf.h        |  2 +-
 ext/gsl_native/include/rb_gsl_tensor.h    |  2 +-
 ext/gsl_native/include/templates_off.h    |  5 +++
 ext/gsl_native/include/templates_on.h     |  6 ++++
 ext/gsl_native/interp.c                   |  2 +-
 ext/gsl_native/interp2d.c                 |  2 +-
 ext/gsl_native/linalg_complex.c           |  4 +--
 ext/gsl_native/matrix_source.h            |  2 +-
 ext/gsl_native/monte.c                    |  2 +-
 ext/gsl_native/root.c                     |  2 +-
 ext/gsl_native/sf_bessel.c                |  2 +-
 ext/gsl_native/sf_coulomb.c               |  2 +-
 ext/gsl_native/sf_legendre.c              |  2 +-
 ext/gsl_native/sort.c                     |  4 +--
 ext/gsl_native/spline.c                   |  2 +-
 ext/gsl_native/spline2d.c                 |  2 +-
 ext/gsl_native/vector_complex.c           |  2 +-
 ext/gsl_native/vector_source.h            |  4 +--
 32 files changed, 94 insertions(+), 79 deletions(-)

diff --git a/ext/gsl_native/extconf.rb b/ext/gsl_native/extconf.rb
index a9864fe..40f6ba9 100644
--- a/ext/gsl_native/extconf.rb
+++ b/ext/gsl_native/extconf.rb
@@ -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(.*)/
diff --git a/ext/gsl_native/gsl_narray.c b/ext/gsl_native/gsl_narray.c
index ba895e6..a4a90d9 100644
--- a/ext/gsl_native/gsl_narray.c
+++ b/ext/gsl_native/gsl_narray.c
@@ -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;
diff --git a/ext/gsl_native/include/rb_gsl.h b/ext/gsl_native/include/rb_gsl.h
index bc1d6c0..aa643e6 100644
--- a/ext/gsl_native/include/rb_gsl.h
+++ b/ext/gsl_native/include/rb_gsl.h
@@ -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);
 
diff --git a/ext/gsl_native/include/rb_gsl_array.h b/ext/gsl_native/include/rb_gsl_array.h
index 447679d..e4d4440 100644
--- a/ext/gsl_native/include/rb_gsl_array.h
+++ b/ext/gsl_native/include/rb_gsl_array.h
@@ -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);
diff --git a/ext/gsl_native/include/rb_gsl_common.h b/ext/gsl_native/include/rb_gsl_common.h
index e3365b0..44f23aa 100644
--- a/ext/gsl_native/include/rb_gsl_common.h
+++ b/ext/gsl_native/include/rb_gsl_common.h
@@ -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");
@@ -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
@@ -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
diff --git a/ext/gsl_native/include/rb_gsl_complex.h b/ext/gsl_native/include/rb_gsl_complex.h
index 6243311..4747f84 100644
--- a/ext/gsl_native/include/rb_gsl_complex.h
+++ b/ext/gsl_native/include/rb_gsl_complex.h
@@ -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);
 
diff --git a/ext/gsl_native/include/rb_gsl_const.h b/ext/gsl_native/include/rb_gsl_const.h
index c46b61b..735480a 100644
--- a/ext/gsl_native/include/rb_gsl_const.h
+++ b/ext/gsl_native/include/rb_gsl_const.h
@@ -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
diff --git a/ext/gsl_native/include/rb_gsl_fft.h b/ext/gsl_native/include/rb_gsl_fft.h
index 8de6449..a220ae2 100644
--- a/ext/gsl_native/include/rb_gsl_fft.h
+++ b/ext/gsl_native/include/rb_gsl_fft.h
@@ -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
diff --git a/ext/gsl_native/include/rb_gsl_fit.h b/ext/gsl_native/include/rb_gsl_fit.h
index 3b38e6b..c32805b 100644
--- a/ext/gsl_native/include/rb_gsl_fit.h
+++ b/ext/gsl_native/include/rb_gsl_fit.h
@@ -18,6 +18,6 @@
 #include <gsl/gsl_multifit_nlin.h>
 #include "rb_gsl_array.h"
 
-EXTERN VALUE mgsl_multifit;
+extern VALUE mgsl_multifit;
 
 #endif
diff --git a/ext/gsl_native/include/rb_gsl_function.h b/ext/gsl_native/include/rb_gsl_function.h
index 207e21e..71bb67f 100644
--- a/ext/gsl_native/include/rb_gsl_function.h
+++ b/ext/gsl_native/include/rb_gsl_function.h
@@ -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);
diff --git a/ext/gsl_native/include/rb_gsl_histogram.h b/ext/gsl_native/include/rb_gsl_histogram.h
index 02a9b7b..a0635ac 100644
--- a/ext/gsl_native/include/rb_gsl_histogram.h
+++ b/ext/gsl_native/include/rb_gsl_histogram.h
@@ -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;
diff --git a/ext/gsl_native/include/rb_gsl_poly.h b/ext/gsl_native/include/rb_gsl_poly.h
index 02422ca..76e0a9d 100644
--- a/ext/gsl_native/include/rb_gsl_poly.h
+++ b/ext/gsl_native/include/rb_gsl_poly.h
@@ -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;
diff --git a/ext/gsl_native/include/rb_gsl_rng.h b/ext/gsl_native/include/rb_gsl_rng.h
index 796c4ee..f656365 100644
--- a/ext/gsl_native/include/rb_gsl_rng.h
+++ b/ext/gsl_native/include/rb_gsl_rng.h
@@ -15,6 +15,6 @@
 #include <gsl/gsl_rng.h>
 #include "rb_gsl.h"
 
-EXTERN VALUE cgsl_rng;
+extern VALUE cgsl_rng;
 
 #endif
diff --git a/ext/gsl_native/include/rb_gsl_root.h b/ext/gsl_native/include/rb_gsl_root.h
index 6b68bab..0d98dd4 100644
--- a/ext/gsl_native/include/rb_gsl_root.h
+++ b/ext/gsl_native/include/rb_gsl_root.h
@@ -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
diff --git a/ext/gsl_native/include/rb_gsl_sf.h b/ext/gsl_native/include/rb_gsl_sf.h
index 9a61cec..65f5e12 100644
--- a/ext/gsl_native/include/rb_gsl_sf.h
+++ b/ext/gsl_native/include/rb_gsl_sf.h
@@ -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);
 
diff --git a/ext/gsl_native/include/rb_gsl_tensor.h b/ext/gsl_native/include/rb_gsl_tensor.h
index 35c98c1..9828f9b 100644
--- a/ext/gsl_native/include/rb_gsl_tensor.h
+++ b/ext/gsl_native/include/rb_gsl_tensor.h
@@ -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,
diff --git a/ext/gsl_native/include/templates_off.h b/ext/gsl_native/include/templates_off.h
index 37e024d..68b9403 100644
--- a/ext/gsl_native/include/templates_off.h
+++ b/ext/gsl_native/include/templates_off.h
@@ -85,3 +85,8 @@
 #undef NAME
 #undef STRING
 #undef EXPAND
+
+#ifdef RUBY_3
+#undef memcpy
+#define memcpy ruby_nonempty_memcpy
+#endif
diff --git a/ext/gsl_native/include/templates_on.h b/ext/gsl_native/include/templates_on.h
index 4db23e9..4213554 100644
--- a/ext/gsl_native/include/templates_on.h
+++ b/ext/gsl_native/include/templates_on.h
@@ -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
diff --git a/ext/gsl_native/interp.c b/ext/gsl_native/interp.c
index 366f594..4decffc 100644
--- a/ext/gsl_native/interp.c
+++ b/ext/gsl_native/interp.c
@@ -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);
 
diff --git a/ext/gsl_native/interp2d.c b/ext/gsl_native/interp2d.c
index 1e9b76a..e078611 100644
--- a/ext/gsl_native/interp2d.c
+++ b/ext/gsl_native/interp2d.c
@@ -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)
 { 
diff --git a/ext/gsl_native/linalg_complex.c b/ext/gsl_native/linalg_complex.c
index 491ad0c..4ee62fa 100644
--- a/ext/gsl_native/linalg_complex.c
+++ b/ext/gsl_native/linalg_complex.c
@@ -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;
diff --git a/ext/gsl_native/matrix_source.h b/ext/gsl_native/matrix_source.h
index d6f312b..cef5a9a 100644
--- a/ext/gsl_native/matrix_source.h
+++ b/ext/gsl_native/matrix_source.h
@@ -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
diff --git a/ext/gsl_native/monte.c b/ext/gsl_native/monte.c
index 3559001..8d83bdb 100644
--- a/ext/gsl_native/monte.c
+++ b/ext/gsl_native/monte.c
@@ -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,
diff --git a/ext/gsl_native/root.c b/ext/gsl_native/root.c
index dfed2c8..666ec81 100644
--- a/ext/gsl_native/root.c
+++ b/ext/gsl_native/root.c
@@ -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,
diff --git a/ext/gsl_native/sf_bessel.c b/ext/gsl_native/sf_bessel.c
index 65d5038..c0ab45d 100644
--- a/ext/gsl_native/sf_bessel.c
+++ b/ext/gsl_native/sf_bessel.c
@@ -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)
diff --git a/ext/gsl_native/sf_coulomb.c b/ext/gsl_native/sf_coulomb.c
index c314642..6479769 100644
--- a/ext/gsl_native/sf_coulomb.c
+++ b/ext/gsl_native/sf_coulomb.c
@@ -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)
 {
diff --git a/ext/gsl_native/sf_legendre.c b/ext/gsl_native/sf_legendre.c
index 5a9470e..91836e1 100644
--- a/ext/gsl_native/sf_legendre.c
+++ b/ext/gsl_native/sf_legendre.c
@@ -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)
 {
diff --git a/ext/gsl_native/sort.c b/ext/gsl_native/sort.c
index a1acd78..240a8fb 100644
--- a/ext/gsl_native/sort.c
+++ b/ext/gsl_native/sort.c
@@ -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);
diff --git a/ext/gsl_native/spline.c b/ext/gsl_native/spline.c
index dd42355..0d730da 100644
--- a/ext/gsl_native/spline.c
+++ b/ext/gsl_native/spline.c
@@ -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);
 
diff --git a/ext/gsl_native/spline2d.c b/ext/gsl_native/spline2d.c
index 5b9c262..c82778c 100644
--- a/ext/gsl_native/spline2d.c
+++ b/ext/gsl_native/spline2d.c
@@ -11,7 +11,7 @@
 #ifdef GSL_2_0_LATER
 #include "include/rb_gsl_interp2d.h"
 
-EXTERN VALUE cgsl_interp2d_accel;  /* defined in interp2d.c */
+extern VALUE cgsl_interp2d_accel;  /* defined in interp2d.c */
 static void rb_gsl_spline2d_free(rb_gsl_spline2d *fr);
 
 static VALUE rb_gsl_spline2d_alloc(int argc, VALUE *argv, VALUE self)
diff --git a/ext/gsl_native/vector_complex.c b/ext/gsl_native/vector_complex.c
index b598746..83db5ee 100644
--- a/ext/gsl_native/vector_complex.c
+++ b/ext/gsl_native/vector_complex.c
@@ -12,7 +12,7 @@
 #include "include/rb_gsl_array.h"
 #include "include/rb_gsl_complex.h"
 
-EXTERN VALUE cgsl_complex;
+extern VALUE cgsl_complex;
 static VALUE rb_gsl_vector_complex_inner_product(int argc, VALUE *argv, VALUE obj);
 static VALUE rb_gsl_vector_complex_product_to_m(int argc, VALUE *argv, VALUE obj);
 
diff --git a/ext/gsl_native/vector_source.h b/ext/gsl_native/vector_source.h
index 1d343cd..2b265d9 100644
--- a/ext/gsl_native/vector_source.h
+++ b/ext/gsl_native/vector_source.h
@@ -687,7 +687,7 @@ static VALUE FUNCTION(rb_gsl_vector,uplus)(VALUE obj)
   return obj;
 }
 
-EXTERN VALUE cgsl_poly;
+extern VALUE cgsl_poly;
 
 VALUE FUNCTION(rb_gsl_vector,uminus)(VALUE obj)
 {
@@ -1009,7 +1009,7 @@ int FUNCTION(rbgsl_vector,equal)(const GSL_TYPE(gsl_vector) *v1, const GSL_TYPE(
 }
 
 #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
