Skip to content

Commit a177c27

Browse files
committed
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent f235dbe commit a177c27

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

dmyenc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ int ruby_require_internal(const char *, int);
44
void
55
Init_enc(void)
66
{
7-
if (require("enc/encdb.so") == 0) {
7+
if (require("enc/encdb.so") == 1) {
88
require("enc/trans/transdb.so");
99
}
1010
}

load.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -940,10 +940,17 @@ load_ext(VALUE path)
940940
return (VALUE)dln_load(RSTRING_PTR(path));
941941
}
942942

943+
/*
944+
* returns
945+
* 0: if already loaded (false)
946+
* 1: successfully loaded (true)
947+
* <0: not found (LoadError)
948+
* >1: exception
949+
*/
943950
static int
944951
rb_require_internal(VALUE fname, int safe)
945952
{
946-
volatile int result = -2;
953+
volatile int result = -1;
947954
rb_thread_t *th = GET_THREAD();
948955
volatile VALUE errinfo = th->errinfo;
949956
int state;
@@ -985,11 +992,11 @@ rb_require_internal(VALUE fname, int safe)
985992
}
986993
if (found) {
987994
if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) {
988-
result = -1;
995+
result = 0;
989996
}
990997
else if (!*ftptr) {
991998
rb_provide_feature(path);
992-
result = 0;
999+
result = 1;
9931000
}
9941001
else {
9951002
switch (found) {
@@ -1004,7 +1011,7 @@ rb_require_internal(VALUE fname, int safe)
10041011
break;
10051012
}
10061013
rb_provide_feature(path);
1007-
result = 0;
1014+
result = 1;
10081015
}
10091016
}
10101017
}
@@ -1013,6 +1020,7 @@ rb_require_internal(VALUE fname, int safe)
10131020

10141021
rb_set_safe_level_force(saved.safe);
10151022
if (state) {
1023+
/* never TAG_RETURN */
10161024
return state;
10171025
}
10181026

@@ -1040,14 +1048,14 @@ rb_require_safe(VALUE fname, int safe)
10401048
{
10411049
int result = rb_require_internal(fname, safe);
10421050

1043-
if (result > 0) {
1051+
if (result > 1) {
10441052
JUMP_TAG(result);
10451053
}
1046-
if (result < -1) {
1054+
if (result < 0) {
10471055
load_failed(fname);
10481056
}
10491057

1050-
return result ? Qfalse : Qtrue;
1058+
return result ? Qtrue : Qfalse;
10511059
}
10521060

10531061
VALUE

0 commit comments

Comments
 (0)