Skip to content

Commit f235dbe

Browse files
committed
dmyenc.c: try to load encdb
* load.c (ruby_require_internal): separate from rb_require_safe, not to raise exceptions. * ruby.c (process_options): remove unnatural encoding search. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 49b3b2d commit f235dbe

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

ChangeLog

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Wed Dec 3 14:51:26 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* load.c (ruby_require_internal): separate from rb_require_safe,
4+
not to raise exceptions.
5+
6+
* ruby.c (process_options): remove unnatural encoding search.
7+
18
Wed Dec 3 14:34:07 2014 Nobuyoshi Nakada <[email protected]>
29

310
* string.c (setup_fake_str): fake string does not share another

dmyenc.c

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
#define require(name) ruby_require_internal(name, (unsigned int)sizeof(name)-1)
2+
int ruby_require_internal(const char *, int);
3+
14
void
25
Init_enc(void)
36
{
7+
if (require("enc/encdb.so") == 0) {
8+
require("enc/trans/transdb.so");
9+
}
410
}

load.c

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

943-
VALUE
944-
rb_require_safe(VALUE fname, int safe)
943+
static int
944+
rb_require_internal(VALUE fname, int safe)
945945
{
946-
volatile VALUE result = Qnil;
946+
volatile int result = -2;
947947
rb_thread_t *th = GET_THREAD();
948948
volatile VALUE errinfo = th->errinfo;
949949
int state;
@@ -985,11 +985,11 @@ rb_require_safe(VALUE fname, int safe)
985985
}
986986
if (found) {
987987
if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) {
988-
result = Qfalse;
988+
result = -1;
989989
}
990990
else if (!*ftptr) {
991991
rb_provide_feature(path);
992-
result = Qtrue;
992+
result = 0;
993993
}
994994
else {
995995
switch (found) {
@@ -1004,7 +1004,7 @@ rb_require_safe(VALUE fname, int safe)
10041004
break;
10051005
}
10061006
rb_provide_feature(path);
1007-
result = Qtrue;
1007+
result = 0;
10081008
}
10091009
}
10101010
}
@@ -1013,11 +1013,7 @@ rb_require_safe(VALUE fname, int safe)
10131013

10141014
rb_set_safe_level_force(saved.safe);
10151015
if (state) {
1016-
JUMP_TAG(state);
1017-
}
1018-
1019-
if (NIL_P(result)) {
1020-
load_failed(fname);
1016+
return state;
10211017
}
10221018

10231019
th->errinfo = errinfo;
@@ -1031,6 +1027,29 @@ rb_require_safe(VALUE fname, int safe)
10311027
return result;
10321028
}
10331029

1030+
int
1031+
ruby_require_internal(const char *fname, unsigned int len)
1032+
{
1033+
struct RString fake;
1034+
VALUE str = rb_setup_fake_str(&fake, fname, len, 0);
1035+
return rb_require_internal(str, 0);
1036+
}
1037+
1038+
VALUE
1039+
rb_require_safe(VALUE fname, int safe)
1040+
{
1041+
int result = rb_require_internal(fname, safe);
1042+
1043+
if (result > 0) {
1044+
JUMP_TAG(result);
1045+
}
1046+
if (result < -1) {
1047+
load_failed(fname);
1048+
}
1049+
1050+
return result ? Qfalse : Qtrue;
1051+
}
1052+
10341053
VALUE
10351054
rb_require(const char *fname)
10361055
{

ruby.c

-1
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,6 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
13681368
ruby_gc_set_params(opt->safe_level);
13691369
ruby_init_loadpath_safe(opt->safe_level);
13701370
Init_enc();
1371-
rb_enc_find_index("encdb");
13721371
lenc = rb_locale_encoding();
13731372
rb_enc_associate(rb_progname, lenc);
13741373
rb_obj_freeze(rb_progname);

0 commit comments

Comments
 (0)