mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Split MRB_BINARY_FORMAT to major and minor.
The minor versions should be upper compatible. So mere opcode, section addition can be done without breaking compiled binary.
This commit is contained in:
@@ -49,7 +49,12 @@ MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
|
||||
|
||||
/* Rite Binary File header */
|
||||
#define RITE_BINARY_IDENT "RITE"
|
||||
#define RITE_BINARY_FORMAT_VER "0007"
|
||||
/* Binary Format Version Major:Minor */
|
||||
/* Major: Incompatible to prior versions */
|
||||
/* Minor: Upper-compatible to prior versions */
|
||||
#define RITE_BINARY_MAJOR_VER "01"
|
||||
#define RITE_BINARY_MINOR_VER "00"
|
||||
#define RITE_BINARY_FORMAT_VER RITE_BINARY_MAJOR_VER RITE_BINARY_MINOR_VER
|
||||
#define RITE_COMPILER_NAME "MATZ"
|
||||
#define RITE_COMPILER_VERSION "0000"
|
||||
|
||||
@@ -66,7 +71,8 @@ MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
|
||||
/* binary header */
|
||||
struct rite_binary_header {
|
||||
uint8_t binary_ident[4]; /* Binary Identifier */
|
||||
uint8_t binary_version[4]; /* Binary Format Version */
|
||||
uint8_t major_version[2]; /* Binary Format Major Version */
|
||||
uint8_t minor_version[2]; /* Binary Format Minor Version */
|
||||
uint8_t binary_crc[2]; /* Binary CRC */
|
||||
uint8_t binary_size[4]; /* Binary Size */
|
||||
uint8_t compiler_name[4]; /* Compiler name */
|
||||
|
||||
+2
-1
@@ -726,7 +726,8 @@ write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t *bin, uint8
|
||||
uint32_t offset;
|
||||
|
||||
memcpy(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident));
|
||||
memcpy(header->binary_version, RITE_BINARY_FORMAT_VER, sizeof(header->binary_version));
|
||||
memcpy(header->major_version, RITE_BINARY_MAJOR_VER, sizeof(header->major_version));
|
||||
memcpy(header->minor_version, RITE_BINARY_MAJOR_VER, sizeof(header->minor_version));
|
||||
memcpy(header->compiler_name, RITE_COMPILER_NAME, sizeof(header->compiler_name));
|
||||
memcpy(header->compiler_version, RITE_COMPILER_VERSION, sizeof(header->compiler_version));
|
||||
mrb_assert(binary_size <= UINT32_MAX);
|
||||
|
||||
+6
-1
@@ -525,7 +525,12 @@ read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint16_
|
||||
return MRB_DUMP_INVALID_FILE_HEADER;
|
||||
}
|
||||
|
||||
if (memcmp(header->binary_version, RITE_BINARY_FORMAT_VER, sizeof(header->binary_version)) != 0) {
|
||||
/* if major version is different, they are incompatible */
|
||||
if (memcmp(header->major_version, RITE_BINARY_MAJOR_VER, sizeof(header->major_version)) != 0) {
|
||||
return MRB_DUMP_INVALID_FILE_HEADER;
|
||||
}
|
||||
/* if minor version is different, we can accept the older version */
|
||||
if (memcmp(header->minor_version, RITE_BINARY_MINOR_VER, sizeof(header->minor_version)) <= 0) {
|
||||
return MRB_DUMP_INVALID_FILE_HEADER;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user