mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
load.c: defer initalization of static-linked-ext
* load.c (rb_feature_p): deal with default loadable suffixes. * load.c (load_lock): initialize statically linked extensions. * load.c (search_required, rb_require_safe): deal with statically linked extensions. * load.c (ruby_init_ext): defer initalization of statically linked extensions until required actually. [Bug #8883] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3c8072937c
commit
86ffd21c39
2 changed files with 59 additions and 16 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
Sun Nov 3 09:35:47 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* load.c (rb_feature_p): deal with default loadable suffixes.
|
||||||
|
|
||||||
|
* load.c (load_lock): initialize statically linked extensions.
|
||||||
|
|
||||||
|
* load.c (search_required, rb_require_safe): deal with statically
|
||||||
|
linked extensions.
|
||||||
|
|
||||||
|
* load.c (ruby_init_ext): defer initalization of statically linked
|
||||||
|
extensions until required actually. [Bug #8883]
|
||||||
|
|
||||||
Sat Nov 2 15:14:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Nov 2 15:14:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/logger.rb (Logger::LogDevice::LogDeviceMutex#lock_shift_log):
|
* lib/logger.rb (Logger::LogDevice::LogDeviceMutex#lock_shift_log):
|
||||||
|
|
63
load.c
63
load.c
|
@ -8,6 +8,7 @@
|
||||||
#include "dln.h"
|
#include "dln.h"
|
||||||
#include "eval_intern.h"
|
#include "eval_intern.h"
|
||||||
#include "probes.h"
|
#include "probes.h"
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
VALUE ruby_dln_librefs;
|
VALUE ruby_dln_librefs;
|
||||||
|
|
||||||
|
@ -482,6 +483,9 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c
|
||||||
else {
|
else {
|
||||||
VALUE bufstr;
|
VALUE bufstr;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
static const char so_ext[][4] = {
|
||||||
|
".so", ".o",
|
||||||
|
};
|
||||||
|
|
||||||
if (ext && *ext) return 0;
|
if (ext && *ext) return 0;
|
||||||
bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
|
bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
|
||||||
|
@ -495,6 +499,14 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c
|
||||||
return i ? 's' : 'r';
|
return i ? 's' : 'r';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (i = 0; i < numberof(so_ext); i++) {
|
||||||
|
strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
|
||||||
|
if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
|
||||||
|
rb_str_resize(bufstr, 0);
|
||||||
|
if (fn) *fn = (const char*)data;
|
||||||
|
return 's';
|
||||||
|
}
|
||||||
|
}
|
||||||
rb_str_resize(bufstr, 0);
|
rb_str_resize(bufstr, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -709,6 +721,14 @@ load_lock(const char *ftptr)
|
||||||
st_insert(loading_tbl, (st_data_t)ftptr, data);
|
st_insert(loading_tbl, (st_data_t)ftptr, data);
|
||||||
return (char *)ftptr;
|
return (char *)ftptr;
|
||||||
}
|
}
|
||||||
|
else if (RB_TYPE_P((VALUE)data, T_NODE) && nd_type((VALUE)data) == NODE_MEMO) {
|
||||||
|
NODE *memo = RNODE(data);
|
||||||
|
void (*init)(void) = (void (*)(void))memo->nd_cfnc;
|
||||||
|
data = (st_data_t)rb_thread_shield_new();
|
||||||
|
st_insert(loading_tbl, (st_data_t)ftptr, data);
|
||||||
|
(*init)();
|
||||||
|
return (char *)"";
|
||||||
|
}
|
||||||
if (RTEST(ruby_verbose)) {
|
if (RTEST(ruby_verbose)) {
|
||||||
rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
|
rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
|
||||||
rb_backtrace_print_to(rb_stderr);
|
rb_backtrace_print_to(rb_stderr);
|
||||||
|
@ -881,13 +901,16 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0:
|
case 0:
|
||||||
if (ft)
|
if (ft)
|
||||||
break;
|
goto statically_linked;
|
||||||
ftptr = RSTRING_PTR(tmp);
|
ftptr = RSTRING_PTR(tmp);
|
||||||
return rb_feature_p(ftptr, 0, FALSE, TRUE, 0);
|
return rb_feature_p(ftptr, 0, FALSE, TRUE, 0);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (ft)
|
if (ft) {
|
||||||
break;
|
statically_linked:
|
||||||
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
||||||
|
return ft;
|
||||||
|
}
|
||||||
case 1:
|
case 1:
|
||||||
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
||||||
if (rb_feature_p(ftptr, ext, !--type, TRUE, &loading) && !loading)
|
if (rb_feature_p(ftptr, ext, !--type, TRUE, &loading) && !loading)
|
||||||
|
@ -957,6 +980,10 @@ rb_require_safe(VALUE fname, int safe)
|
||||||
if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) {
|
if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) {
|
||||||
result = Qfalse;
|
result = Qfalse;
|
||||||
}
|
}
|
||||||
|
else if (!*ftptr) {
|
||||||
|
rb_provide_feature(path);
|
||||||
|
result = Qtrue;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
switch (found) {
|
switch (found) {
|
||||||
case 'r':
|
case 'r':
|
||||||
|
@ -1005,26 +1032,30 @@ rb_require(const char *fname)
|
||||||
return rb_require_safe(fn, rb_safe_level());
|
return rb_require_safe(fn, rb_safe_level());
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static int
|
||||||
init_ext_call(VALUE arg)
|
register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing)
|
||||||
{
|
{
|
||||||
SCOPE_SET(NOEX_PUBLIC);
|
const char *name = (char *)*key;
|
||||||
(*(void (*)(void))arg)();
|
if (existing) {
|
||||||
return Qnil;
|
/* already registered */
|
||||||
|
rb_warn("%s is already registered", name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*value = (st_data_t)NEW_MEMO(init, 0, 0);
|
||||||
|
*key = (st_data_t)ruby_strdup(name);
|
||||||
|
}
|
||||||
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUBY_FUNC_EXPORTED void
|
RUBY_FUNC_EXPORTED void
|
||||||
ruby_init_ext(const char *name, void (*init)(void))
|
ruby_init_ext(const char *name, void (*init)(void))
|
||||||
{
|
{
|
||||||
char* const lock_key = load_lock(name);
|
st_table *loading_tbl = get_loading_table();
|
||||||
if (lock_key) {
|
|
||||||
VALUE feature = rb_usascii_str_new_cstr(name);
|
if (!loading_tbl) {
|
||||||
OBJ_FREEZE(feature);
|
GET_VM()->loading_table = loading_tbl = st_init_strtable();
|
||||||
rb_vm_call_cfunc(rb_vm_top_self(), init_ext_call, (VALUE)init,
|
|
||||||
0, feature);
|
|
||||||
rb_provide_feature(feature);
|
|
||||||
load_unlock(lock_key, 1);
|
|
||||||
}
|
}
|
||||||
|
st_update(loading_tbl, (st_data_t)name, register_init_ext, (st_data_t)init);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue