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)
130130 rb_ary_push (params , ULL2NUM (* (unsigned LONG_LONG * )x -> args [i ]));
131131 break ;
132132#endif
133+ case TYPE_CONST_STRING :
134+ rb_ary_push (params ,
135+ rb_str_new_cstr (* ((const char * * )(x -> args [i ]))));
136+ break ;
133137 default :
134138 rb_raise (rb_eRuntimeError , "closure args: %d" , type );
135139 }
@@ -175,6 +179,10 @@ with_gvl_callback(void *ptr)
175179 * (unsigned LONG_LONG * )x -> resp = NUM2ULL (ret );
176180 break ;
177181#endif
182+ case TYPE_CONST_STRING :
183+ /* Dangerous. Callback must keep reference of the String. */
184+ * ((const char * * )(x -> resp )) = StringValueCStr (ret );
185+ break ;
178186 default :
179187 rb_raise (rb_eRuntimeError , "closure retval: %d" , type );
180188 }
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ def call thing
5454 assert_equal 10 , func . call ( 10 )
5555 end
5656
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+
5770 def test_block_caller
5871 cb = Closure ::BlockCaller . new ( TYPE_INT , [ TYPE_INT ] ) do |one |
5972 one
You can’t perform that action at this time.
0 commit comments