@@ -89,8 +89,8 @@ static mrb_value
8989mrb_sandbox_compile_from_memory (mrb_state * mrb , mrb_value self )
9090{
9191 SS ();
92- const mrb_int address ;
93- const size_t size ;
92+ mrb_int address ;
93+ mrb_int size ;
9494
9595 uint32_t kw_num = 1 ;
9696 uint32_t kw_required = 0 ;
@@ -99,6 +99,12 @@ mrb_sandbox_compile_from_memory(mrb_state *mrb, mrb_value self)
9999 mrb_kwargs kwargs = { kw_num , kw_required , kw_names , kw_values , NULL };
100100
101101 mrb_get_args (mrb , "ii:" , & address , & size , & kwargs );
102+ if (size <= 0 ) {
103+ mrb_raisef (mrb , E_ARGUMENT_ERROR , "invalid size: %S" , mrb_fixnum_value (size ));
104+ }
105+ if (address <= 0 ) {
106+ mrb_raisef (mrb , E_ARGUMENT_ERROR , "invalid address: %S" , mrb_fixnum_value (address ));
107+ }
102108 if (mrb_undef_p (kw_values [0 ])) { kw_values [0 ] = mrb_false_value (); }
103109
104110 if (!sandbox_compile_sub (mrb , ss , (const uint8_t * )(uintptr_t )address , size , kw_values [0 ])) {
@@ -172,7 +178,9 @@ mrb_sandbox_error(mrb_state *mrb, mrb_value self)
172178static mrb_value
173179mrb_sandbox_interrupt (mrb_state * mrb , mrb_value self )
174180{
175- mrb_notimplement (mrb );
181+ SS ();
182+ // TODO: Should fix this workaround?
183+ ss -> tcb -> c .status = MRB_TASK_STOPPED ;
176184 return mrb_nil_value ();
177185}
178186
@@ -224,7 +232,7 @@ static mrb_value
224232mrb_sandbox_exec_vm_code_from_memory (mrb_state * mrb , mrb_value self )
225233{
226234 SS ();
227- const mrb_int address ;
235+ mrb_int address ;
228236 mrb_get_args (mrb , "i" , & address );
229237 ss -> irep = mrb_read_irep (mrb , (const uint8_t * )(uintptr_t )address );
230238 if (sandbox_exec_vm_code_sub (mrb , ss )) {
@@ -251,8 +259,8 @@ mrb_picoruby_sandbox_gem_init(mrb_state *mrb)
251259 MRB_SET_INSTANCE_TT (class_Sandbox , MRB_TT_CDATA );
252260
253261 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (initialize ), mrb_sandbox_initialize , MRB_ARGS_OPT (1 ));
254- mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (compile ), mrb_sandbox_compile , MRB_ARGS_REQ (1 ));
255- mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (compile_from_memory ), mrb_sandbox_compile_from_memory , MRB_ARGS_REQ (2 ));
262+ mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (compile ), mrb_sandbox_compile , MRB_ARGS_REQ (1 )| MRB_ARGS_KEY ( 1 , 1 ) );
263+ mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (compile_from_memory ), mrb_sandbox_compile_from_memory , MRB_ARGS_REQ (2 )| MRB_ARGS_KEY ( 1 , 1 ) );
256264 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (execute ), mrb_sandbox_execute , MRB_ARGS_NONE ());
257265 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (state ), mrb_sandbox_state , MRB_ARGS_NONE ());
258266 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (result ), mrb_sandbox_result , MRB_ARGS_NONE ());
@@ -261,7 +269,7 @@ mrb_picoruby_sandbox_gem_init(mrb_state *mrb)
261269 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (suspend ), mrb_sandbox_suspend , MRB_ARGS_NONE ());
262270 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (free_parser ), mrb_sandbox_free_parser , MRB_ARGS_NONE ());
263271 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (exec_mrb ), mrb_sandbox_exec_vm_code , MRB_ARGS_REQ (1 ));
264- mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (exec_mrb_from_memory ), mrb_sandbox_exec_vm_code_from_memory , MRB_ARGS_REQ (2 ));
272+ mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (exec_mrb_from_memory ), mrb_sandbox_exec_vm_code_from_memory , MRB_ARGS_REQ (1 ));
265273 mrb_define_method_id (mrb , class_Sandbox , MRB_SYM (terminate ), mrb_sandbox_terminate , MRB_ARGS_NONE ());
266274}
267275
0 commit comments