* iseq.c: rename methods

RubyVM::InstructionSequence#to_binary_format -> #to_binary
  RubyVM::InstructionSequence.from_binary_format -> .load_from_binary
  RubyVM::InstructionSequence.from_binary_format_extra_data ->
                             .load_from_binary_extra_data

* iseq.c: fix document of iseq.to_binary.
  [Fix GH-1134]

* sample/iseq_loader.rb: catch up this change.

* test/lib/iseq_loader_checker.rb: ditto.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-12-09 15:10:57 +00:00
parent 98b75d59b9
commit 4b8da4b9c8
4 changed files with 35 additions and 20 deletions

View File

@ -1,3 +1,18 @@
Thu Dec 10 00:06:56 2015 Koichi Sasada <ko1@atdot.net>
* iseq.c: rename methods
RubyVM::InstructionSequence#to_binary_format -> #to_binary
RubyVM::InstructionSequence.from_binary_format -> .load_from_binary
RubyVM::InstructionSequence.from_binary_format_extra_data ->
.load_from_binary_extra_data
* iseq.c: fix document of iseq.to_binary.
[Fix GH-1134]
* sample/iseq_loader.rb: catch up this change.
* test/lib/iseq_loader_checker.rb: ditto.
Wed Dec 9 17:02:03 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Dec 9 17:02:03 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* regparse.h (SET_NTYPE): get rid of breaking strict aliasing. * regparse.h (SET_NTYPE): get rid of breaking strict aliasing.

26
iseq.c
View File

@ -2334,23 +2334,23 @@ rb_iseqw_local_variables(VALUE iseqval)
/* /*
* call-seq: * call-seq:
* iseq.to_binary_format(extra_data = nil) -> binary str * iseq.to_binary(extra_data = nil) -> binary str
* *
* Returns serialized iseq binary format data as a String object. * Returns serialized iseq binary format data as a String object.
* A correspnding iseq object is created by * A correspnding iseq object is created by
* RubyVM::InstructionSequence.from_binary_format() method. * RubyVM::InstructionSequence.load_from_binary() method.
* *
* String extra_data will be saved with binary data. * String extra_data will be saved with binary data.
* You can access this data with * You can access this data with
* RubyVM::InstructionSequence.from_binary_format_extra_data(binary). * RubyVM::InstructionSequence.load_from_binary_extra_data(binary).
* *
* Note that the translated binary data is not portable. * Note that the translated binary data is not portable.
* You can not move this binary data to another machine. * You can not move this binary data to another machine.
* You can not use the binary data whcih is created by another * You can not use the binary data which is created by another
* version/another architecture of Ruby. * version/another architecture of Ruby.
*/ */
static VALUE static VALUE
iseqw_to_binary_format(int argc, VALUE *argv, VALUE self) iseqw_to_binary(int argc, VALUE *argv, VALUE self)
{ {
VALUE opt; VALUE opt;
rb_scan_args(argc, argv, "01", &opt); rb_scan_args(argc, argv, "01", &opt);
@ -2359,10 +2359,10 @@ iseqw_to_binary_format(int argc, VALUE *argv, VALUE self)
/* /*
* call-seq: * call-seq:
* RubyVM::InstructionSequence.from_binary_format(binary) -> iseq * RubyVM::InstructionSequence.load_from_binary(binary) -> iseq
* *
* Load an iseq object from binary format String object * Load an iseq object from binary format String object
* created by RubyVM::InstructionSequence.to_binary_format. * created by RubyVM::InstructionSequence.to_binary.
* *
* This loader does not have a verifier, so that loading broken/modified * This loader does not have a verifier, so that loading broken/modified
* binary causes critical problem. * binary causes critical problem.
@ -2371,19 +2371,19 @@ iseqw_to_binary_format(int argc, VALUE *argv, VALUE self)
* You should use binary data translated by yourself. * You should use binary data translated by yourself.
*/ */
static VALUE static VALUE
iseqw_s_from_binary_format(VALUE self, VALUE str) iseqw_s_load_from_binary(VALUE self, VALUE str)
{ {
return iseqw_new(iseq_ibf_load(str)); return iseqw_new(iseq_ibf_load(str));
} }
/* /*
* call-seq: * call-seq:
* RubyVM::InstructionSequence.from_binary_format_extra_data(binary) -> str * RubyVM::InstructionSequence.load_from_binary_extra_data(binary) -> str
* *
* Load extra data embed into binary format String object. * Load extra data embed into binary format String object.
*/ */
static VALUE static VALUE
iseqw_s_from_binary_format_extra_data(VALUE self, VALUE str) iseqw_s_load_from_binary_extra_data(VALUE self, VALUE str)
{ {
return iseq_ibf_load_extra_data(str); return iseq_ibf_load_extra_data(str);
} }
@ -2419,9 +2419,9 @@ Init_ISeq(void)
rb_define_method(rb_cISeq, "to_a", iseqw_to_a, 0); rb_define_method(rb_cISeq, "to_a", iseqw_to_a, 0);
rb_define_method(rb_cISeq, "eval", iseqw_eval, 0); rb_define_method(rb_cISeq, "eval", iseqw_eval, 0);
rb_define_method(rb_cISeq, "to_binary_format", iseqw_to_binary_format, -1); rb_define_method(rb_cISeq, "to_binary", iseqw_to_binary, -1);
rb_define_singleton_method(rb_cISeq, "from_binary_format", iseqw_s_from_binary_format, 1); rb_define_singleton_method(rb_cISeq, "load_from_binary", iseqw_s_load_from_binary, 1);
rb_define_singleton_method(rb_cISeq, "from_binary_format_extra_data", iseqw_s_from_binary_format_extra_data, 1); rb_define_singleton_method(rb_cISeq, "load_from_binary_extra_data", iseqw_s_load_from_binary_extra_data, 1);
/* location APIs */ /* location APIs */

View File

@ -70,9 +70,9 @@ class RubyVM::InstructionSequence
$ISEQ_LOADER_LOADED += 1 $ISEQ_LOADER_LOADED += 1
STDERR.puts "[ISEQ_LOADER] #{Process.pid} load #{fname} from #{iseq_key}" if COMPILE_DEBUG STDERR.puts "[ISEQ_LOADER] #{Process.pid} load #{fname} from #{iseq_key}" if COMPILE_DEBUG
binary = read_compiled_iseq(fname, iseq_key) binary = read_compiled_iseq(fname, iseq_key)
iseq = RubyVM::InstructionSequence.from_binary_format(binary) iseq = RubyVM::InstructionSequence.load_from_binary(binary)
# p [extra_data(iseq.path), RubyVM::InstructionSequence.from_binary_format_extra_data(binary)] # p [extra_data(iseq.path), RubyVM::InstructionSequence.load_from_binary_extra_data(binary)]
# raise unless extra_data(iseq.path) == RubyVM::InstructionSequence.from_binary_format_extra_data(binary) # raise unless extra_data(iseq.path) == RubyVM::InstructionSequence.load_from_binary_extra_data(binary)
iseq iseq
elsif COMPILE_IF_NOT_COMPILED elsif COMPILE_IF_NOT_COMPILED
compile_and_save_iseq(fname, iseq_key) compile_and_save_iseq(fname, iseq_key)
@ -92,7 +92,7 @@ class RubyVM::InstructionSequence
STDERR.puts "[RUBY_COMPILED_FILE] compile #{fname}" if COMPILE_DEBUG STDERR.puts "[RUBY_COMPILED_FILE] compile #{fname}" if COMPILE_DEBUG
iseq = RubyVM::InstructionSequence.compile_file(fname) iseq = RubyVM::InstructionSequence.compile_file(fname)
binary = iseq.to_binary_format(extra_data(fname)) binary = iseq.to_binary(extra_data(fname))
write_compiled_iseq(fname, iseq_key, binary) write_compiled_iseq(fname, iseq_key, binary)
iseq iseq
end end

View File

@ -51,18 +51,18 @@ class RubyVM::InstructionSequence
RubyVM::InstructionSequence.iseq_load(ary) RubyVM::InstructionSequence.iseq_load(ary)
}) if CHECK_TO_A && defined?(RubyVM::InstructionSequence.iseq_load) }) if CHECK_TO_A && defined?(RubyVM::InstructionSequence.iseq_load)
# check to_binary_format # check to_binary
i2_bin = compare_dump_and_load(i1, i2_bin = compare_dump_and_load(i1,
proc{|iseq| proc{|iseq|
begin begin
iseq.to_binary_format iseq.to_binary
rescue RuntimeError => e # not a toplevel rescue RuntimeError => e # not a toplevel
# STDERR.puts [:failed, e, iseq].inspect # STDERR.puts [:failed, e, iseq].inspect
nil nil
end end
}, },
proc{|bin| proc{|bin|
iseq = RubyVM::InstructionSequence.from_binary_format(bin) iseq = RubyVM::InstructionSequence.load_from_binary(bin)
# STDERR.puts iseq.inspect # STDERR.puts iseq.inspect
iseq iseq
}) if CHECK_TO_BINARY }) if CHECK_TO_BINARY