Changeset 110

Show
Ignore:
Timestamp:
12/31/2006 18:00:41 (23 months ago)
Author:
mental
Message:
  • ext/sand_table/sand_table.h: added sandwick::self
  • ext/sand_table/sand_table.c: semi-reified sandwicks for proper gc behavior
Location:
trunk/ext/sand_table
Files:
2 modified

Legend:

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

    r105 r110  
    1717 
    1818static VALUE Qimport, Qinit, Qload, Qenv, Qio, Qreal, Qref, Qall; 
    19 VALUE rb_cSandbox, rb_cSandboxFull, rb_cSandboxSafe, rb_eSandboxException, rb_cSandboxRef; 
     19VALUE rb_cSandbox, rb_cSandboxFull, rb_cSandboxSafe, rb_eSandboxException, rb_cSandboxRef, rb_cSandwick; 
    2020static ID s_options; 
    2121 
     
    317317} sandtransfer; 
    318318 
     319void 
     320mark_sandwick(wick) 
     321  sandwick *wick; 
     322{ 
     323  int i; 
     324  for ( i = 0 ; i < wick->argc ; i++ ) { 
     325    rb_gc_mark_maybe(wick->argv[i]); 
     326  } 
     327  rb_gc_mark(wick->link); 
     328  rb_gc_mark(wick->exception); 
     329  if (wick->kit) { 
     330    rb_gc_mark(wick->kit->self); 
     331  } 
     332  rb_gc_mark(wick->banished); 
     333  /* TODO: mark wick->scope and wick->dyna_vars */ 
     334} 
     335 
     336void 
     337free_sandwick(wick) 
     338  sandwick *wick; 
     339{ 
     340  rb_gc_unregister_address(&wick->self); 
     341  free(wick); 
     342} 
     343 
     344sandwick * 
     345alloc_sandwick() 
     346{ 
     347  sandwick *wick; 
     348  wick = (sandwick *)malloc(sizeof(sandwick)); 
     349  wick->self = Qnil; 
     350  wick->argc = 0; 
     351  wick->argv = NULL; 
     352  wick->link = Qnil; 
     353  wick->action = NULL; 
     354  wick->exception = Qnil; 
     355  wick->kit = NULL; 
     356  wick->banished = Qnil; 
     357  wick->scope = NULL; 
     358  wick->dyna_vars = NULL; 
     359 
     360  rb_gc_register_address(&wick->self); 
     361  wick->self = Data_Wrap_Struct(rb_cSandwick, mark_sandwick, free_sandwick, wick); 
     362 
     363  return wick; 
     364} 
     365 
    319366/* 
    320367 * A "wick" for starting a sandbox that calls 
     
    328375  VALUE *argv; 
    329376{ 
    330   sandwick *wick = ALLOC(sandwick); 
     377  sandwick *wick = alloc_sandwick(); 
    331378  wick->calltype = SANDBOX_METHOD_CALL; 
    332   wick->action = NULL; 
    333379  wick->link = link; 
    334380  wick->argc = argc; 
     
    355401  VALUE str; 
    356402{ 
    357   sandwick *wick = ALLOC(sandwick); 
     403  sandwick *wick = alloc_sandwick(); 
    358404  wick->calltype = SANDBOX_EVAL; 
    359   wick->action = NULL; 
    360405  wick->link = str; 
    361   wick->argc = 0; 
    362   wick->argv = NULL; 
    363406  return wick; 
    364407} 
     
    686729  } 
    687730  sandbox_off( wick ); 
    688   free( wick ); 
     731  free_sandwick( wick ); 
    689732  if (!NIL_P(exc)) 
    690733  { 
     
    29603003  Init_kit_real(&base, 0); 
    29613004 
     3005  rb_cSandwick = rb_class_new(rb_cObject); 
     3006 
    29623007  rb_cSandbox = rb_define_module("Sandbox"); 
    29633008  rb_cSandboxFull = rb_define_class_under(rb_cSandbox, "Full", rb_cObject); 
  • trunk/ext/sand_table/sand_table.h

    r108 r110  
    173173 */ 
    174174typedef struct { 
     175  VALUE self; 
     176 
    175177  /* how is the sandbox to be called? */ 
    176178  char calltype;