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

Support Ruby 3.2 #79

Merged
merged 4 commits into from
Jan 30, 2023
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
28 changes: 17 additions & 11 deletions fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1672,9 +1672,9 @@ static VALUE fb_cursor_fields_ary(XSQLDA *sqlda, short downcase_names)
dtp = var->sqltype & ~1;

if (var->aliasname_length) { /* aliasname always present? */
name = rb_tainted_str_new(var->aliasname, var->aliasname_length);
name = rb_str_new(var->aliasname, var->aliasname_length);
} else {
name = rb_tainted_str_new(var->sqlname, var->sqlname_length);
name = rb_str_new(var->sqlname, var->sqlname_length);
}
if (downcase_names && no_lowercase(name)) {
rb_funcall(name, id_downcase_bang, 0);
Expand Down Expand Up @@ -1816,15 +1816,15 @@ static VALUE fb_cursor_fetch(struct FbCursor *fb_cursor)

switch (dtp) {
case SQL_TEXT:
val = rb_tainted_str_new(var->sqldata, var->sqllen);
val = rb_str_new(var->sqldata, var->sqllen);
#if HAVE_RUBY_ENCODING_H
rb_funcall(val, id_force_encoding, 1, fb_connection->encoding);
#endif
break;

case SQL_VARYING:
vary = (VARY*)var->sqldata;
val = rb_tainted_str_new(vary->vary_string, vary->vary_length);
val = rb_str_new(vary->vary_string, vary->vary_length);
#if HAVE_RUBY_ENCODING_H
rb_funcall(val, id_force_encoding, 1, fb_connection->encoding);
#endif
Expand Down Expand Up @@ -1906,7 +1906,7 @@ static VALUE fb_cursor_fetch(struct FbCursor *fb_cursor)
break;
}
}
val = rb_tainted_str_new(NULL,total_length);
val = rb_str_new(NULL,total_length);
for (p = RSTRING_PTR(val); num_segments > 0; num_segments--, p += actual_seg_len) {
isc_get_segment(fb_connection->isc_status, &blob_handle, &actual_seg_len, max_segment, p);
fb_error_check(fb_connection->isc_status);
Expand Down Expand Up @@ -2727,8 +2727,7 @@ static VALUE default_int(VALUE hash, const char *key, int def)

static VALUE database_allocate_instance(VALUE klass)
{
NEWOBJ(obj, struct RObject);
OBJSETUP((VALUE)obj, klass, T_OBJECT);
NEWOBJ_OF(obj, struct RObject, klass, T_OBJECT);
return (VALUE)obj;
}

Expand Down Expand Up @@ -2941,7 +2940,8 @@ void Init_fb()

rb_mFb = rb_define_module("Fb");

rb_cFbDatabase = rb_define_class_under(rb_mFb, "Database", rb_cData);
rb_cFbDatabase = rb_define_class_under(rb_mFb, "Database", rb_cObject);
rb_undef_alloc_func(rb_cFbDatabase);
rb_define_alloc_func(rb_cFbDatabase, database_allocate_instance);
rb_define_method(rb_cFbDatabase, "initialize", database_initialize, -1);
rb_define_attr(rb_cFbDatabase, "database", 1, 1);
Expand All @@ -2959,7 +2959,9 @@ void Init_fb()
rb_define_method(rb_cFbDatabase, "drop", database_drop, 0);
rb_define_singleton_method(rb_cFbDatabase, "drop", database_s_drop, -1);

rb_cFbConnection = rb_define_class_under(rb_mFb, "Connection", rb_cData);
rb_cFbConnection = rb_define_class_under(rb_mFb, "Connection", rb_cObject);
rb_undef_alloc_func(rb_cFbConnection);
rb_undef_method(CLASS_OF(rb_cFbConnection), "new");
rb_define_attr(rb_cFbConnection, "database", 1, 1);
rb_define_attr(rb_cFbConnection, "username", 1, 1);
rb_define_attr(rb_cFbConnection, "password", 1, 1);
Expand Down Expand Up @@ -2989,7 +2991,9 @@ void Init_fb()
rb_define_method(rb_cFbConnection, "columns", connection_columns, 1);
/* rb_define_method(rb_cFbConnection, "cursor", connection_cursor, 0); */

rb_cFbCursor = rb_define_class_under(rb_mFb, "Cursor", rb_cData);
rb_cFbCursor = rb_define_class_under(rb_mFb, "Cursor", rb_cObject);
rb_undef_alloc_func(rb_cFbCursor);
rb_undef_method(CLASS_OF(rb_cFbCursor), "new");
/* rb_define_method(rb_cFbCursor, "execute", cursor_execute, -1); */
rb_define_method(rb_cFbCursor, "fields", cursor_fields, -1);
rb_define_method(rb_cFbCursor, "fetch", cursor_fetch, -1);
Expand All @@ -2998,7 +3002,9 @@ void Init_fb()
rb_define_method(rb_cFbCursor, "close", cursor_close, 0);
rb_define_method(rb_cFbCursor, "drop", cursor_drop, 0);

rb_cFbSqlType = rb_define_class_under(rb_mFb, "SqlType", rb_cData);
rb_cFbSqlType = rb_define_class_under(rb_mFb, "SqlType", rb_cObject);
rb_undef_alloc_func(rb_cFbSqlType);
rb_undef_method(CLASS_OF(rb_cFbSqlType), "new");
rb_define_singleton_method(rb_cFbSqlType, "from_code", sql_type_from_code, 2);

rb_eFbError = rb_define_class_under(rb_mFb, "Error", rb_eStandardError);
Expand Down
8 changes: 4 additions & 4 deletions test/ConnectionTestCases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ def test_properties_singleton

def test_drop_instance
db = Database.create(@parms)
assert File.exists?(@db_file)
assert File.exist?(@db_file)
connection = db.connect
assert connection.open?
connection.drop
assert !connection.open?
assert !File.exists?(@db_file)
assert !File.exist?(@db_file)
end

def test_drop_singleton
Database.create(@parms) do |connection|
assert File.exists?(@db_file)
assert File.exist?(@db_file)
connection.drop
assert !File.exists?(@db_file)
assert !File.exist?(@db_file)
end
end

Expand Down
22 changes: 11 additions & 11 deletions test/DatabaseTestCases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_initialize_string
def test_create_instance
db = Database.new(@parms)
db.create
assert File.exists?(@db_file)
assert File.exist?(@db_file)
end

def test_create_instance_block
Expand All @@ -82,17 +82,17 @@ def test_create_instance_block
assert_equal 3, connection.dialect
assert_equal 3, connection.db_dialect
end
assert File.exists?(@db_file)
assert File.exist?(@db_file)
end

def test_create_singleton
db = Database.create(@parms);
assert File.exists?(@db_file)
assert File.exist?(@db_file)
end

def test_create_singleton_with_defaults
db = Database.create(:database => "localhost:#{@db_file}");
assert File.exists?(@db_file)
assert File.exist?(@db_file)
end

def test_create_singleton_block
Expand All @@ -103,7 +103,7 @@ def test_create_singleton_block
end
end
assert_instance_of Database, db
assert File.exists?(@db_file)
assert File.exist?(@db_file)
end

def test_create_bad_param
Expand Down Expand Up @@ -133,19 +133,19 @@ def test_connect_singleton
end

def test_drop_instance
assert !File.exists?(@db_file)
assert !File.exist?(@db_file)
db = Database.create(@parms)
assert File.exists?(@db_file)
assert File.exist?(@db_file)
db.drop
assert !File.exists?(@db_file)
assert !File.exist?(@db_file)
end

def test_drop_singleton
assert !File.exists?(@db_file)
assert !File.exist?(@db_file)
Database.create(@parms)
assert File.exists?(@db_file)
assert File.exist?(@db_file)
Database.drop(@parms)
assert !File.exists?(@db_file)
assert !File.exist?(@db_file)
end

def test_role_support
Expand Down