Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit b6856e6

Browse files
committed
[[ Bug 17690 ]] Add new stack file version 8.1 and make default
[[ Bug 17690 ]] Change block index / size values in 8.1 format to uint32, add check to MCBlock::getminimumstackfileversion() to test if 8.1 format is needed.
1 parent 3e9827d commit b6856e6

File tree

4 files changed

+74
-12
lines changed

4 files changed

+74
-12
lines changed

engine/src/MCBlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class MCBlock : public MCDLlist
8585
// MCBlock functions
8686
void copy(MCBlock *bptr);
8787

88+
// IM-2016-07-06: [[ Bug 17690 ]] Test if block sizes or offsets require 32bit
89+
// values to store (stack file format v8.1).
8890
uint32_t getminimumstackfileversion(void);
8991

9092
// MW-2012-03-04: [[ StackFile5500 ]] If 'is_ext' is true then this block has

engine/src/block.cpp

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,23 @@ bool MCBlock::visit(MCObjectVisitorOptions p_options, uint32_t p_part, MCObjectV
145145
return p_visitor -> OnBlock(this);
146146
}
147147

148+
// IM-2016-07-06: [[ Bug 17690 ]] Test if block sizes or offsets require 32bit
149+
// values to store (stack file format v8.1).
148150
uint32_t MCBlock::getminimumstackfileversion(void)
149151
{
152+
bool t_is_unicode;
153+
// paragraph text is always unicode when saving as version 7.0 or greater.
154+
// since we can't know which version will be used at this point, the
155+
// best we can do is assume unicode text.
156+
/* t_is_unicode = !MCStringIsNative(parent->GetInternalStringRef()); */
157+
t_is_unicode = true;
158+
159+
uint32_t t_index_size;
160+
t_index_size = t_is_unicode ? sizeof(unichar_t) : sizeof(char_t);
161+
162+
if (m_index * t_index_size > UINT16_MAX || m_size * t_index_size > UINT16_MAX)
163+
return kMCStackFileFormatVersion_8_1;
164+
else
150165
return kMCStackFileFormatMinimumExportVersion;
151166
}
152167

@@ -310,13 +325,33 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
310325
//
311326
// Helpfully, the paragraph loading code makes a SetRanges call to inform
312327
// the block of the correct offsets as soon as it knows them.
313-
uint2 index, size;
314-
if ((stat = IO_read_uint2(&index, stream)) != IO_NORMAL)
315-
return checkloadstat(stat);
316-
if ((stat = IO_read_uint2(&size, stream)) != IO_NORMAL)
317-
return checkloadstat(stat);
318-
m_index = index;
319-
m_size = size;
328+
329+
// IM-2016-07-11: [[ Bug 17690 ]] change storage format for index & size from
330+
// 16bit to 32bit in stack file format v8.1.
331+
if (version >= kMCStackFileFormatVersion_8_1)
332+
{
333+
uint32_t t_index, t_size;
334+
stat = IO_read_uint4(&t_index, stream);
335+
if (stat != IO_NORMAL)
336+
return checkloadstat(stat);
337+
338+
stat = IO_read_uint4(&t_size, stream);
339+
if (stat != IO_NORMAL)
340+
return checkloadstat(stat);
341+
342+
m_index = t_index;
343+
m_size = t_size;
344+
}
345+
else
346+
{
347+
uint2 index, size;
348+
if ((stat = IO_read_uint2(&index, stream)) != IO_NORMAL)
349+
return checkloadstat(stat);
350+
if ((stat = IO_read_uint2(&size, stream)) != IO_NORMAL)
351+
return checkloadstat(stat);
352+
m_index = index;
353+
m_size = size;
354+
}
320355

321356
// MW-2012-02-17: [[ SplitTextAttrs ]] Adjust the flags to their in-memory
322357
// representation. We ditch F_FONT because it is superceeded by the HAS_F*
@@ -465,10 +500,25 @@ IO_stat MCBlock::save(IO_handle stream, uint4 p_part, uint32_t p_version)
465500
uint32_t t_index_size;
466501
t_index_size = t_is_unicode ? sizeof(unichar_t) : sizeof(char_t);
467502

468-
if ((stat = IO_write_uint2(m_index * t_index_size, stream)) != IO_NORMAL)
469-
return stat;
470-
if ((stat = IO_write_uint2(m_size * t_index_size, stream)) != IO_NORMAL)
471-
return stat;
503+
// IM-2016-07-11: [[ Bug 17690 ]] change storage format for index & size from
504+
// 16bit to 32bit in stack file format v8.1.
505+
if (p_version >= kMCStackFileFormatVersion_8_1)
506+
{
507+
stat = IO_write_uint4(m_index * t_index_size, stream);
508+
if (stat != IO_NORMAL)
509+
return checkloadstat(stat);
510+
511+
stat = IO_write_uint4(m_size * t_index_size, stream);
512+
if (stat != IO_NORMAL)
513+
return checkloadstat(stat);
514+
}
515+
else
516+
{
517+
if ((stat = IO_write_uint2(m_index * t_index_size, stream)) != IO_NORMAL)
518+
return stat;
519+
if ((stat = IO_write_uint2(m_size * t_index_size, stream)) != IO_NORMAL)
520+
return stat;
521+
}
472522

473523
return IO_NORMAL;
474524
}

engine/src/stackfileformat.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ bool MCStackFileParseVersionNumber(const char *p_buffer, uint32_t &r_version)
6363
// map the version to one of the supported stack file versions
6464
uint32_t MCStackFileMapToSupportedVersion(uint32_t p_version)
6565
{
66+
if (p_version >= kMCStackFileFormatVersion_8_1)
67+
return kMCStackFileFormatVersion_8_1;
68+
6669
if (p_version >= kMCStackFileFormatVersion_8_0)
6770
return kMCStackFileFormatVersion_8_0;
6871

@@ -82,6 +85,11 @@ void MCStackFileGetHeaderForVersion(uint32_t p_version, const char *&r_header, u
8285
{
8386
switch (MCStackFileMapToSupportedVersion(p_version))
8487
{
88+
case kMCStackFileFormatVersion_8_1:
89+
r_header = kMCStackFileVersionString_8_1;
90+
r_size = kMCStackFileVersionStringLength;
91+
break;
92+
8593
case kMCStackFileFormatVersion_8_0:
8694
r_header = kMCStackFileVersionString_8_0;
8795
r_size = kMCStackFileVersionStringLength;

engine/src/stackfileformat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
#define kMCStackFileFormatVersion_5_5 (5500)
2828
#define kMCStackFileFormatVersion_7_0 (7000)
2929
#define kMCStackFileFormatVersion_8_0 (8000)
30+
#define kMCStackFileFormatVersion_8_1 (8100)
3031

3132
#define kMCStackFileFormatMinimumExportVersion kMCStackFileFormatVersion_2_4
32-
#define kMCStackFileFormatCurrentVersion kMCStackFileFormatVersion_8_0
33+
#define kMCStackFileFormatCurrentVersion kMCStackFileFormatVersion_8_1
3334

3435

3536
#define kMCStackFileVersionStringPrefix "REVO"
@@ -39,6 +40,7 @@
3940
#define kMCStackFileVersionString_5_5 "REVO5500"
4041
#define kMCStackFileVersionString_7_0 "REVO7000"
4142
#define kMCStackFileVersionString_8_0 "REVO8000"
43+
#define kMCStackFileVersionString_8_1 "REVO8100"
4244
#define kMCStackFileVersionStringLength 8
4345

4446
#define kMCStackFileMetaCardVersionString "#!/bin/sh\n# MetaCard 2.4 stack\n# The following is not ASCII text,\n# so now would be a good time to q out of more\f\nexec mc $0 \"$@\"\n"

0 commit comments

Comments
 (0)