aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 13:58:50 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 13:58:50 +0000
commit3dbb390180a0e9f98623b6db0d71b0213359c541 (patch)
treead18953723a41185b127a340386427b3c86d6904 /proc.c
parent8f620b9b17ccbaae1e3eb9a1b9b5d528f4d5f900 (diff)
downloadruby-3dbb390180a0e9f98623b6db0d71b0213359c541.tar.gz
* introduce new ISeq binary format serializer/de-serializer
and a pre-compilation/runtime loader sample. [Feature #11788] * iseq.c: add new methods: * RubyVM::InstructionSequence#to_binary_format(extra_data = nil) * RubyVM::InstructionSequence.from_binary_format(binary) * RubyVM::InstructionSequence.from_binary_format_extra_data(binary) * compile.c: implement body of this new feature. * load.c (rb_load_internal0), iseq.c (rb_iseq_load_iseq): call RubyVM::InstructionSequence.load_iseq(fname) with loading script name if this method is defined. We can return any ISeq object as a result value. Otherwise loading will be continue as usual. This interface is not matured and is not extensible. So that we don't guarantee the future compatibility of this method. Basically, you should'nt use this method. * iseq.h: move ISEQ_MAJOR/MINOR_VERSION (and some definitions) from iseq.c. * encoding.c (rb_data_is_encoding), internal.h: added. * vm_core.h: add several supports for lazy load. * add USE_LAZY_LOAD macro to specify enable or disable of this feature. * add several fields to rb_iseq_t. * introduce new macro rb_iseq_check(). * insns.def: some check for lazy loading feature. * vm_insnhelper.c: ditto. * proc.c: ditto. * vm.c: ditto. * test/lib/iseq_loader_checker.rb: enabled iff suitable environment variables are provided. * test/runner.rb: enable lib/iseq_loader_checker.rb. * sample/iseq_loader.rb: add sample compiler and loader. $ ruby sample/iseq_loader.rb [dir] will compile all ruby scripts in [dir]. With default setting, this compile creates *.rb.yarb files in same directory of target .rb scripts. $ ruby -r sample/iseq_loader.rb [app] will run with enable to load compiled binary data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/proc.c b/proc.c
index c88c676729..c71e62e7ac 100644
--- a/proc.c
+++ b/proc.c
@@ -984,12 +984,15 @@ rb_proc_get_iseq(VALUE self, int *is_proc)
iseq = rb_method_iseq((VALUE)ifunc->data);
if (is_proc) *is_proc = 0;
}
+ return iseq;
}
else if (SYMBOL_P(iseq)) {
self = rb_sym_to_proc((VALUE)iseq);
goto again;
}
- return iseq;
+ else {
+ return rb_iseq_check(iseq);
+ }
}
static VALUE
@@ -998,6 +1001,7 @@ iseq_location(const rb_iseq_t *iseq)
VALUE loc[2];
if (!iseq) return Qnil;
+ rb_iseq_check(iseq);
loc[0] = iseq->body->location.path;
if (iseq->body->line_info_table) {
loc[1] = rb_iseq_first_lineno(iseq);
@@ -1142,7 +1146,7 @@ proc_to_s(VALUE self)
iseq = proc->block.iseq;
is_lambda = proc->is_lambda ? " (lambda)" : "";
- if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
+ if (RUBY_VM_NORMAL_ISEQ_P(iseq) && rb_iseq_check(iseq)) {
int first_lineno = 0;
if (iseq->body->line_info_table) {
@@ -2152,7 +2156,7 @@ rb_method_entry_min_max_arity(const rb_method_entry_t *me, int *max)
case VM_METHOD_TYPE_BMETHOD:
return rb_proc_min_max_arity(def->body.proc, max);
case VM_METHOD_TYPE_ISEQ: {
- const rb_iseq_t *iseq = def->body.iseq.iseqptr;
+ const rb_iseq_t *iseq = rb_iseq_check(def->body.iseq.iseqptr);
return rb_iseq_min_max_arity(iseq, max);
}
case VM_METHOD_TYPE_UNDEF:
@@ -2289,7 +2293,7 @@ method_def_iseq(const rb_method_definition_t *def)
{
switch (def->type) {
case VM_METHOD_TYPE_ISEQ:
- return def->body.iseq.iseqptr;
+ return rb_iseq_check(def->body.iseq.iseqptr);
case VM_METHOD_TYPE_BMETHOD:
return get_proc_iseq(def->body.proc, 0);
case VM_METHOD_TYPE_ALIAS:
@@ -2654,6 +2658,7 @@ proc_binding(VALUE self)
bind->env = envval;
if (iseq) {
+ rb_iseq_check(iseq);
bind->path = iseq->body->location.path;
bind->first_lineno = FIX2INT(rb_iseq_first_lineno(iseq));
}