summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-09-13 16:24:28 +0900
committerKoichi Sasada <ko1@atdot.net>2019-09-13 16:24:28 +0900
commit2da6b328bb5124793a6420c55325f3106b615bb4 (patch)
treedd1b501070f0bce777b74f3259e04a405c5ef3de
parent3c162df9d4a80bc09d88eeb36db7d59ea0034b1d (diff)
introduce IBF_(MAJOR|MINOR)_VERSION.
RubyVM::InstructionSequence.to_binary generates a bytecode binary representation. To check compatibility with binary and loading MRI we prepared major/minor version and compare them at loading time. However, development version of MRI can change this format but we can not increment minor version to make them consistent with Ruby's major/minor versions. To solve this issue, we introduce new minor version scheme (binary's minor_version = ruby's minor * 10000 + dev ver) and we can check incompatibility with older dev version.
-rw-r--r--compile.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/compile.c b/compile.c
index 9e952e4591..e1cd82c788 100644
--- a/compile.c
+++ b/compile.c
@@ -9184,6 +9184,14 @@ rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func)
typedef unsigned int ibf_offset_t;
#define IBF_OFFSET(ptr) ((ibf_offset_t)(VALUE)(ptr))
+#define IBF_MAJOR_VERSION ISEQ_MAJOR_VERSION
+#if RUBY_DEVEL
+#define IBF_DEVEL_VERSION 0
+#define IBF_MINOR_VERSION (ISEQ_MINOR_VERSION * 10000 + IBF_DEVEL_VERSION)
+#else
+#define IBF_MINOR_VERSION ISEQ_MINOR_VERSION
+#endif
+
struct ibf_header {
char magic[4]; /* YARB */
unsigned int major_version;
@@ -10666,8 +10674,8 @@ rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
header.magic[1] = 'A';
header.magic[2] = 'R';
header.magic[3] = 'B';
- header.major_version = ISEQ_MAJOR_VERSION;
- header.minor_version = ISEQ_MINOR_VERSION;
+ header.major_version = IBF_MAJOR_VERSION;
+ header.minor_version = IBF_MINOR_VERSION;
ibf_dump_iseq_list(dump, &header);
ibf_dump_id_list(dump, &header);
ibf_dump_object_list(dump, &header);
@@ -10804,10 +10812,10 @@ ibf_load_setup(struct ibf_load *load, VALUE loader_obj, VALUE str)
if (strncmp(load->header->magic, "YARB", 4) != 0) {
rb_raise(rb_eRuntimeError, "unknown binary format");
}
- if (load->header->major_version != ISEQ_MAJOR_VERSION ||
- load->header->minor_version != ISEQ_MINOR_VERSION) {
+ if (load->header->major_version != IBF_MAJOR_VERSION ||
+ load->header->minor_version != IBF_MINOR_VERSION) {
rb_raise(rb_eRuntimeError, "unmatched version file (%u.%u for %u.%u)",
- load->header->major_version, load->header->minor_version, ISEQ_MAJOR_VERSION, ISEQ_MINOR_VERSION);
+ load->header->major_version, load->header->minor_version, IBF_MAJOR_VERSION, IBF_MINOR_VERSION);
}
if (strcmp(load->buff + sizeof(struct ibf_header), RUBY_PLATFORM) != 0) {
rb_raise(rb_eRuntimeError, "unmatched platform");