[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dennou-ruby:002920] ruby 1.9 対 応パッチ



堀之内様

大塚です。

Ruby-NetCDF と Ruby-DCL の ruby 1.9 用パッチです。

-- 
京都大学大学院理学研究科
気象学研究室 D2
大塚成徳 (Shigenori OTSUKA)
email: otsuka@xxxxxxxxxxxxxxxxxx
diff -Naur ruby-netcdf-0.6.3.org/netcdfraw.c ruby-netcdf-0.6.3/netcdfraw.c
--- ruby-netcdf-0.6.3.org/netcdfraw.c	2007-12-25 20:10:39.000000000 +0900
+++ ruby-netcdf-0.6.3/netcdfraw.c	2008-02-05 16:26:54.593750000 +0900
@@ -4,6 +4,15 @@
 #include<netcdf.h>
 #include<string.h>
 
+/* for compatibility with ruby 1.6 */
+#ifndef RSTRING_PTR
+#define RSTRING_PTR(a) (RSTRING(a)->ptr)
+#endif
+#ifndef RSTRING_LEN
+#define RSTRING_LEN(a) (RSTRING(a)->len)
+#endif
+
+
 /* Data to NArray */
 
 /*    memcpy(ary->ptr,nc_ptr,na_sizeof[NA_SINT]*ary->total); \ */
@@ -573,7 +582,7 @@
   Data_Get_Struct(file,struct Netcdf,Netcdffile);
   
   Check_Type(dim_name,T_STRING);
-  c_dim_name=RSTRING(dim_name)->ptr;
+  c_dim_name=RSTRING_PTR(dim_name);
   c_length=NUM2UINT(length);
   ncid=Netcdffile->ncid;
 
@@ -595,7 +604,7 @@
 
     /* check atttype (not necessarily needed but it's better to do it) */
     if (TYPE(atttype) == T_STRING){
-	if ( natype2nctype(RSTRING(atttype)->ptr) !=  NC_CHAR ) {
+	if ( natype2nctype(RSTRING_PTR(atttype)) !=  NC_CHAR ) {
 	    rb_raise(rb_eNetcdfError,
 	        "attribute type must be 'char' (or nil) for a String value");
 	}
@@ -606,7 +615,7 @@
     /* put value */
     Check_Type(value,T_STRING);
     status = nc_put_att_text(ncid, varid, name,
-			     RSTRING(value)->len, RSTRING(value)->ptr);
+			     RSTRING_LEN(value), RSTRING_PTR(value));
     if(status != NC_NOERR) NC_RAISE(status);
 
     ncatt = NetCDF_att_init(ncid,varid,name);
@@ -715,7 +724,7 @@
     rb_secure(4);
     Data_Get_Struct(file,struct Netcdf,ncfile);
     Check_Type(att_name,T_STRING);
-    name = RSTRING(att_name)->ptr;
+    name = RSTRING_PTR(att_name);
 
     return( NetCDF_put_att__(ncfile->ncid, name, value, atttype, NC_GLOBAL) );
 }
@@ -733,7 +742,7 @@
     rb_secure(4);
     Data_Get_Struct(var,struct NetCDFVar,ncvar);
     Check_Type(att_name,T_STRING);
-    name = RSTRING(att_name)->ptr;
+    name = RSTRING_PTR(att_name);
 
     return( NetCDF_put_att__(ncvar->ncid, name, value, atttype, ncvar->varid));
 }
@@ -761,14 +770,14 @@
   Check_Type(var_name,T_STRING);
   Check_Type(dimensions,T_ARRAY);
 
-  c_var_name=RSTRING(var_name)->ptr;
+  c_var_name=RSTRING_PTR(var_name);
   c_ndims=RARRAY(dimensions)->len;
   
   Data_Get_Struct(file,struct Netcdf,Netcdffile);
   ncid=Netcdffile->ncid;
 
   if (TYPE(vartype) == T_STRING){
-      xtype = natype2nctype(RSTRING(vartype)->ptr);     
+      xtype = natype2nctype(RSTRING_PTR(vartype));     
   } else if (TYPE(vartype) == T_FIXNUM){
       xtype = natypecode2nctype(NUM2INT(vartype));     
   } else {
@@ -818,7 +827,7 @@
   Data_Get_Struct(file,struct Netcdf,Netcdffile);
   ncid=Netcdffile->ncid;
   Check_Type(dim_name,T_STRING);
-  c_dim_name=RSTRING(dim_name)->ptr;
+  c_dim_name=RSTRING_PTR(dim_name);
   
   status = nc_inq_dimid(ncid,c_dim_name,&dimidp);
   if(status !=NC_NOERR){
@@ -849,7 +858,7 @@
   Data_Get_Struct(file,struct Netcdf,Netcdffile);
   ncid=Netcdffile->ncid;
   Check_Type(var_name,T_STRING);
-  c_var_name=RSTRING(var_name)->ptr;
+  c_var_name=RSTRING_PTR(var_name);
   
   status=nc_inq_varid(ncid,c_var_name,&varidp);
   if(status != NC_NOERR){
@@ -879,7 +888,7 @@
   Data_Get_Struct(file,struct Netcdf,Netcdffile);
   ncid=Netcdffile->ncid;
   Check_Type(att_name,T_STRING);
-  c_att_name=RSTRING(att_name)->ptr;
+  c_att_name=RSTRING_PTR(att_name);
   
 
   status = nc_inq_attid(ncid,NC_GLOBAL,c_att_name,&attnump);
@@ -1008,7 +1017,7 @@
 
   Check_Type(filename,T_STRING);
   Check_SafeStr(filename);
-  c_filename=RSTRING(filename)->ptr;
+  c_filename=RSTRING_PTR(filename);
   Check_Type(omode,T_FIXNUM);
   c_omode=NUM2INT(omode);
   
@@ -1031,7 +1040,7 @@
   
   Check_Type(filename,T_STRING);
   Check_SafeStr(filename);
-  c_filename=RSTRING(filename)->ptr;
+  c_filename=RSTRING_PTR(filename);
   Check_Type(cmode,T_FIXNUM);
   c_cmode=NUM2INT(cmode);
   
diff -Naur ruby-dcl-1.5.3.org/dcl_obj2cary.c ruby-dcl-1.5.3/dcl_obj2cary.c
--- ruby-dcl-1.5.3.org/dcl_obj2cary.c	2003-12-10 16:25:37.000000000 +0900
+++ ruby-dcl-1.5.3/dcl_obj2cary.c	2008-03-11 13:24:33.546875000 +0900
@@ -5,7 +5,6 @@
 
 #include <math.h>
 #include "ruby.h"
-#include "version.h"
 #include "libtinyf2c.h"
 #include "narray.h"
 
@@ -41,7 +40,11 @@
 
 /*  defines  */
 #define BE_INTEGER(x) ((integer)(NUM2INT(rb_Integer(x))))
-#define BE_REAL(x)    ((real)(RFLOAT(rb_Float(x))->value))
+#ifndef RFLOAT_VALUE
+/* for compatibility with ruby 1.6 */
+#define RFLOAT_VALUE(x) ((real)(RFLOAT(x)->value))
+#endif
+#define BE_REAL(x)    ((real)(RFLOAT_VALUE(rb_Float(x))))
 #define BE_LOGICAL(x) (((x == Qnil) || (x == Qfalse)) ? FALSE_ : TRUE_ )
 /* not implemented 
 #define BE_COMPLEX(x) ...
@@ -268,9 +271,11 @@
 {
     VALUE *ptr;
     long len, i, j;
-#if RUBY_VERSION_CODE > 170
+#ifdef StringValue
+    // Ruby version 1.8 or later
     long rlen;
 #else
+    // Ruby version 1.7 or before
     int rlen;
 #endif
     char *rtn, *wk, *rwk;
diff -Naur ruby-dcl-1.5.3.org/extconf.rb ruby-dcl-1.5.3/extconf.rb
--- ruby-dcl-1.5.3.org/extconf.rb	2006-12-01 09:24:43.000000000 +0900
+++ ruby-dcl-1.5.3/extconf.rb	2008-03-11 13:33:11.390625000 +0900
@@ -1,5 +1,15 @@
 require "mkmf"
-require "ftools"
+require "rbconfig"
+if Config::CONFIG["MINOR"].to_i > 7
+  $rb18 = true
+else
+  $rb18 = false
+end
+if $rb18
+  require "fileutils"
+else
+  require "ftools"
+end
 
 dir_config('narray',$sitearchdir,$sitearchdir)
 if ( ! ( have_header("narray.h") && have_header("narray_config.h") ) ) then
@@ -49,7 +59,11 @@
     initcfile = "init.c.default"
   else
     print "**Infomation** compile with gtk+ (ver.#{gtkversion})\n"
-    File.copy("grph1_zgpack.c.org","grph1_zgpack.c")
+    if $rb18
+      FileUtils.copy("grph1_zgpack.c.org","grph1_zgpack.c")
+    else
+      File.copy("grph1_zgpack.c.org","grph1_zgpack.c")
+    end
     initcfile = "init.c.gtk"
     if ldlibs =~ /-lgdk_imlib/ then
       print "**Infomation** compile with imlib_gdk\n"