Skip to content

Commit

Permalink
load.c: tweak the return value
Browse files Browse the repository at this point in the history
* load.c (rb_require_internal): tweak the return value, 1 and 0
  correspond to true and false in Kernel#require, respectively.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Dec 3, 2014
1 parent f235dbe commit a177c27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dmyenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ int ruby_require_internal(const char *, int);
void
Init_enc(void)
{
if (require("enc/encdb.so") == 0) {
if (require("enc/encdb.so") == 1) {
require("enc/trans/transdb.so");
}
}
22 changes: 15 additions & 7 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,17 @@ load_ext(VALUE path)
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;
Expand Down Expand Up @@ -985,11 +992,11 @@ rb_require_internal(VALUE fname, int safe)
}
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) {
Expand All @@ -1004,7 +1011,7 @@ rb_require_internal(VALUE fname, int safe)
break;
}
rb_provide_feature(path);
result = 0;
result = 1;
}
}
}
Expand All @@ -1013,6 +1020,7 @@ rb_require_internal(VALUE fname, int safe)

rb_set_safe_level_force(saved.safe);
if (state) {
/* never TAG_RETURN */
return state;
}

Expand Down Expand Up @@ -1040,14 +1048,14 @@ rb_require_safe(VALUE fname, int safe)
{
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
Expand Down

0 comments on commit a177c27

Please sign in to comment.