[ruby/fiddle] Accept Symbol as Function name again

GitHub: fix https://github.com/ruby/fiddle/pull/159

It's used by FFI test. So Symbol may be used by other use cases.

https://github.com/ruby/fiddle/pull/139 introduced the "Function name is String" limitation. This
commit removed the limitation.

Reported by Mamoru TASAKA. Thanks!!!

https://github.com/ruby/fiddle/commit/cea30fe5f9
This commit is contained in:
Sutou Kouhei 2024-11-09 15:33:24 +09:00 коммит произвёл Hiroshi SHIBATA
Родитель 5eaa4c76c6
Коммит a23c6db5c5
2 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -154,7 +154,9 @@ initialize(int argc, VALUE argv[], VALUE self)
if (args[kw_name] != Qundef) {
name = args[kw_name];
#ifdef HAVE_RB_STR_TO_INTERNED_STR
if (RB_TYPE_P(name, RUBY_T_STRING)) {
name = rb_str_to_interned_str(name);
}
#endif
}
if (args[kw_need_gvl] != Qundef) {

Просмотреть файл

@ -37,6 +37,11 @@ module Fiddle
assert_equal 'sin', func.name
end
def test_name_symbol
func = Function.new(@libm['sin'], [TYPE_DOUBLE], TYPE_DOUBLE, name: :sin)
assert_equal :sin, func.name
end
def test_need_gvl?
if RUBY_ENGINE == "jruby"
omit("rb_str_dup() doesn't exist in JRuby")
@ -261,7 +266,25 @@ module Fiddle
def test_ractor_shareable
omit("Need Ractor") unless defined?(Ractor)
assert_ractor_shareable(Function.new(@libm['sin'], [TYPE_DOUBLE], TYPE_DOUBLE))
assert_ractor_shareable(Function.new(@libm["sin"],
[TYPE_DOUBLE],
TYPE_DOUBLE))
end
def test_ractor_shareable_name
omit("Need Ractor") unless defined?(Ractor)
assert_ractor_shareable(Function.new(@libm["sin"],
[TYPE_DOUBLE],
TYPE_DOUBLE,
name: "sin"))
end
def test_ractor_shareable_name_symbol
omit("Need Ractor") unless defined?(Ractor)
assert_ractor_shareable(Function.new(@libm["sin"],
[TYPE_DOUBLE],
TYPE_DOUBLE,
name: :sin))
end
private