ruby-changes:36616
From: nobu <ko1@a...>
Date: Wed, 3 Dec 2014 15:14:07 +0900 (JST)
Subject: [ruby-changes:36616] nobu:r48697 (trunk): load.c: tweak the return value
nobu 2014-12-03 15:13:58 +0900 (Wed, 03 Dec 2014) New Revision: 48697 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48697 Log: load.c: tweak the return value * load.c (rb_require_internal): tweak the return value, 1 and 0 correspond to true and false in Kernel#require, respectively. Modified files: trunk/dmyenc.c trunk/load.c Index: dmyenc.c =================================================================== --- dmyenc.c (revision 48696) +++ dmyenc.c (revision 48697) @@ -4,7 +4,7 @@ int ruby_require_internal(const char *, https://github.com/ruby/ruby/blob/trunk/dmyenc.c#L4 void Init_enc(void) { - if (require("enc/encdb.so") == 0) { + if (require("enc/encdb.so") == 1) { require("enc/trans/transdb.so"); } } Index: load.c =================================================================== --- load.c (revision 48696) +++ load.c (revision 48697) @@ -940,10 +940,17 @@ load_ext(VALUE path) https://github.com/ruby/ruby/blob/trunk/load.c#L940 return (VALUE)dln_load(RSTRING_PTR(path)); } +/* + * returns + * 0: if already loaded (false) + * 1: successfully loaded (true) + * <0: not found (LoadError) + * >1: exception + */ static int rb_require_internal(VALUE fname, int safe) { - volatile int result = -2; + volatile int result = -1; rb_thread_t *th = GET_THREAD(); volatile VALUE errinfo = th->errinfo; int state; @@ -985,11 +992,11 @@ rb_require_internal(VALUE fname, int saf https://github.com/ruby/ruby/blob/trunk/load.c#L992 } if (found) { if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) { - result = -1; + result = 0; } else if (!*ftptr) { rb_provide_feature(path); - result = 0; + result = 1; } else { switch (found) { @@ -1004,7 +1011,7 @@ rb_require_internal(VALUE fname, int saf https://github.com/ruby/ruby/blob/trunk/load.c#L1011 break; } rb_provide_feature(path); - result = 0; + result = 1; } } } @@ -1013,6 +1020,7 @@ rb_require_internal(VALUE fname, int saf https://github.com/ruby/ruby/blob/trunk/load.c#L1020 rb_set_safe_level_force(saved.safe); if (state) { + /* never TAG_RETURN */ return state; } @@ -1040,14 +1048,14 @@ rb_require_safe(VALUE fname, int safe) https://github.com/ruby/ruby/blob/trunk/load.c#L1048 { int result = rb_require_internal(fname, safe); - if (result > 0) { + if (result > 1) { JUMP_TAG(result); } - if (result < -1) { + if (result < 0) { load_failed(fname); } - return result ? Qfalse : Qtrue; + return result ? Qtrue : Qfalse; } VALUE -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/