Changeset 102

Show
Ignore:
Timestamp:
10/05/2006 18:27:52 (2 years ago)
Author:
mental
Message:

eliminate most direct uses of sandbox_begin/sandbox_whoa_whoa_whoa in favor of sandbox_perform (or sandbox_perform_raw)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/sand_table/sand_table.c

    r101 r102  
    2727static void Init_kit_prelude _((sandkit *)); 
    2828void sandbox_swap(sandkit *kit, int mode); 
     29static VALUE sandbox_perform_raw _((sandkit *, VALUE (*)(), VALUE)); 
     30 
     31typedef struct { 
     32  VALUE (*f)(); 
     33  VALUE data; 
     34} mini_closure; 
    2935 
    3036#define SANDBOX_STORE 1 
     
    484490 
    485491VALUE 
     492sandbox_capture_exception(go, exc) 
     493  go_cart *go; 
     494  VALUE exc; 
     495{ 
     496  go->exception = exc; 
     497  return Qnil; 
     498} 
     499 
     500static VALUE 
     501sandbox_perform_inner(value) 
     502  VALUE value; 
     503{ 
     504  go_cart *go=(go_cart *)value; 
     505  mini_closure *closure=(mini_closure *)go->argv[0]; 
     506  return rb_rescue2(closure->f, closure->data, sandbox_capture_exception, (VALUE)go, rb_cObject, 0); 
     507} 
     508 
     509static VALUE 
     510sandbox_perform_raw(kit, action, arg) 
     511  sandkit *kit; 
     512  VALUE (*action)(); 
     513  VALUE arg; 
     514{ 
     515  mini_closure closure={ action, arg }; 
     516  VALUE temp=(VALUE)&closure; 
     517  go_cart go; 
     518  sandbox_begin(kit, &go); 
     519  go.argv = &temp; 
     520  return rb_ensure(sandbox_perform_inner, (VALUE)&go, sandbox_whoa_whoa_whoa, (VALUE)&go); 
     521} 
     522 
     523VALUE 
    486524sandbox_perform(kit, action, arg) 
    487525  sandkit *kit; 
     
    489527  VALUE arg; 
    490528{ 
    491   go_cart go; 
    492   sandbox_begin(kit, &go); 
    493   return sandbox_obj_ref(kit, rb_ensure(action, arg, sandbox_whoa_whoa_whoa, (VALUE)&go)); 
     529  return sandbox_obj_ref(kit, sandbox_perform_raw(kit, action, arg)); 
    494530} 
    495531 
    496532VALUE 
    497 sandbox_inner_eval(go) 
    498   go_cart *go; 
    499 { 
    500   VALUE str = go->argv[0]; 
     533sandbox_go_go_go(str) 
     534  VALUE str; 
     535{ 
    501536  StringValue(str); 
    502537  if (!rb_const_defined(rb_cObject, rb_intern("TOPLEVEL_BINDING"))) { 
     
    506541} 
    507542 
    508 VALUE 
    509 sandbox_capture_exception(go, exc) 
    510   go_cart *go; 
    511   VALUE exc; 
    512 { 
    513   go->exception = exc; 
    514   return Qnil; 
    515 } 
    516  
    517 VALUE 
    518 sandbox_go_go_go(go) 
    519   go_cart *go; 
    520 { 
    521   return rb_rescue2(sandbox_inner_eval, (VALUE)go, sandbox_capture_exception, (VALUE)go, rb_cObject, 0); 
    522 } 
    523  
    524543/* :nodoc: */ 
    525544VALUE 
     
    527546  VALUE self, str; 
    528547{ 
    529   go_cart go; 
    530548  sandkit *kit; 
    531549  Data_Get_Struct( self, sandkit, kit ); 
    532   sandbox_begin(kit, &go); 
    533   go.argv = &str; 
    534   return sandbox_obj_ref(kit, rb_ensure(sandbox_go_go_go, (VALUE)&go, sandbox_whoa_whoa_whoa, (VALUE)&go)); 
     550  return sandbox_perform(kit, sandbox_go_go_go, (VALUE)str); 
    535551} 
    536552 
     
    571587 
    572588VALUE 
    573 sandbox_safe_go_go_go(go) 
    574   go_cart *go; 
    575 { 
    576   return rb_marshal_dump(sandbox_go_go_go(go), Qnil); 
     589sandbox_safe_go_go_go(str) 
     590  VALUE str; 
     591{ 
     592  return rb_marshal_dump(sandbox_go_go_go(str), Qnil); 
    577593} 
    578594 
     
    583599{ 
    584600  VALUE marshed; 
    585   go_cart go; 
    586601  sandkit *kit; 
    587602  Data_Get_Struct( self, sandkit, kit ); 
    588   sandbox_begin(kit, &go); 
    589   go.argv = &str; 
    590   marshed = rb_ensure(sandbox_safe_go_go_go, (VALUE)&go, sandbox_whoa_whoa_whoa, (VALUE)&go); 
     603  marshed = sandbox_perform(kit, sandbox_safe_go_go_go, str); 
    591604  return rb_marshal_load(marshed); 
    592605} 
     
    613626  VALUE obj; 
    614627{ 
    615   VALUE sandobj = rb_marshal_dump(obj, Qnil); 
    616   go_cart go; 
    617   sandbox_begin(kit, &go); 
    618   sandobj = rb_marshal_load(sandobj); 
    619   sandbox_whoa_whoa_whoa(&go); 
    620   return sandobj; 
     628  return sandbox_perform_raw(kit, rb_marshal_load, rb_marshal_dump(obj, Qnil)); 
    621629} 
    622630 
     
    27652773} 
    27662774 
     2775typedef struct { 
     2776  sandkit *kit; 
     2777  VALUE prelude; 
     2778} Init_kit_prelude_args; 
     2779 
     2780static VALUE 
     2781Init_kit_prelude_inner(value) 
     2782  VALUE value; 
     2783{ 
     2784  Init_kit_prelude_args *args=(Init_kit_prelude_args *)value; 
     2785#if defined(HAVE_TIMES) || defined(_WIN32) 
     2786  if (args->kit->mProcess != 0) { 
     2787    args->kit->sTms = rb_struct_define("Tms", "utime", "stime", "cutime", "cstime", NULL); 
     2788  } 
     2789#endif 
     2790  rb_load(args->prelude, 0); 
     2791  return Qnil; 
     2792} 
     2793 
    27672794static void 
    27682795Init_kit_prelude(kit) 
    27692796  sandkit *kit; 
    27702797{ 
    2771   go_cart go; 
    2772   VALUE prelude = rb_const_get(rb_cSandbox, rb_intern("PRELUDE")); 
    2773   StringValue(prelude); 
    2774   sandbox_begin(kit, &go); 
    2775 #if defined(HAVE_TIMES) || defined(_WIN32) 
    2776   if (kit->mProcess != 0) { 
    2777     kit->sTms = rb_struct_define("Tms", "utime", "stime", "cutime", "cstime", NULL); 
    2778   } 
    2779 #endif 
    2780  
    2781   rb_load(prelude, 0); 
    2782   sandbox_whoa_whoa_whoa(&go); 
     2798  Init_kit_prelude_args args; 
     2799  args.kit = kit; 
     2800  args.prelude = rb_const_get(rb_cSandbox, rb_intern("PRELUDE")); 
     2801  StringValue(args.prelude); 
     2802  sandbox_perform_raw(kit, Init_kit_prelude_inner, (VALUE)&args); 
    27832803} 
    27842804