Skip to content

Commit 2e216b5

Browse files
committed
Merge pull request #106552 from nikitalita/bytecode-version-bump
Bump script bytecode version after token enum change
2 parents f0d11e4 + 6909309 commit 2e216b5

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

modules/gdscript/gdscript_tokenizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class GDScriptTokenizer {
4545
};
4646

4747
struct Token {
48+
// If this enum changes, please increment the TOKENIZER_VERSION in gdscript_tokenizer_buffer.h
4849
enum Type {
4950
EMPTY,
5051
// Basic

modules/gdscript/gdscript_tokenizer_buffer.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include "core/io/compression.h"
3434
#include "core/io/marshalls.h"
3535

36-
#define TOKENIZER_VERSION 100
37-
3836
int GDScriptTokenizerBuffer::_token_to_binary(const Token &p_token, Vector<uint8_t> &r_buffer, int p_start, HashMap<StringName, uint32_t> &r_identifiers_map, HashMap<Variant, uint32_t, VariantHasher, VariantComparator> &r_constants_map) {
3937
int pos = p_start;
4038

@@ -143,7 +141,7 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer)
143141
ERR_FAIL_COND_V(p_buffer.size() < 12 || p_buffer[0] != 'G' || p_buffer[1] != 'D' || p_buffer[2] != 'S' || p_buffer[3] != 'C', ERR_INVALID_DATA);
144142

145143
int version = decode_uint32(&buf[4]);
146-
ERR_FAIL_COND_V_MSG(version > TOKENIZER_VERSION, ERR_INVALID_DATA, "Binary GDScript is too recent! Please use a newer engine version.");
144+
ERR_FAIL_COND_V_MSG(version != TOKENIZER_VERSION, ERR_INVALID_DATA, "Binary GDScript is not compatible with this engine version.");
147145

148146
int decompressed_size = decode_uint32(&buf[8]);
149147

@@ -161,10 +159,10 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer)
161159
uint32_t identifier_count = decode_uint32(&buf[0]);
162160
uint32_t constant_count = decode_uint32(&buf[4]);
163161
uint32_t token_line_count = decode_uint32(&buf[8]);
164-
uint32_t token_count = decode_uint32(&buf[16]);
162+
uint32_t token_count = decode_uint32(&buf[12]);
165163

166-
const uint8_t *b = &buf[20];
167-
total_len -= 20;
164+
const uint8_t *b = &buf[16];
165+
total_len -= 16;
168166

169167
identifiers.resize(identifier_count);
170168
for (uint32_t i = 0; i < identifier_count; i++) {
@@ -292,14 +290,13 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code,
292290
}
293291

294292
Vector<uint8_t> contents;
295-
contents.resize(20);
293+
contents.resize(16);
296294
encode_uint32(identifier_map.size(), &contents.write[0]);
297295
encode_uint32(constant_map.size(), &contents.write[4]);
298296
encode_uint32(token_lines.size(), &contents.write[8]);
299-
encode_uint32(0, &contents.write[12]); // Unused, kept for compatibility. Please remove at next `TOKENIZER_VERSION` increment.
300-
encode_uint32(token_counter, &contents.write[16]);
297+
encode_uint32(token_counter, &contents.write[12]);
301298

302-
int buf_pos = 20;
299+
int buf_pos = 16;
303300

304301
// Save identifiers.
305302
for (const StringName &id : rev_identifier_map) {

modules/gdscript/gdscript_tokenizer_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class GDScriptTokenizerBuffer : public GDScriptTokenizer {
3939
COMPRESS_ZSTD,
4040
};
4141

42+
static constexpr uint32_t TOKENIZER_VERSION = 101;
4243
static constexpr uint32_t TOKEN_BYTE_MASK = 0x80;
4344
static constexpr uint32_t TOKEN_BITS = 8;
4445
static constexpr uint32_t TOKEN_MASK = (1 << (TOKEN_BITS - 1)) - 1;

0 commit comments

Comments
 (0)