Skip to content

Commit cea30fe

Browse files
committed
Accept Symbol as Function name again
GitHub: fix GH-159 It's used by FFI test. So Symbol may be used by other use cases. GH-139 introduced the "Function name is String" limitation. This commit removed the limitation. Reported by Mamoru TASAKA. Thanks!!!
1 parent 5053ccc commit cea30fe

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

ext/fiddle/function.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ initialize(int argc, VALUE argv[], VALUE self)
154154
if (args[kw_name] != Qundef) {
155155
name = args[kw_name];
156156
#ifdef HAVE_RB_STR_TO_INTERNED_STR
157-
name = rb_str_to_interned_str(name);
157+
if (RB_TYPE_P(name, RUBY_T_STRING)) {
158+
name = rb_str_to_interned_str(name);
159+
}
158160
#endif
159161
}
160162
if (args[kw_need_gvl] != Qundef) {

test/fiddle/test_function.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def test_name
3737
assert_equal 'sin', func.name
3838
end
3939

40+
def test_name_symbol
41+
func = Function.new(@libm['sin'], [TYPE_DOUBLE], TYPE_DOUBLE, name: :sin)
42+
assert_equal :sin, func.name
43+
end
44+
4045
def test_need_gvl?
4146
if RUBY_ENGINE == "jruby"
4247
omit("rb_str_dup() doesn't exist in JRuby")
@@ -261,7 +266,25 @@ def test_no_memory_leak
261266

262267
def test_ractor_shareable
263268
omit("Need Ractor") unless defined?(Ractor)
264-
assert_ractor_shareable(Function.new(@libm['sin'], [TYPE_DOUBLE], TYPE_DOUBLE))
269+
assert_ractor_shareable(Function.new(@libm["sin"],
270+
[TYPE_DOUBLE],
271+
TYPE_DOUBLE))
272+
end
273+
274+
def test_ractor_shareable_name
275+
omit("Need Ractor") unless defined?(Ractor)
276+
assert_ractor_shareable(Function.new(@libm["sin"],
277+
[TYPE_DOUBLE],
278+
TYPE_DOUBLE,
279+
name: "sin"))
280+
end
281+
282+
def test_ractor_shareable_name_symbol
283+
omit("Need Ractor") unless defined?(Ractor)
284+
assert_ractor_shareable(Function.new(@libm["sin"],
285+
[TYPE_DOUBLE],
286+
TYPE_DOUBLE,
287+
name: :sin))
265288
end
266289

267290
private

0 commit comments

Comments
 (0)