Skip to content

Commit 007f6e9

Browse files
Signature of MCS_read* functions updated to the more convenient (void*, size_t, IO_header)
MCMemoryFileHandle and MCCustomFileHandle declarations moved to system.h so that they are accessible from platform-specific files (dskmac.cpp, dskw32.cpp and such)
1 parent 648a1f6 commit 007f6e9

36 files changed

Lines changed: 378 additions & 422 deletions

engine/engine.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,7 @@
15451545
A71F80530F4F178C003012FD /* Standalone.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = Standalone.icns; path = rsrc/Standalone.icns; sourceTree = "<group>"; };
15461546
A71F80610F4F17F9003012FD /* StandaloneDoc.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = StandaloneDoc.icns; path = rsrc/StandaloneDoc.icns; sourceTree = "<group>"; };
15471547
BEF2C0EF17BA493A00E96459 /* socket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = socket.h; path = src/socket.h; sourceTree = "<group>"; };
1548+
BEF3110417C217C30073D70F /* dskw32.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = dskw32.cpp; path = src/dskw32.cpp; sourceTree = "<group>"; };
15481549
BEFE81D317B2B32800C9D14F /* dskmac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = dskmac.cpp; path = src/dskmac.cpp; sourceTree = "<group>"; };
15491550
E8189EB515D17E8000194F25 /* exec-logic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "exec-logic.cpp"; path = "src/exec-logic.cpp"; sourceTree = "<group>"; };
15501551
E864B41F15BDAB3F00F5361C /* legacy_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = legacy_spec.cpp; path = src/legacy_spec.cpp; sourceTree = "<group>"; };
@@ -2387,6 +2388,7 @@
23872388
4D05B90E13E06AAC001CD82A /* dskosxmain.mm */,
23882389
4D05B90F13E06AAC001CD82A /* dskw32main.cpp */,
23892390
4DE7ED0D13B33B7F002634F5 /* dskspec.cpp */,
2391+
BEF3110417C217C30073D70F /* dskw32.cpp */,
23902392
);
23912393
name = Desktop;
23922394
sourceTree = "<group>";

engine/src/aclip.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ Boolean MCAudioClip::import(const char *fname, IO_handle stream)
497497
if (size == 0)
498498
return False;
499499
samples = new int1[size];
500-
if (IO_read(samples, sizeof(int1), size, stream) != IO_NORMAL)
500+
if (IO_read(samples, size, stream) != IO_NORMAL)
501501
return False;
502502
if (strnequal(samples, ".snd", 4))
503503
{
@@ -1011,7 +1011,7 @@ IO_stat MCAudioClip::load(IO_handle stream, const char *version)
10111011
if (size != 0)
10121012
{
10131013
samples = new int1[size];
1014-
if ((stat = IO_read(samples, sizeof(int1), size, stream)) != IO_NORMAL)
1014+
if ((stat = IO_read(samples, size, stream)) != IO_NORMAL)
10151015
return stat;
10161016
}
10171017
if ((stat = IO_read_uint2(&format, stream)) != IO_NORMAL)

engine/src/capsule.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,7 @@ static bool MCCapsuleReadBuckets(MCCapsuleRef self, void *p_buffer, uint32_t p_b
393393
return false;
394394

395395
// Read the data we require.
396-
if (MCS_readfixed(t_buffer, 1, t_amount_read, self -> buckets -> data_file) == IO_ERROR)
397-
return false;
398-
399-
// If the amount we require isn't available, its an error.
400-
if (t_amount != t_amount_read)
396+
if (MCS_readfixed(t_buffer, t_amount_read, self -> buckets -> data_file) == IO_ERROR)
401397
return false;
402398
}
403399

@@ -788,10 +784,7 @@ bool MCCapsuleProcess(MCCapsuleRef self)
788784
{
789785
// If we haven't got all the data, then we have all data buffered
790786
// so can use a regular variety fake stream.
791-
MCAutoDataRef t_data;
792-
793-
t_success = MCDataCreateWithBytes(self -> output_buffer + t_header_size, t_length, &t_data);
794-
t_stream = MCS_fakeopen(*t_data);
787+
t_stream = MCS_fakeopen(MCString((const char *)self -> output_buffer + t_header_size, t_length));
795788
}
796789
else
797790
{

engine/src/chunk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ Exec_stat MCChunk::getobj(MCExecPoint &ep, MCObject *&objptr,
944944
uint4 offset;
945945
if (MCU_offset(SIGNATURE, ep.getsvalue(), offset) && (ep . getsvalue() . getlength() > 8 && strncmp(ep . getsvalue() . getstring(), "REVO", 4) == 0))
946946
{
947-
IO_handle stream = MCS_fakeopen((MCDataRef)ep.getvalueref());
947+
IO_handle stream = MCS_fakeopen(ep.getsvalue());
948948
if (MCdispatcher->readfile(NULL, NULL, stream, sptr) != IO_NORMAL)
949949
{
950950
MCS_close(stream);

engine/src/cmdss.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ MCStack *MCGo::findstack(MCExecPoint &ep, Chunk_term etype, MCCard *&cptr, bool
525525
uint4 offset;
526526
if (MCU_offset(SIGNATURE, ep.getsvalue(), offset) || (ep . getsvalue() . getlength() > 8 && strncmp(ep . getsvalue() . getstring(), "REVO", 4) == 0))
527527
{
528-
IO_handle stream = MCS_fakeopen((MCDataRef)ep.getvalueref());
528+
IO_handle stream = MCS_fakeopen(ep.getsvalue());
529529
if (MCdispatcher->readfile(NULL, NULL, stream, sptr) != IO_NORMAL)
530530
{
531531
MCS_close(stream);

engine/src/dispatch.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,7 @@ Boolean MCDispatch::openenv(MCStringRef sname, MCStringRef env,
478478
IO_stat readheader(IO_handle& stream, char *version)
479479
{
480480
char tnewheader[NEWHEADERSIZE];
481-
uint4 size = (uint4)NEWHEADERSIZE;
482-
483-
if (IO_read(tnewheader, sizeof(char), size, stream) == IO_NORMAL)
481+
if (IO_read(tnewheader, NEWHEADERSIZE, stream) == IO_NORMAL)
484482
{
485483
// MW-2012-03-04: [[ StackFile5500 ]] Check for either the 2.7 or 5.5 header.
486484
if (strncmp(tnewheader, newheader, NEWHEADERSIZE) == 0 ||
@@ -497,11 +495,10 @@ IO_stat readheader(IO_handle& stream, char *version)
497495
else
498496
{
499497
char theader[HEADERSIZE + 1];
500-
uint4 size = HEADERSIZE - NEWHEADERSIZE;
501498
theader[HEADERSIZE] = '\0';
502499
uint4 offset;
503500
strncpy(theader, tnewheader, NEWHEADERSIZE);
504-
if (IO_read(theader + NEWHEADERSIZE, sizeof(char), size, stream) == IO_NORMAL
501+
if (IO_read(theader + NEWHEADERSIZE, HEADERSIZE - NEWHEADERSIZE, stream) == IO_NORMAL
505502
&& MCU_offset(SIGNATURE, theader, offset))
506503
{
507504
if (theader[offset - 1] != '\n' || theader[offset - 2] == '\r')
@@ -740,7 +737,7 @@ IO_stat MCDispatch::doreadfile(const char *openpath, const char *inname, IO_hand
740737
char *script = new char[size + 2];
741738
script[size] = '\n';
742739
script[size + 1] = '\0';
743-
if (IO_read(script, sizeof(char), size, stream) != IO_NORMAL
740+
if (IO_read(script, size, stream) != IO_NORMAL
744741
|| !stacks->setscript(script))
745742
{
746743
delete script;

engine/src/dskmac.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5126,7 +5126,7 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
51265126
}
51275127

51285128
// NOTE: 'GetTemporaryFileName' returns a standard (not native) path.
5129-
virtual void GetTemporaryFileName(MCStringRef& r_tmp_name)
5129+
virtual bool GetTemporaryFileName(MCStringRef& r_tmp_name)
51305130
{
51315131
#ifdef /* MCS_tmpnam_dsk_mac */ LEGACY_SYSTEM
51325132
char *t_temp_file = nil;
@@ -5158,44 +5158,47 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
51585158
delete t_temp_file;
51595159
return t_success;
51605160
#endif /* MCS_tmpnam_dsk_mac */
5161-
bool t_error = false;
5161+
bool t_success = false;
51625162
MCAutoStringRef t_temp_file_auto;
51635163
FSRef t_folder_ref;
51645164
char* t_temp_file_chars;
51655165

51665166
t_temp_file_chars = nil;
5167-
t_error = !MCStringCreateMutable(0, &t_temp_file_auto);
5167+
t_success = MCStringCreateMutable(0, &t_temp_file_auto);
51685168

5169-
if (!t_error && FSFindFolder(kOnSystemDisk, kTemporaryFolderType, TRUE, &t_folder_ref) == noErr)
5169+
if (t_success && FSFindFolder(kOnSystemDisk, kTemporaryFolderType, TRUE, &t_folder_ref) == noErr)
51705170
{
51715171
int t_fd;
5172-
t_error = !MCS_fsref_to_path(t_folder_ref, &t_temp_file_auto);
5172+
t_success = MCS_fsref_to_path(t_folder_ref, &t_temp_file_auto);
51735173

5174-
if (!t_error)
5175-
t_error = MCStringAppendFormat(&t_temp_file_auto, "/tmp.%d.XXXXXXXX", getpid());
5174+
if (t_success)
5175+
t_success = MCStringAppendFormat(&t_temp_file_auto, "/tmp.%d.XXXXXXXX", getpid());
51765176

5177-
t_error = MCMemoryAllocateCopy(MCStringGetCString(*t_temp_file_auto), MCStringGetLength(*t_temp_file_auto) + 1, t_temp_file_chars);
5177+
if (t_success)
5178+
t_success = MCMemoryAllocateCopy(MCStringGetCString(*t_temp_file_auto), MCStringGetLength(*t_temp_file_auto) + 1, t_temp_file_chars);
51785179

5179-
if (!t_error)
5180+
if (t_success)
51805181
{
51815182
t_fd = mkstemp(t_temp_file_chars);
5182-
t_error = t_fd != -1;
5183+
t_success = t_fd != -1;
51835184
}
51845185

5185-
if (!t_error)
5186+
if (t_success)
51865187
{
51875188
close(t_fd);
5188-
t_error = unlink(t_temp_file_chars) != 0;
5189+
t_success = unlink(t_temp_file_chars) == 0;
51895190
}
51905191
}
51915192

5192-
if (!t_error)
5193-
t_error = !MCStringCreateWithCString(t_temp_file_chars, r_tmp_name);
5193+
if (t_success)
5194+
t_success = MCStringCreateWithCString(t_temp_file_chars, r_tmp_name);
51945195

5195-
if (t_error)
5196+
if (!t_success)
51965197
r_tmp_name = MCValueRetain(kMCEmptyString);
51975198

51985199
MCMemoryDeallocate(t_temp_file_chars);
5200+
5201+
return t_success;
51995202
}
52005203

52015204
#define CATALOG_MAX_ENTRIES 16

engine/src/eps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ IO_stat MCEPS::load(IO_handle stream, const char *version)
571571
if ((stat = IO_read_uint4(&size, stream)) != IO_NORMAL)
572572
return stat;
573573
postscript = new char[size + 1];
574-
if ((stat = IO_read(postscript, sizeof(char), size, stream)) != IO_NORMAL)
574+
if ((stat = IO_read(postscript, size, stream)) != IO_NORMAL)
575575
return stat;
576576
postscript[size] = '\0';
577577
if ((stat = IO_read_string(prolog, stream)) != IO_NORMAL)
@@ -730,7 +730,7 @@ Boolean MCEPS::import(const char *fname, IO_handle stream)
730730
size = (uint4)MCS_fsize(stream);
731731
delete postscript;
732732
postscript = new char[size + 1];
733-
if (IO_read(postscript, sizeof(char), size, stream) != IO_NORMAL)
733+
if (IO_read(postscript, size, stream) != IO_NORMAL)
734734
return False;
735735
postscript[size] = '\0';
736736
const char *tname = strrchr(fname, PATH_SEPARATOR);

engine/src/exec-array.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,17 @@ void MCArraysEvalArrayEncode(MCExecContext& ctxt, MCArrayRef p_array, MCStringRe
279279

280280
//////////
281281

282-
char *t_buffer;
283-
uint32_t t_length;
282+
void *t_buffer;
283+
size_t t_length;
284284
t_buffer = nil;
285285
t_length = 0;
286-
if (MCS_closetakingbuffer(t_stream_handle, reinterpret_cast<void*&>(t_buffer), reinterpret_cast<size_t&>(t_length)) != IO_NORMAL)
286+
if (MCS_closetakingbuffer(t_stream_handle, t_buffer, t_length) != IO_NORMAL)
287287
t_success = false;
288288

289289
if (t_success)
290290
t_success = MCStringCreateWithNativeChars((const char_t *)t_buffer, t_length, r_encoding);
291291

292-
delete t_buffer;
292+
free(t_buffer);
293293

294294
if (t_success)
295295
return;
@@ -303,14 +303,10 @@ void MCArraysEvalArrayDecode(MCExecContext& ctxt, MCStringRef p_encoding, MCArra
303303
t_success = true;
304304

305305
IO_handle t_stream_handle;
306-
MCAutoDataRef t_data;
307306
t_stream_handle = nil;
308-
if (t_success)
309-
t_success = MCDataCreateWithBytes(MCStringGetBytePtr(p_encoding), MCStringGetLength(p_encoding), &t_data);
310-
311307
if (t_success)
312308
{
313-
t_stream_handle = MCS_fakeopen(*t_data);
309+
t_stream_handle = MCS_fakeopen(MCStringGetOldString(p_encoding));
314310
if (t_stream_handle == nil)
315311
t_success = false;
316312
}

engine/src/exec-files.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void MCFilesEvalSpecialFolderPath(MCExecContext& ctxt, MCStringRef p_folder, MCS
256256
MCNameCreate(p_folder, &t_path);
257257
if (MCS_getspecialfolder(*t_path, r_path))
258258
{
259-
if (MCStringGetLength(r_path) == 0)
259+
if (MCStringIsEmpty(r_path))
260260
ctxt.SetTheResultToCString("folder not found");
261261
else
262262
ctxt.SetTheResultToEmpty();
@@ -1003,7 +1003,7 @@ void MCFilesExecPerformReadFor(MCExecContext& ctxt, IO_handle p_stream, int4 p_i
10031003
{
10041004
uint4 rsize = size - tsize;
10051005
uint4 fullsize = rsize;
1006-
r_stat = MCS_readfixed(t_current.Chars() + tsize, sizeof(char_t), rsize, p_stream);
1006+
r_stat = MCS_readfixed(t_current.Chars() + tsize, rsize, p_stream); // ??? readall ???
10071007
tsize += rsize;
10081008
if (rsize < fullsize)
10091009
{
@@ -1221,7 +1221,7 @@ void MCFilesExecPerformReadUntil(MCExecContext& ctxt, IO_handle p_stream, int4 p
12211221
/* UNCHECKED */ t_buffer.Extend(tsize + BUFSIZ);
12221222
tsize += BUFSIZ;
12231223
}
1224-
r_stat = MCS_readfixed(t_buffer.Chars() + size, sizeof(char_t), rsize, p_stream);
1224+
r_stat = MCS_readfixed(t_buffer.Chars() + size, rsize, p_stream); // ??? readall ???
12251225
size += rsize;
12261226
if (rsize < fullsize)
12271227
{
@@ -1289,7 +1289,7 @@ void MCFilesExecPerformReadUntil(MCExecContext& ctxt, IO_handle p_stream, int4 p
12891289
{
12901290
uint1 term;
12911291
uint4 nread = 1;
1292-
if (MCS_readfixed(&term, sizeof(char), nread, p_stream) == IO_NORMAL)
1292+
if (MCS_readfixed(&term, nread, p_stream) == IO_NORMAL) // ??? readall ???
12931293
{
12941294
if (term != '\n')
12951295
MCS_putback(term, p_stream);
@@ -1346,7 +1346,7 @@ void MCFilesExecPerformReadUntilBinary(MCExecContext& ctxt, IO_handle stream, in
13461346
/* UNCHECKED */ t_buffer.Extend(tsize + BUFSIZ);
13471347
tsize += BUFSIZ;
13481348
}
1349-
r_stat = MCS_readfixed(t_buffer.Chars() + size, sizeof(char_t), rsize, stream);
1349+
r_stat = MCS_readfixed(t_buffer.Chars() + size, rsize, stream); // ??? readall ???
13501350
size += rsize;
13511351
if (rsize < fullsize)
13521352
{

0 commit comments

Comments
 (0)