Changeset 91
- Timestamp:
- 09/23/2006 22:09:40 (2 years ago)
- Location:
- trunk/ext/sand_table
- Files:
-
- 3 modified
-
sand_hacks.c (modified) (5 diffs)
-
sand_table.c (modified) (11 diffs)
-
sand_table.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/sand_table/sand_hacks.c
r90 r91 269 269 const char *ptr; 270 270 { 271 NEWOBJ(str, struct RString); 272 OBJSETUP(str, kit->cString, T_STRING); 273 274 str->len = strlen(ptr); 275 str->aux.capa = str->len; 276 str->ptr = ALLOC_N(char,str->len+1); 277 memcpy(str->ptr, ptr, str->len); 278 str->ptr[str->len] = '\0'; 279 280 return (VALUE)str; 271 VALUE str = rb_obj_alloc(kit->cString); 272 return rb_str_buf_cat2(str, ptr); 281 273 } 282 274 … … 290 282 291 283 st_lookup(RCLASS(oklass)->m_tbl, def, (st_data_t *)&body); 292 if (!body ) {284 if (!body || body->nd_body <= (NODE *)1) { 293 285 rb_warn("%s: no method %s found for copying", FREAKYFREAKY, rb_id2name(def)); 294 286 return; … … 351 343 while (*p && *p != ':') p++; 352 344 str = rb_str_new(pbeg, p-pbeg); 353 id = rb_ intern(RSTRING(str)->ptr);345 id = rb_to_id(str); 354 346 if (p[0] == ':') { 355 347 if (p[1] != ':') goto undefined_class; … … 367 359 switch (TYPE(c)) { 368 360 case T_MODULE: 369 kitc = sandbox_defmodule(kit, RSTRING(str)->ptr);361 kitc = sandbox_defmodule(kit, rb_str_ptr(str)); 370 362 break; 371 363 case T_CLASS: 372 kitc = sandbox_defclass(kit, RSTRING(str)->ptr, super);364 kitc = sandbox_defclass(kit, rb_str_ptr(str), super); 373 365 break; 374 366 } … … 376 368 switch (TYPE(c)) { 377 369 case T_MODULE: 378 kitc = rb_define_module_under(kitc, RSTRING(str)->ptr);370 kitc = rb_define_module_under(kitc, rb_str_ptr(str)); 379 371 break; 380 372 case T_CLASS: 381 kitc = rb_define_class_under(kitc, RSTRING(str)->ptr, super);373 kitc = rb_define_class_under(kitc, rb_str_ptr(str), super); 382 374 break; 383 375 } -
trunk/ext/sand_table/sand_table.c
r90 r91 36 36 { 37 37 rb_mark_tbl(kit->tbl); 38 #ifdef KIT2 39 rb_gc_mark_maybe(kit->cBasicObject); 40 #endif 38 41 rb_gc_mark_maybe(kit->cObject); 39 42 rb_gc_mark_maybe(kit->cModule); … … 115 118 rb_gc_mark((VALUE)kit->top_cref); 116 119 rb_gc_mark((VALUE)kit->ruby_cref); 117 rb_gc_mark_maybe(kit->r uby_class);120 rb_gc_mark_maybe(kit->rclass); 118 121 sandbox_mark_globals(kit->globals); 119 122 } … … 201 204 kit->top_cref = rb_node_newnode(NODE_CREF,kit->cObject,0,0); 202 205 kit->ruby_cref = kit->top_cref; 203 kit->ruby_class = kit->cObject; 206 kit->ruby_cref->nd_clss = kit->cObject; 207 kit->rclass = kit->cObject; 204 208 205 209 kit->self = Data_Wrap_Struct( class, mark_sandbox, free_sandbox, kit ); … … 243 247 int init_load = 0, init_env = 0, init_io = 0, init_real = 0; 244 248 init = rb_Array(init); 245 for ( i = 0; i < RARRAY(init)->len; i++ )249 for ( i = 0; i < rb_ary_len(init); i++ ) 246 250 { 247 251 VALUE mod = rb_ary_entry(init, i); … … 272 276 int i; 273 277 Check_Type(import, T_ARRAY); 274 for ( i = 0; i < RARRAY(import)->len; i++ )278 for ( i = 0; i < rb_ary_len(import); i++ ) 275 279 { 276 280 rb_funcall(self, rb_intern("import"), 1, rb_ary_entry(import, i)); … … 308 312 SWAP_VAR(ruby_sandbox, self); 309 313 SWAP_VAR(rb_class_tbl, tbl); 314 #ifdef KIT2 315 SWAP(cBasicObject); 316 #endif 310 317 SWAP(cObject); 311 318 SWAP(cModule); … … 375 382 SWAP_VAR(rb_global_tbl, globals); 376 383 SWAP_VAR(ruby_cref, ruby_cref); 377 SWAP_VAR(ruby_class, ruby_class);384 // SWAP_VAR(ruby_class, rclass); 378 385 SWAP(cMatch); 379 386 SWAP(cMethod); … … 401 408 { 402 409 VALUE msg = rb_funcall(exc, rb_intern("message"), 0); 403 rb_raise(rb_eSandboxException, "%s: %s", rb_class2name(rb_obj_class(exc)), RSTRING(msg)->ptr);410 rb_raise(rb_eSandboxException, "%s: %s", rb_class2name(rb_obj_class(exc)), rb_str_ptr(msg)); 404 411 } 405 412 } … … 433 440 rb_const_set(rb_cObject, rb_intern("TOPLEVEL_BINDING"), rb_eval_string("binding")); 434 441 } 435 return rb_eval_string( RSTRING(str)->ptr);442 return rb_eval_string(rb_str_ptr(str)); 436 443 } 437 444 … … 582 589 kit->cObject = 0; 583 590 591 #ifdef KIT2 592 kit->cBasicObject = sandbox_bootclass(kit, "BasicObject", 0); 593 kit->cObject = sandbox_bootclass(kit, "Object", kit->cBasicObject); 594 #else 584 595 kit->cObject = sandbox_bootclass(kit, "Object", 0); 596 #endif 585 597 kit->cModule = sandbox_bootclass(kit, "Module", kit->cObject); 586 598 kit->cClass = sandbox_bootclass(kit, "Class", kit->cModule); 587 599 600 #ifdef KIT2 601 metaclass = sandbox_metaclass(kit, kit->cBasicObject, kit->cClass); 602 metaclass = sandbox_metaclass(kit, kit->cObject, metaclass); 603 SAND_COPY(cBasicObject, "=="); 604 SAND_COPY(cBasicObject, "equal?"); 605 #else 588 606 metaclass = sandbox_metaclass(kit, kit->cObject, kit->cClass); 607 #endif 589 608 metaclass = sandbox_metaclass(kit, kit->cModule, metaclass); 590 609 metaclass = sandbox_metaclass(kit, kit->cClass, metaclass); … … 592 611 kit->mKernel = sandbox_defmodule(kit, "Kernel"); 593 612 rb_include_module(kit->cObject, kit->mKernel); 594 rb_define_alloc_func(kit ->cObject, sandbox_alloc_obj);613 rb_define_alloc_func(kitBasicObject, sandbox_alloc_obj); 595 614 596 615 rb_define_private_method(kit->cModule, "method_added", sandbox_dummy, 1); 597 rb_define_private_method(kit ->cObject, "initialize", sandbox_dummy, 0);616 rb_define_private_method(kitBasicObject, "initialize", sandbox_dummy, 0); 598 617 rb_define_private_method(kit->cClass, "inherited", sandbox_dummy, 1); 599 618 rb_define_private_method(kit->cModule, "included", sandbox_dummy, 1); -
trunk/ext/sand_table/sand_table.h
r90 r91 28 28 extern st_table *rb_global_tbl; 29 29 30 #ifdef RARRAY_LEN 31 #undef T_SYMBOL 32 #define T_SYMBOL T_STRING 33 static inline long rb_str_len(VALUE s) {return RSTRING_LEN(s);} 34 static inline char *rb_str_ptr(VALUE s) {return RSTRING_PTR(s);} 35 static inline long rb_ary_len(VALUE s) {return RARRAY_LEN(s);} 36 static inline VALUE *rb_ary_ptr(VALUE s) {return RARRAY_PTR(s);} 37 #else 38 static inline long rb_str_len(VALUE s) {return RSTRING(s)->len;} 39 static inline char *rb_str_ptr(VALUE s) {return RSTRING(s)->ptr;} 40 static inline long rb_ary_len(VALUE s) {return RARRAY(s)->len;} 41 static inline VALUE *rb_ary_ptr(VALUE s) {return RARRAY(s)->ptr;} 42 #endif 43 30 44 #if RUBY_VERSION_CODE <= 185 31 45 #warning "** Sandbox will NOT compile without a patched 1.8.5 -- Proceeding anyway! **" 46 #endif 47 48 #if RUBY_VERSION_CODE > 190 49 #define KIT2 50 #define kitBasicObject kit->cBasicObject 51 #else 52 #define kitBasicObject kit->cObject 32 53 #endif 33 54 … … 42 63 VALUE _progname; 43 64 65 #if KIT2 66 VALUE cBasicObject; 67 #endif 44 68 VALUE cObject; 45 69 VALUE cModule; … … 131 155 NODE *top_cref; 132 156 NODE *ruby_cref; 133 VALUE r uby_class;157 VALUE rclass; 134 158 struct SCOPE *scope; 135 159 } sandkit;
