Skip to content

Commit 7eefdd4

Browse files
author
runrevali
committed
[[ RefactorSyntax ]] Fixes for standalone building
1 parent aad7820 commit 7eefdd4

File tree

12 files changed

+91
-23
lines changed

12 files changed

+91
-23
lines changed

engine/src/deploy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bool MCDeployParameters::InitWithArray(MCExecContext &ctxt, MCArrayRef p_array)
128128
MCValueAssign(externals, t_temp_array);
129129
MCValueRelease(t_temp_array);
130130

131-
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("startup_script"), false, startup_script))
131+
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("startup_script"), false, t_temp_string))
132132
return false;
133133
MCValueAssign(startup_script, t_temp_string);
134134
MCValueRelease(t_temp_string);
@@ -215,7 +215,7 @@ bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_
215215
// Open the spill file, if required
216216
MCDeployFileRef t_spill;
217217
t_spill = NULL;
218-
if (t_success && !MCStringIsEmpty(p_params . spill) && !MCDeployFileOpen(p_params . spill, kMCSOpenFileModeWrite, t_spill))
218+
if (t_success && !MCStringIsEmpty(p_params . spill) && !MCDeployFileOpen(p_params . spill, kMCSOpenFileModeCreate, t_spill))
219219
t_success = MCDeployThrow(kMCDeployErrorNoSpill);
220220

221221
// First create our deployment capsule
@@ -320,7 +320,7 @@ bool MCDeployWriteProject(const MCDeployParameters& p_params, bool p_to_network,
320320
{
321321
uint32_t t_swapped_size;
322322
t_swapped_size = t_project_size;
323-
if (p_params . spill != NULL)
323+
if (!MCStringIsEmpty(p_params . spill))
324324
t_swapped_size |= 1U << 31;
325325
MCDeployByteSwap32(p_to_network, t_swapped_size);
326326
t_success = MCDeployFileWriteAt(p_output, &t_swapped_size, sizeof(uint32_t), p_output_offset);

engine/src/deploy_file.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ bool MCDeployFileOpen(MCStringRef p_path, intenum_t p_mode, MCDeployFileRef& r_f
125125

126126
if (MCStringIsEmpty(p_path))
127127
return false;
128-
129-
IO_handle t_handle = MCS_open(p_path, p_mode, false, false, 0);
128+
129+
IO_handle t_handle ;
130+
if (p_mode == kMCSOpenFileModeCreate)
131+
t_handle = MCS_deploy_open(p_path, p_mode);
132+
else
133+
t_handle = MCS_open(p_path, p_mode, false, false, 0);
130134

131135
t_success = (t_handle != nil);
132136

@@ -175,15 +179,18 @@ bool MCDeployFileCopy(MCDeployFileRef p_dst, uint32_t p_at, MCDeployFileRef p_sr
175179
{
176180
if (MCS_seek_set(p_src, p_from) != IO_NORMAL)
177181
return MCDeployThrow(kMCDeployErrorBadRead);
178-
182+
183+
if (MCS_seek_set(p_dst, p_at) != IO_NORMAL)
184+
return MCDeployThrow(kMCDeployErrorBadWrite);
185+
179186
while(p_amount > 0)
180187
{
181188
char t_buffer[4096];
182189
uint32_t t_size;
183190
t_size = MCU_min(4096U, p_amount);
184191
if (MCS_readfixed(t_buffer, t_size, p_src) != IO_NORMAL)
185192
return MCDeployThrow(kMCDeployErrorBadRead);
186-
if (MCS_writeat(t_buffer, t_size, p_at, p_dst) != IO_NORMAL)
193+
if (MCS_write(t_buffer, t_size, 1, p_dst) != IO_NORMAL)
187194
return MCDeployThrow(kMCDeployErrorBadWrite);
188195
p_amount -= t_size;
189196
}
@@ -193,9 +200,12 @@ bool MCDeployFileCopy(MCDeployFileRef p_dst, uint32_t p_at, MCDeployFileRef p_sr
193200

194201
bool MCDeployFileWriteAt(MCDeployFileRef p_dst, const void *p_buffer, uint32_t p_size, uint32_t p_at)
195202
{
196-
if (MCS_writeat(p_buffer, p_size, p_at, p_dst) != IO_NORMAL)
203+
if (MCS_seek_set(p_dst, p_at) != IO_NORMAL)
197204
return MCDeployThrow(kMCDeployErrorBadWrite);
198-
205+
206+
if (MCS_write(p_buffer, p_size, 1, p_dst) != IO_NORMAL)
207+
return MCDeployThrow(kMCDeployErrorBadWrite);
208+
199209
return true;
200210
}
201211

engine/src/deploy_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ Exec_stat MCDeployToELF(const MCDeployParameters& p_params, bool p_is_android)
661661
t_engine = t_output = NULL;
662662
if (t_success && !MCDeployFileOpen(p_params . engine, kMCSOpenFileModeRead, t_engine))
663663
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
664-
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeWrite, t_output))
664+
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeCreate, t_output))
665665
t_success = MCDeployThrow(kMCDeployErrorNoOutput);
666666

667667
// Now read in the main ELF header

engine/src/deploy_macosx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ Exec_stat MCDeployToMacOSX(const MCDeployParameters& p_params)
16901690
(!MCStringIsEmpty(p_params . engine_x86) && !MCDeployFileOpen(p_params . engine_x86, kMCSOpenFileModeRead, t_engine_x86))))
16911691
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
16921692

1693-
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeWrite, t_output))
1693+
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeCreate, t_output))
16941694
t_success = MCDeployThrow(kMCDeployErrorNoOutput);
16951695

16961696
// MW-2013-06-13: If we have a single engine, process that in the appropriate

engine/src/dispatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ IO_stat MCDispatch::loadfile(MCStringRef p_name, MCStack *&sptr)
843843
{
844844

845845
MCAutoStringRef t_homename;
846-
if (MCS_getenv(MCSTR("HOME"), &t_homename))
846+
if (MCS_getenv(MCSTR("HOME"), &t_homename) && !MCStringIsEmpty(*t_homename))
847847
{
848848
MCAutoStringRef t_trimmed_homename;
849849
if (MCStringGetCharAtIndex(*t_homename, MCStringGetLength(*t_homename) - 1) == '/')

engine/src/dsklnx.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,27 @@ class MCLinuxDesktop: public MCSystemInterface
15801580
return umask(p_mask);
15811581
}
15821582

1583+
virtual IO_handle DeployOpen(MCStringRef p_path, intenum_t p_mode)
1584+
{
1585+
if (p_mode != kMCSOpenFileModeCreate)
1586+
return OpenFile(p_path, p_mode, False);
1587+
1588+
FILE *fptr;
1589+
IO_handle t_handle;
1590+
t_handle = NULL;
1591+
1592+
MCAutoStringRefAsUTF8String t_path_utf;
1593+
if (!t_path_utf.Lock(p_path))
1594+
return NULL;
1595+
1596+
fptr = fopen(*t_path_utf, "wb+");
1597+
1598+
if (fptr != nil)
1599+
t_handle = new MCStdioFileHandle(fptr);
1600+
1601+
return t_handle;
1602+
}
1603+
15831604
virtual IO_handle OpenFile(MCStringRef p_path, intenum_t p_mode, Boolean p_map)
15841605
{
15851606
#ifdef /* MCS_open_dsk_lnx */ LEGACY_SYSTEM

engine/src/dskmac.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6565,6 +6565,27 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
65656565
return MCStringCopy(*t_newname, r_resolved_path);
65666566
}
65676567

6568+
virtual IO_handle DeployOpen(MCStringRef p_path, intenum_t p_mode)
6569+
{
6570+
if (p_mode != kMCSOpenFileModeCreate)
6571+
return OpenFile(p_path, p_mode, False);
6572+
6573+
FILE *fptr;
6574+
IO_handle t_handle;
6575+
t_handle = NULL;
6576+
6577+
MCAutoStringRefAsUTF8String t_path_utf;
6578+
if (!t_path_utf.Lock(p_path))
6579+
return NULL;
6580+
6581+
fptr = fopen(*t_path_utf, IO_CREATE_MODE);
6582+
6583+
if (fptr != nil)
6584+
t_handle = new MCStdioFileHandle(fptr);
6585+
6586+
return t_handle;
6587+
}
6588+
65686589
virtual IO_handle OpenFile(MCStringRef p_path, intenum_t p_mode, Boolean p_map)
65696590
{
65706591
#ifdef /* MCS_open_dsk_mac */ LEGACY_SYSTEM
@@ -6649,7 +6670,7 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
66496670
if (fptr != NULL)
66506671
{
66516672
created = False;
6652-
if (p_mode != kMCSystemFileModeRead)
6673+
if (p_mode != kMCSOpenFileModeRead)
66536674
{
66546675
fclose(fptr);
66556676
fptr = NULL;

engine/src/dskw32.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,7 @@ struct MCWindowsDesktop: public MCSystemInterface, public MCWindowsSystemService
28712871
#endif /* MCS_umask_dsk_w32 */
28722872
return _umask(p_mask);
28732873
}
2874-
2874+
28752875
virtual IO_handle OpenFile(MCStringRef p_path, intenum_t p_mode, Boolean p_map)
28762876
{
28772877
#ifdef /* MCS_open_dsk_w32 */ LEGACY_SYSTEM

engine/src/mcio.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ enum MCSOpenFileMode
5252
kMCSOpenFileModeRead,
5353
kMCSOpenFileModeWrite,
5454
kMCSOpenFileModeUpdate,
55-
kMCSOpenFileModeAppend
55+
kMCSOpenFileModeAppend,
56+
kMCSOpenFileModeCreate
5657
};
5758

5859
////////////////////////////////////////////////////////////////////////////////
@@ -167,6 +168,7 @@ extern IO_handle MCS_fakeopenwrite(void);
167168
///* LEGACY */ extern IO_stat MCS_fakeclosewrite(IO_handle &stream, char*& r_buffer, uint4& r_length);
168169
extern IO_stat MCS_closetakingbuffer(IO_handle& p_stream, void*& r_buffer, size_t& r_length);
169170

171+
extern IO_handle MCS_deploy_open(MCStringRef path, intenum_t p_mode);
170172
/* LEGACY */ extern IO_handle MCS_open(const char *path, const char *mode, Boolean map, Boolean driver, uint4 offset);
171173
extern IO_handle MCS_open(MCStringRef path, intenum_t mode, Boolean map, Boolean driver, uint4 offset);
172174
extern void MCS_close(IO_handle &stream);

engine/src/mode_standalone.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ IO_stat MCDispatch::startup(void)
462462
#endif
463463

464464
MCAutoStringRef t_env;
465-
if (MCS_getenv(MCSTR("TEST_STACK"), &t_env))
465+
if (MCS_getenv(MCSTR("TEST_STACK"), &t_env) && !MCStringIsEmpty(*t_env))
466466
{
467467
MCStack *t_stack;
468468
IO_handle t_stream;
@@ -501,13 +501,18 @@ IO_stat MCDispatch::startup(void)
501501

502502
if (((MCcapsule . size) & (1U << 31)) == 0)
503503
{
504-
// Capsule is not spilled - just use the project section.
505-
// MW-2010-05-08: Capsule size includes 'size' field, so need to adjust
506-
if (!MCCapsuleFillNoCopy(t_capsule, (const void *)&MCcapsule . data, MCcapsule . size - sizeof(uint32_t), true))
507-
{
508-
MCCapsuleClose(t_capsule);
509-
return IO_ERROR;
510-
}
504+
if (MCcapsule . size != 0)
505+
{
506+
// Capsule is not spilled - just use the project section.
507+
// MW-2010-05-08: Capsule size includes 'size' field, so need to adjust
508+
if (!MCCapsuleFillNoCopy(t_capsule, (const void *)&MCcapsule . data, MCcapsule . size - sizeof(uint32_t), true))
509+
{
510+
MCCapsuleClose(t_capsule);
511+
return IO_ERROR;
512+
}
513+
}
514+
else
515+
return IO_ERROR;
511516
}
512517
else
513518
{

0 commit comments

Comments
 (0)