Created
October 25, 2011 02:30
-
-
Save tenderlove/1311137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/load.c b/load.c | |
index 9ed386d..1a6f5e9 100644 | |
--- a/load.c | |
+++ b/load.c | |
@@ -270,7 +270,7 @@ rb_provide(const char *feature) | |
NORETURN(static void load_failed(VALUE)); | |
static void | |
-rb_load_internal(VALUE fname, int wrap) | |
+rb_load_internal(VALUE fname, VALUE wrap) | |
{ | |
int state; | |
rb_thread_t *th = GET_THREAD(); | |
@@ -284,14 +284,14 @@ rb_load_internal(VALUE fname, int wrap) | |
th->errinfo = Qnil; /* ensure */ | |
- if (!wrap) { | |
+ if (!wrap || NIL_P(wrap)) { | |
rb_secure(4); /* should alter global state */ | |
th->top_wrapper = 0; | |
} | |
else { | |
/* load in anonymous module as toplevel */ | |
th->top_self = rb_obj_clone(rb_vm_top_self()); | |
- th->top_wrapper = rb_module_new(); | |
+ th->top_wrapper = wrap; | |
rb_extend_object(th->top_self, th->top_wrapper); | |
} | |
@@ -336,8 +336,12 @@ void | |
rb_load(VALUE fname, int wrap) | |
{ | |
VALUE tmp = rb_find_file(FilePathValue(fname)); | |
+ VALUE wrapper; | |
+ | |
if (!tmp) load_failed(fname); | |
- rb_load_internal(tmp, wrap); | |
+ | |
+ wrapper = wrap ? rb_module_new() : Qnil; | |
+ rb_load_internal(tmp, wrapper); | |
} | |
void | |
@@ -380,7 +384,7 @@ rb_f_load(int argc, VALUE *argv) | |
load_failed(fname); | |
path = fname; | |
} | |
- rb_load_internal(path, RTEST(wrap)); | |
+ rb_load_internal(path, wrap); | |
return Qtrue; | |
} | |
@@ -616,7 +620,7 @@ rb_require_safe(VALUE fname, int safe) | |
else { | |
switch (found) { | |
case 'r': | |
- rb_load_internal(path, 0); | |
+ rb_load_internal(path, Qnil); | |
break; | |
case 's': |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Huh. Effectively, one hacky way to add namespaces. Sweet.