Avoid tainted string function deprecation warnings, and allow eventual
building and running without warnings on Ruby 3.2. OK tb@
This commit is contained in:
parent
f283ff5f4e
commit
477f3b51b4
|
@ -1,7 +1,7 @@
|
|||
COMMENT= access a MySQL database from Ruby
|
||||
|
||||
DISTNAME= mysql-2.9.1
|
||||
REVISION= 6
|
||||
REVISION= 7
|
||||
CATEGORIES= databases
|
||||
|
||||
HOMEPAGE= http://tmtm.org/mysql/ruby/
|
||||
|
|
|
@ -6,9 +6,37 @@ Mysql#close not cause a crash if called more than once.
|
|||
|
||||
Remove client version check, which stopped working in MariaDB 10.6.
|
||||
|
||||
Replace tainted string functions with non-tainted ones, as Ruby has removed
|
||||
tainted string support.
|
||||
|
||||
Undef alloc function for Mysql and Mysql::Result to work around warning
|
||||
in Ruby 3.2.
|
||||
|
||||
Index: ext/mysql_api/mysql.c
|
||||
--- ext/mysql_api/mysql.c.orig
|
||||
+++ ext/mysql_api/mysql.c
|
||||
@@ -170,7 +170,7 @@ static void mysql_raise(MYSQL* m)
|
||||
VALUE e = rb_exc_new2(eMysql, mysql_error(m));
|
||||
rb_iv_set(e, "errno", INT2FIX(mysql_errno(m)));
|
||||
#if MYSQL_VERSION_ID >= 40101
|
||||
- rb_iv_set(e, "sqlstate", rb_tainted_str_new2(mysql_sqlstate(m)));
|
||||
+ rb_iv_set(e, "sqlstate", rb_str_new2(mysql_sqlstate(m)));
|
||||
#endif
|
||||
rb_exc_raise(e);
|
||||
}
|
||||
@@ -197,9 +197,9 @@ static VALUE make_field_obj(MYSQL_FIELD* f)
|
||||
if (f == NULL)
|
||||
return Qnil;
|
||||
obj = rb_obj_alloc(cMysqlField);
|
||||
- rb_iv_set(obj, "name", f->name? rb_str_freeze(rb_tainted_str_new2(f->name)): Qnil);
|
||||
- rb_iv_set(obj, "table", f->table? rb_str_freeze(rb_tainted_str_new2(f->table)): Qnil);
|
||||
- rb_iv_set(obj, "def", f->def? rb_str_freeze(rb_tainted_str_new2(f->def)): Qnil);
|
||||
+ rb_iv_set(obj, "name", f->name? rb_str_freeze(rb_str_new2(f->name)): Qnil);
|
||||
+ rb_iv_set(obj, "table", f->table? rb_str_freeze(rb_str_new2(f->table)): Qnil);
|
||||
+ rb_iv_set(obj, "def", f->def? rb_str_freeze(rb_str_new2(f->def)): Qnil);
|
||||
rb_iv_set(obj, "type", INT2NUM(f->type));
|
||||
rb_iv_set(obj, "length", INT2NUM(f->length));
|
||||
rb_iv_set(obj, "max_length", INT2NUM(f->max_length));
|
||||
@@ -273,7 +273,6 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE
|
||||
rb_thread_start_timer();
|
||||
#endif
|
||||
|
@ -17,6 +45,15 @@ Index: ext/mysql_api/mysql.c
|
|||
myp->connection = Qtrue;
|
||||
myp->query_with_result = Qtrue;
|
||||
rb_obj_call_init(obj, argc, argv);
|
||||
@@ -294,7 +293,7 @@ static VALUE escape_string(VALUE klass, VALUE str)
|
||||
/* client_info() */
|
||||
static VALUE client_info(VALUE klass)
|
||||
{
|
||||
- return rb_tainted_str_new2(mysql_get_client_info());
|
||||
+ return rb_str_new2(mysql_get_client_info());
|
||||
}
|
||||
|
||||
#if MYSQL_VERSION_ID >= 32332
|
||||
@@ -347,7 +346,6 @@ static VALUE real_connect2(int argc, VALUE* argv, VALU
|
||||
#ifdef HAVE_RB_THREAD_START_TIMER
|
||||
rb_thread_start_timer();
|
||||
|
@ -25,6 +62,15 @@ Index: ext/mysql_api/mysql.c
|
|||
GetMysqlStruct(obj)->connection = Qtrue;
|
||||
|
||||
return obj;
|
||||
@@ -469,7 +467,7 @@ static VALUE change_user(int argc, VALUE* argv, VALUE
|
||||
/* character_set_name() */
|
||||
static VALUE character_set_name(VALUE obj)
|
||||
{
|
||||
- return rb_tainted_str_new2(mysql_character_set_name(GetHandler(obj)));
|
||||
+ return rb_str_new2(mysql_character_set_name(GetHandler(obj)));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -477,8 +475,10 @@ static VALUE character_set_name(VALUE obj)
|
||||
static VALUE my_close(VALUE obj)
|
||||
{
|
||||
|
@ -38,6 +84,68 @@ Index: ext/mysql_api/mysql.c
|
|||
return obj;
|
||||
}
|
||||
|
||||
@@ -534,7 +534,7 @@ static VALUE field_count(VALUE obj)
|
||||
/* host_info() */
|
||||
static VALUE host_info(VALUE obj)
|
||||
{
|
||||
- return rb_tainted_str_new2(mysql_get_host_info(GetHandler(obj)));
|
||||
+ return rb_str_new2(mysql_get_host_info(GetHandler(obj)));
|
||||
}
|
||||
|
||||
/* proto_info() */
|
||||
@@ -546,14 +546,14 @@ static VALUE proto_info(VALUE obj)
|
||||
/* server_info() */
|
||||
static VALUE server_info(VALUE obj)
|
||||
{
|
||||
- return rb_tainted_str_new2(mysql_get_server_info(GetHandler(obj)));
|
||||
+ return rb_str_new2(mysql_get_server_info(GetHandler(obj)));
|
||||
}
|
||||
|
||||
/* info() */
|
||||
static VALUE info(VALUE obj)
|
||||
{
|
||||
const char* p = mysql_info(GetHandler(obj));
|
||||
- return p? rb_tainted_str_new2(p): Qnil;
|
||||
+ return p? rb_str_new2(p): Qnil;
|
||||
}
|
||||
|
||||
/* insert_id() */
|
||||
@@ -588,7 +588,7 @@ static VALUE list_dbs(int argc, VALUE* argv, VALUE obj
|
||||
n = mysql_num_rows(res);
|
||||
ret = rb_ary_new2(n);
|
||||
for (i=0; i<n; i++)
|
||||
- rb_ary_store(ret, i, rb_tainted_str_new2(mysql_fetch_row(res)[0]));
|
||||
+ rb_ary_store(ret, i, rb_str_new2(mysql_fetch_row(res)[0]));
|
||||
mysql_free_result(res);
|
||||
return ret;
|
||||
}
|
||||
@@ -633,7 +633,7 @@ static VALUE list_tables(int argc, VALUE* argv, VALUE
|
||||
n = mysql_num_rows(res);
|
||||
ret = rb_ary_new2(n);
|
||||
for (i=0; i<n; i++)
|
||||
- rb_ary_store(ret, i, rb_tainted_str_new2(mysql_fetch_row(res)[0]));
|
||||
+ rb_ary_store(ret, i, rb_str_new2(mysql_fetch_row(res)[0]));
|
||||
mysql_free_result(res);
|
||||
return ret;
|
||||
}
|
||||
@@ -697,7 +697,7 @@ static VALUE my_stat(VALUE obj)
|
||||
const char* s = mysql_stat(m);
|
||||
if (s == NULL)
|
||||
mysql_raise(m);
|
||||
- return rb_tainted_str_new2(s);
|
||||
+ return rb_str_new2(s);
|
||||
}
|
||||
|
||||
/* store_result() */
|
||||
@@ -864,7 +864,7 @@ static VALUE set_server_option(VALUE obj, VALUE option
|
||||
static VALUE sqlstate(VALUE obj)
|
||||
{
|
||||
MYSQL *m = GetHandler(obj);
|
||||
- return rb_tainted_str_new2(mysql_sqlstate(m));
|
||||
+ return rb_str_new2(mysql_sqlstate(m));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -875,12 +875,12 @@ static VALUE stmt_init(VALUE obj)
|
||||
MYSQL *m = GetHandler(obj);
|
||||
MYSQL_STMT *s;
|
||||
|
@ -68,6 +176,51 @@ Index: ext/mysql_api/mysql.c
|
|||
return flag;
|
||||
}
|
||||
|
||||
@@ -1029,7 +1028,7 @@ static VALUE fetch_row(VALUE obj)
|
||||
return Qnil;
|
||||
ary = rb_ary_new2(n);
|
||||
for (i=0; i<n; i++)
|
||||
- rb_ary_store(ary, i, row[i]? rb_tainted_str_new(row[i], lengths[i]): Qnil);
|
||||
+ rb_ary_store(ary, i, row[i]? rb_str_new(row[i], lengths[i]): Qnil);
|
||||
return ary;
|
||||
}
|
||||
|
||||
@@ -1053,7 +1052,7 @@ static VALUE fetch_hash2(VALUE obj, VALUE with_table)
|
||||
if (colname == Qnil) {
|
||||
colname = rb_ary_new2(n);
|
||||
for (i=0; i<n; i++) {
|
||||
- VALUE s = rb_tainted_str_new2(fields[i].name);
|
||||
+ VALUE s = rb_str_new2(fields[i].name);
|
||||
rb_obj_freeze(s);
|
||||
rb_ary_store(colname, i, s);
|
||||
}
|
||||
@@ -1066,7 +1065,7 @@ static VALUE fetch_hash2(VALUE obj, VALUE with_table)
|
||||
colname = rb_ary_new2(n);
|
||||
for (i=0; i<n; i++) {
|
||||
int len = strlen(fields[i].table)+strlen(fields[i].name)+1;
|
||||
- VALUE s = rb_tainted_str_new(NULL, len);
|
||||
+ VALUE s = rb_str_new(NULL, len);
|
||||
snprintf(RSTRING_PTR(s), len+1, "%s.%s", fields[i].table, fields[i].name);
|
||||
rb_obj_freeze(s);
|
||||
rb_ary_store(colname, i, s);
|
||||
@@ -1076,7 +1075,7 @@ static VALUE fetch_hash2(VALUE obj, VALUE with_table)
|
||||
}
|
||||
}
|
||||
for (i=0; i<n; i++) {
|
||||
- rb_hash_aset(hash, rb_ary_entry(colname, i), row[i]? rb_tainted_str_new(row[i], lengths[i]): Qnil);
|
||||
+ rb_hash_aset(hash, rb_ary_entry(colname, i), row[i]? rb_str_new(row[i], lengths[i]): Qnil);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
@@ -1257,7 +1256,7 @@ static void mysql_stmt_raise(MYSQL_STMT* s)
|
||||
{
|
||||
VALUE e = rb_exc_new2(eMysql, mysql_stmt_error(s));
|
||||
rb_iv_set(e, "errno", INT2FIX(mysql_stmt_errno(s)));
|
||||
- rb_iv_set(e, "sqlstate", rb_tainted_str_new2(mysql_stmt_sqlstate(s)));
|
||||
+ rb_iv_set(e, "sqlstate", rb_str_new2(mysql_stmt_sqlstate(s)));
|
||||
rb_exc_raise(e);
|
||||
}
|
||||
|
||||
@@ -1317,7 +1316,7 @@ static VALUE stmt_bind_result(int argc, VALUE *argv, V
|
||||
}
|
||||
else if (argv[i] == rb_cString)
|
||||
|
@ -77,7 +230,25 @@ Index: ext/mysql_api/mysql.c
|
|||
s->result.bind[i].buffer_type = MYSQL_TYPE_LONGLONG;
|
||||
else if (argv[i] == rb_cFloat)
|
||||
s->result.bind[i].buffer_type = MYSQL_TYPE_DOUBLE;
|
||||
@@ -1887,17 +1886,6 @@ void Init_mysql_api(void)
|
||||
@@ -1573,7 +1572,7 @@ static VALUE stmt_fetch(VALUE obj)
|
||||
case MYSQL_TYPE_NEWDECIMAL:
|
||||
case MYSQL_TYPE_BIT:
|
||||
#endif
|
||||
- v = rb_tainted_str_new(s->result.bind[i].buffer, s->result.length[i]);
|
||||
+ v = rb_str_new(s->result.bind[i].buffer, s->result.length[i]);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eTypeError, "unknown buffer_type: %d", s->result.bind[i].buffer_type);
|
||||
@@ -1762,7 +1761,7 @@ static VALUE stmt_send_long_data(VALUE obj, VALUE col,
|
||||
static VALUE stmt_sqlstate(VALUE obj)
|
||||
{
|
||||
struct mysql_stmt* s = DATA_PTR(obj);
|
||||
- return rb_tainted_str_new2(mysql_stmt_sqlstate(s->stmt));
|
||||
+ return rb_str_new2(mysql_stmt_sqlstate(s->stmt));
|
||||
}
|
||||
|
||||
/*-------------------------------
|
||||
@@ -1887,20 +1886,11 @@ void Init_mysql_api(void)
|
||||
int i;
|
||||
int dots = 0;
|
||||
const char *lib = mysql_get_client_info();
|
||||
|
@ -94,4 +265,9 @@ Index: ext/mysql_api/mysql.c
|
|||
- }
|
||||
|
||||
cMysql = rb_define_class("Mysql", rb_cObject);
|
||||
+ rb_undef_alloc_func(cMysql);
|
||||
cMysqlRes = rb_define_class_under(cMysql, "Result", rb_cObject);
|
||||
+ rb_undef_alloc_func(cMysqlRes);
|
||||
cMysqlField = rb_define_class_under(cMysql, "Field", rb_cObject);
|
||||
#if MYSQL_VERSION_ID >= 40102
|
||||
cMysqlStmt = rb_define_class_under(cMysql, "Stmt", rb_cObject);
|
||||
|
|
Loading…
Reference in New Issue