Skip to content

Commit cea30fe

Browse files
committed
Accept Symbol as Function name again
GitHub: fixGH-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

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎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
#ifdefHAVE_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+
deftest_name_symbol
41+
func=Function.new(@libm['sin'],[TYPE_DOUBLE],TYPE_DOUBLE,name: :sin)
42+
assert_equal:sin,func.name
43+
end
44+
4045
deftest_need_gvl?
4146
ifRUBY_ENGINE == "jruby"
4247
omit("rb_str_dup() doesn't exist in JRuby")
@@ -261,7 +266,25 @@ def test_no_memory_leak
261266

262267
deftest_ractor_shareable
263268
omit("Need Ractor")unlessdefined?(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+
deftest_ractor_shareable_name
275+
omit("Need Ractor")unlessdefined?(Ractor)
276+
assert_ractor_shareable(Function.new(@libm["sin"],
277+
[TYPE_DOUBLE],
278+
TYPE_DOUBLE,
279+
name: "sin"))
280+
end
281+
282+
deftest_ractor_shareable_name_symbol
283+
omit("Need Ractor")unlessdefined?(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)