なかだです。

MySQL/Ruby 2.8pre2をみてみたのですが、やや問題があるようです。

= 別ディレクトリでコンパイルできない。
  *.cを自動で探すのはソースディレクトリです。この場合はソース全
  体をコピーしなくとも、ヘッダに分けるだけで充分だと思います。

* RUBYY_VERSION_CODEをみている
  rb_str_set_len()を使うのはRSTRING_LEN()がないときでいいと思い
  ます。

  RUBY_VERSION_CODE < 160 のときにTypeError()やRaise()を使ってい
  ますが、この関数は1.3ではすでに廃止されています。なので、1.4で
  は動かないはずです。また、他のところでは無条件でrb_raiseを使っ
  ているので、1.2以前でもダメなはずです。つまり、もう1.4以前では
  使われていない、とみなしてもいいのでは。


Index: mysql-ruby-2.7.5/extconf.rb =================================================================== --- mysql-ruby-2.7.5/extconf.rb~ 2006-10-29 23:59:44.000000000 +0900 +++ mysql-ruby-2.7.5/extconf.rb 2008-06-16 12:18:51.000000000 +0900 @@ -61,11 +61,7 @@ error_syms.uniq! -newf = File::open('mysql.c', 'w') -IO::foreach('mysql.c.in') do |l| - newf.puts l - if l =~ /\/\* Mysql::Error constant \*\// then - error_syms.each do |s| - newf.puts " rb_define_const(eMysql, \"#{s}\", INT2NUM(#{s}));" - end +File::open('error_const.h', 'w') do |f| + error_syms.each do |s| + f.puts " rb_define_mysql_const(#{s});" end end Index: mysql-ruby-2.7.5/mysql.c =================================================================== --- mysql-ruby-2.7.5/mysql.c.in~ 2008-03-08 01:30:47.000000000 +0900 +++ mysql-ruby-2.7.5/mysql.c 2008-06-16 12:20:36.000000000 +0900 @@ -4,5 +4,4 @@ #include "ruby.h" -#include "version.h" #ifdef HAVE_MYSQL_H #include <mysql.h> @@ -19,4 +18,12 @@ #define GC_STORE_RESULT_LIMIT 20 +#ifndef RSTRING_PTR +#define RSTRING_PTR(str) RSTRING(str)->ptr +#endif +#ifndef RSTRING_LEN +#define RSTRING_LEN(str) RSTRING(str)->len +#define rb_str_set_len(str, length) (RSTRING_LEN(str) = (length)) +#endif + #ifndef Qtrue /* ruby 1.2.x ? */ #define Qtrue TRUE @@ -278,6 +285,6 @@ VALUE ret; Check_Type(str, T_STRING); - ret = rb_str_new(0, (RSTRING(str)->len)*2+1); - RSTRING(ret)->len = mysql_escape_string(RSTRING(ret)->ptr, RSTRING(str)->ptr, RSTRING(str)->len); + ret = rb_str_new(0, (RSTRING_LEN(str))*2+1); + rb_str_set_len(ret, mysql_escape_string(RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str))); return ret; } @@ -412,6 +419,6 @@ VALUE ret; Check_Type(str, T_STRING); - ret = rb_str_new(0, (RSTRING(str)->len)*2+1); - RSTRING(ret)->len = mysql_real_escape_string(m, RSTRING(ret)->ptr, RSTRING(str)->ptr, RSTRING(str)->len); + ret = rb_str_new(0, (RSTRING_LEN(str))*2+1); + rb_str_set_len(ret, mysql_real_escape_string(m, RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str))); return ret; } @@ -723,5 +730,5 @@ mysql_raise(m); #endif - if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0) + if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) mysql_raise(m); do { @@ -743,5 +750,5 @@ return obj; } - if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0) + if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) mysql_raise(m); if (GetMysqlStruct(obj)->query_with_result == Qfalse) @@ -895,9 +902,5 @@ { if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE) -#if RUBY_VERSION_CODE < 160 - TypeError("invalid type, required true or false."); -#else rb_raise(rb_eTypeError, "invalid type, required true or false."); -#endif GetMysqlStruct(obj)->query_with_result = flag; return flag; @@ -973,9 +976,5 @@ n = NUM2INT(nr); if (n >= max) -#if RUBY_VERSION_CODE < 160 - Raise(eMysql, "%d: out of range (max: %d)", n, max-1); -#else rb_raise(eMysql, "%d: out of range (max: %d)", n, max-1); -#endif #if MYSQL_VERSION_ID >= 32226 return make_field_obj(mysql_fetch_field_direct(res, n)); @@ -1046,6 +1045,6 @@ else { col = rb_tainted_str_new(fields[i].table, strlen(fields[i].table)+strlen(fields[i].name)+1); - RSTRING(col)->ptr[strlen(fields[i].table)] = '.'; - strcpy(RSTRING(col)->ptr+strlen(fields[i].table)+1, fields[i].name); + RSTRING_PTR(col)[strlen(fields[i].table)] = '.'; + strcpy(RSTRING_PTR(col)+strlen(fields[i].table)+1, fields[i].name); } rb_hash_aset(hash, col, row[i]? rb_tainted_str_new(row[i], lengths[i]): Qnil); @@ -1171,6 +1170,6 @@ { VALUE n = rb_iv_get(obj, "name"); - VALUE s = rb_str_new(0, RSTRING(n)->len + 16); - sprintf(RSTRING(s)->ptr, "#<Mysql::Field:%s>", RSTRING(n)->ptr); + VALUE s = rb_str_new(0, RSTRING_LEN(n) + 16); + sprintf(RSTRING_PTR(s), "#<Mysql::Field:%s>", RSTRING_PTR(n)); return s; } @@ -1297,5 +1296,5 @@ s->result.bind[i].buffer_type = MYSQL_TYPE_DATETIME; else - rb_raise(rb_eTypeError, "unrecognized class: %s", RSTRING(rb_inspect(argv[i]))->ptr); + rb_raise(rb_eTypeError, "unrecognized class: %s", RSTRING_PTR(rb_inspect(argv[i]))); if (mysql_stmt_bind_result(s->stmt, s->result.bind)) mysql_stmt_raise(s->stmt); @@ -1620,5 +1619,5 @@ check_stmt_closed(obj); Check_Type(query, T_STRING); - if (mysql_stmt_prepare(s->stmt, RSTRING(query)->ptr, RSTRING(query)->len)) + if (mysql_stmt_prepare(s->stmt, RSTRING_PTR(query), RSTRING_LEN(query))) mysql_stmt_raise(s->stmt); @@ -1717,5 +1716,5 @@ mysql_stmt_raise(s->stmt); } - if (mysql_stmt_send_long_data(s->stmt, c, RSTRING(data)->ptr, RSTRING(data)->len)) + if (mysql_stmt_send_long_data(s->stmt, c, RSTRING_PTR(data), RSTRING_LEN(data))) mysql_stmt_raise(s->stmt); return obj; @@ -2233,3 +2232,5 @@ /* Mysql::Error constant */ +#define rb_define_mysql_const(s) rb_define_const(eMysql, #s, INT2NUM(s)) +#include "error_const.h" } Index: mysql-ruby-2.8pre2/extconf.rb =================================================================== --- mysql-ruby-2.8pre2/extconf.rb~ 2007-12-18 08:46:30.000000000 +0900 +++ mysql-ruby-2.8pre2/extconf.rb 2008-06-16 12:17:28.000000000 +0900 @@ -61,11 +61,7 @@ error_syms.uniq! -newf = File::open('mysql.c', 'w') -IO::foreach('mysql.c.in') do |l| - newf.puts l.gsub(/%RUBY_VERSION%/, RUBY_VERSION.gsub(/\D/, '')) - if l =~ /\/\* Mysql::Error constant \*\// then - error_syms.each do |s| - newf.puts " rb_define_const(eMysql, \"#{s}\", INT2NUM(#{s}));" - end +File::open('error_const.h', 'w') do |f| + error_syms.each do |s| + f.puts " rb_define_mysql_const(#{s});" end end Index: mysql-ruby-2.8pre2/mysql.c =================================================================== --- mysql-ruby-2.8pre2/mysql.c.in 2008-03-08 01:16:28.000000000 +0900 +++ mysql-ruby-2.8pre2/mysql.c 2008-06-16 12:15:14.000000000 +0900 @@ -4,5 +4,4 @@ #include "ruby.h" -#define RUBY_VERSION_CODE %RUBY_VERSION% #ifdef HAVE_MYSQL_H #include <mysql.h> @@ -19,4 +18,12 @@ #define GC_STORE_RESULT_LIMIT 20 +#ifndef RSTRING_PTR +#define RSTRING_PTR(str) RSTRING(str)->ptr +#endif +#ifndef RSTRING_LEN +#define RSTRING_LEN(str) RSTRING(str)->len +#define rb_str_set_len(str, length) (RSTRING_LEN(str) = (length)) +#endif + #ifndef Qtrue /* ruby 1.2.x ? */ #define Qtrue TRUE @@ -283,9 +290,5 @@ ret = rb_str_new(0, (RSTRING_LEN(str))*2+1); len = mysql_escape_string(RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str)); -#if RUBY_VERSION_CODE < 190 - RSTRING(ret)->len = len; -#else rb_str_set_len(ret, len); -#endif return ret; } @@ -423,9 +426,5 @@ ret = rb_str_new(0, (RSTRING_LEN(str))*2+1); len = mysql_real_escape_string(m, RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str)); -#if RUBY_VERSION_CODE < 190 - RSTRING(ret)->len = len; -#else rb_str_set_len(ret, len); -#endif return ret; } @@ -905,9 +904,5 @@ { if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE) -#if RUBY_VERSION_CODE < 160 - TypeError("invalid type, required true or false."); -#else rb_raise(rb_eTypeError, "invalid type, required true or false."); -#endif GetMysqlStruct(obj)->query_with_result = flag; return flag; @@ -983,9 +978,5 @@ n = NUM2INT(nr); if (n >= max) -#if RUBY_VERSION_CODE < 160 - Raise(eMysql, "%d: out of range (max: %d)", n, max-1); -#else rb_raise(eMysql, "%d: out of range (max: %d)", n, max-1); -#endif #if MYSQL_VERSION_ID >= 32226 return make_field_obj(mysql_fetch_field_direct(res, n)); @@ -2264,3 +2255,5 @@ /* Mysql::Error constant */ +#define rb_define_mysql_const(s) rb_define_const(eMysql, #s, INT2NUM(s)) +#include "error_const.h" }
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦