File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,10 @@ with_gvl_callback(void *ptr)
130
130
rb_ary_push (params , ULL2NUM (* (unsigned LONG_LONG * )x -> args [i ]));
131
131
break ;
132
132
#endif
133
+ case TYPE_CONST_STRING :
134
+ rb_ary_push (params ,
135
+ rb_str_new_cstr (* ((const char * * )(x -> args [i ]))));
136
+ break ;
133
137
default :
134
138
rb_raise (rb_eRuntimeError , "closure args: %d" , type );
135
139
}
@@ -175,6 +179,10 @@ with_gvl_callback(void *ptr)
175
179
* (unsigned LONG_LONG * )x -> resp = NUM2ULL (ret );
176
180
break ;
177
181
#endif
182
+ case TYPE_CONST_STRING :
183
+ /* Dangerous. Callback must keep reference of the String. */
184
+ * ((const char * * )(x -> resp )) = StringValueCStr (ret );
185
+ break ;
178
186
default :
179
187
rb_raise (rb_eRuntimeError , "closure retval: %d" , type );
180
188
}
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ def call thing
54
54
assert_equal 10 , func . call ( 10 )
55
55
end
56
56
57
+ def test_const_string
58
+ closure_class = Class . new ( Closure ) do
59
+ def call ( string )
60
+ @return_string = "Hello! #{ string } "
61
+ @return_string
62
+ end
63
+ end
64
+ closure = closure_class . new ( :const_string , [ :const_string ] )
65
+
66
+ func = Function . new ( closure , [ :const_string ] , :const_string )
67
+ assert_equal ( "Hello! World!" , func . call ( "World!" ) )
68
+ end
69
+
57
70
def test_block_caller
58
71
cb = Closure ::BlockCaller . new ( TYPE_INT , [ TYPE_INT ] ) do |one |
59
72
one
You can’t perform that action at this time.
0 commit comments