Skip to content

Commit 367b4b4

Browse files
committed
Corrections after Mark's feedback
1 parent 05c6b1d commit 367b4b4

39 files changed

+241
-273
lines changed

engine/src/capsule.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,9 @@ bool MCCapsuleFillFromFile(MCCapsuleRef self, const char *p_path, uint32_t p_off
299299
t_stream = nil;
300300
if (t_success)
301301
{
302-
MCAutoStringRef io_read_mode_string, p_path_string;
303-
/* UNCHECKED */ MCStringCreateWithCString(IO_READ_MODE, &io_read_mode_string);
302+
MCAutoStringRef p_path_string;
304303
/* UNCHECKED */ MCStringCreateWithCString(p_path, &p_path_string);
305-
t_stream = MCS_open(*p_path_string, *io_read_mode_string, True, False, 0);
304+
t_stream = MCS_open(*p_path_string, kMCSOpenFileModeRead, True, False, 0);
306305
if (t_stream == nil)
307306
t_success = false;
308307
}

engine/src/cmdsc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,8 +2862,10 @@ if (MCsecuremode & MC_SECUREMODE_PRIVACY)
28622862
MCeerror->add(EE_RECORD_BADFILE, line, pos);
28632863
return ES_ERROR;
28642864
}
2865-
char *soundfile = MCS_get_canonical_path(ep.getcstring());
2866-
MCtemplateplayer->recordsound(soundfile);
2865+
MCAutoStringRef soundfile, t_path;
2866+
/*UNCHECKED*/MCStringCreateWithCString(ep.getcstring(), &t_path)
2867+
MCS_get_canonical_path(*t_path, &soundfile);
2868+
MCtemplateplayer->recordsound(*soundfile);
28672869
return ES_NORMAL;
28682870
#endif /* MCRecord */
28692871

engine/src/customprinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,9 +2046,7 @@ Exec_stat MCCustomPrinterCreate(const char *p_destination, const char *p_filenam
20462046
#endif
20472047
if (t_module != nil)
20482048
{
2049-
MCAutoStringRef p_symbol;
2050-
/*UNCHECKED*/MCStringCreateWithCString("MCCustomPrinterCreate", &p_symbol);
2051-
s_revpdfprinter_create = (MCCustomPrinterCreateProc)MCS_resolvemodulesymbol(t_module, *p_symbol);
2049+
s_revpdfprinter_create = (MCCustomPrinterCreateProc)MCS_resolvemodulesymbol(t_module, "MCCustomPrinterCreate");
20522050
}
20532051
s_revpdfprinter_loaded = true;
20542052
}

engine/src/dispatch.cpp

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -365,27 +365,25 @@ Boolean MCDispatch::openstartup(const char *sname,
365365
if (enginedir == nil)
366366
return False;
367367

368-
MCAutoStringRef t_io_read_mode_string;
369-
/* UNCHECKED */ MCStringCreateWithCString(IO_READ_MODE, &t_io_read_mode_string);
370-
371368
uint4 l = MCU_max((uint4)strlen(enginedir), (uint4)strlen(startdir)) + strlen(sname) + 11;
372-
char *fullpath = new char[l];
373-
sprintf(fullpath, "%s/%s", startdir, sname);
374-
MCAutoStringRef t_fullpath_string;
375-
/* UNCHECKED */ MCStringCreateWithCString(fullpath, &t_fullpath_string);
369+
MCAutoStringRef t_fullpath_string1;
370+
MCStringFormat(&t_fullpath_string1, "%s/%s", startdir, sname );
376371

377-
if ((stream = MCS_open(*t_fullpath_string, &t_io_read_mode_string, True, False, 0)) != NULL)
372+
if ((stream = MCS_open(*t_fullpath_string1, kMCSOpenFileModeRead, True, False, 0)) != NULL)
378373
{
379-
*outpath = fullpath;
374+
*outpath = strdup(MCStringGetCString(*t_fullpath_string1));
380375
return True;
381376
}
382-
sprintf(fullpath, "%s/%s", enginedir, sname);
383-
if ((stream = MCS_open(*t_fullpath_string, &t_io_read_mode_string, True, False, 0)) != NULL)
377+
378+
MCAutoStringRef t_fullpath_string2;
379+
MCStringFormat(&t_fullpath_string2, "%s/%s", enginedir, sname);
380+
381+
if ((stream = MCS_open(*t_fullpath_string2, kMCSOpenFileModeRead, True, False, 0)) != NULL)
384382
{
385-
*outpath = fullpath;
383+
*outpath = strdup(MCStringGetCString(*t_fullpath_string2));
386384
return True;
387385
}
388-
delete fullpath;
386+
389387

390388
return False;
391389
}
@@ -402,10 +400,10 @@ Boolean MCDispatch::openenv(const char *sname, const char *env,
402400
{
403401
env = MCStringGetCString(*t_env);
404402
char *pathstring = strclone(env);
405-
MCAutoStringRef t_io_read_mode_string;
403+
406404
MCAutoStringRef t_fullpath_string;
407-
/* UNCHECKED */ MCStringCreateWithCString(IO_READ_MODE, &t_io_read_mode_string);
408-
char *fullpath = new char[strlen(env) + strlen(sname) + 2];
405+
406+
//char *fullpath = new char[strlen(env) + strlen(sname) + 2];
409407
char *eptr = pathstring;
410408
while (eptr != NULL)
411409
{
@@ -414,21 +412,22 @@ Boolean MCDispatch::openenv(const char *sname, const char *env,
414412
if (eptr != NULL)
415413
*eptr++ = '\0';
416414
#ifdef _WIN32
417-
sprintf(fullpath, "%s\\%s", path, sname);
415+
MCStringFormat(&t_fullpath_string, "%s\\%s", path, sname);
416+
418417
#else
419-
sprintf(fullpath, "%s/%s", path, sname);
418+
MCStringFormat(&t_fullpath_string, "%s/%s", path, sname);
419+
420420
#endif
421-
/* UNCHECKED */ MCStringCreateWithCString(fullpath, &t_fullpath_string);
422-
if ((stream = MCS_open(*t_fullpath_string, *t_io_read_mode_string, True, False,
421+
if ((stream = MCS_open(*t_fullpath_string, kMCSOpenFileModeRead, True, False,
423422
offset)) != NULL)
424423
{
425424
delete pathstring;
426-
*outpath = fullpath;
425+
*outpath = strdup(MCStringGetCString(*t_fullpath_string));
427426
return True;
428427
}
429428
}
430429
delete pathstring;
431-
delete fullpath;
430+
432431
}
433432
return False;
434433
}
@@ -728,19 +727,17 @@ IO_stat MCDispatch::loadfile(const char *inname, MCStack *&sptr)
728727
char *fname = strclone(inname);
729728
MCAutoStringRef t_fname_string;
730729
/* UNCHECKED */ MCStringCreateWithCString(fname, &t_fname_string);
731-
MCAutoStringRef t_io_read_mode_string;
732-
/* UNCHECKED */ MCStringCreateWithCString(IO_READ_MODE, &t_io_read_mode_string);
733-
if ((stream = MCS_open(*t_fname_string, *t_io_read_mode_string, True, False, 0)) != NULL)
730+
731+
if ((stream = MCS_open(*t_fname_string, kMCSOpenFileModeRead, True, False, 0)) != NULL)
734732
if (fname[0] != PATH_SEPARATOR && fname[1] != ':')
735733
{
736734
MCAutoStringRef t_curpath;
737-
MCS_getcurdir(&t_curpath);
738-
735+
739736
char *curpath = nil;
740-
if (*t_curpath != nil)
737+
if (MCS_getcurdir(&t_curpath))
741738
MCCStringClone(MCStringGetCString(*t_curpath), curpath);
742-
if (curpath[strlen(curpath) - 1] == '/')
743-
curpath[strlen(curpath) - 1] = '\0';
739+
//if (curpath[strlen(curpath) - 1] == '/')
740+
//curpath[strlen(curpath) - 1] = '\0';
744741
openpath = new char[strlen(curpath) + strlen(fname) + 2];
745742
sprintf(openpath, "%s/%s", curpath, fname);
746743
delete curpath;
@@ -758,13 +755,14 @@ IO_stat MCDispatch::loadfile(const char *inname, MCStack *&sptr)
758755
tname++;
759756
MCAutoStringRef tname_string;
760757
/* UNCHECKED */ MCStringCreateWithCString(tname, &tname_string);
761-
if ((stream = MCS_open(*tname_string, *t_io_read_mode_string, True, False, 0)) != NULL)
758+
if ((stream = MCS_open(*tname_string, kMCSOpenFileModeRead, True, False, 0)) != NULL)
762759
{
763760
MCAutoStringRef t_curpath;
764-
MCS_getcurdir(&t_curpath);
761+
765762
char *curpath = nil;
766-
if (*t_curpath != nil)
763+
if (MCS_getcurdir(&t_curpath))
767764
MCCStringClone(MCStringGetCString(*t_curpath), curpath);
765+
768766
openpath = new char[strlen(curpath) + strlen(tname) + 2];
769767
sprintf(openpath, "%s/%s", curpath, tname);
770768
delete curpath;
@@ -792,15 +790,15 @@ IO_stat MCDispatch::loadfile(const char *inname, MCStack *&sptr)
792790
sprintf(openpath, "%s/%s", homename, tname);
793791
MCAutoStringRef t_openpath_string;
794792
/* UNCHECKED */ MCStringCreateWithCString(openpath, &t_openpath_string);
795-
if ((stream = MCS_open(*t_openpath_string, *t_io_read_mode_string, True,
793+
if ((stream = MCS_open(*t_openpath_string, kMCSOpenFileModeRead, True,
796794
False, 0)) == NULL)
797795
{
798796
sprintf(openpath, "%s/stacks/%s", homename, tname);
799-
if ((stream = MCS_open(*t_openpath_string, *t_io_read_mode_string, True,
797+
if ((stream = MCS_open(*t_openpath_string, kMCSOpenFileModeRead, True,
800798
False, 0)) == NULL)
801799
{
802800
sprintf(openpath, "%s/components/%s", homename, tname);
803-
if ((stream = MCS_open(*t_openpath_string, *t_io_read_mode_string, True,
801+
if ((stream = MCS_open(*t_openpath_string, kMCSOpenFileModeRead, True,
804802
False, 0)) == NULL)
805803
{
806804
delete openpath;
@@ -827,18 +825,13 @@ IO_stat MCDispatch::loadfile(const char *inname, MCStack *&sptr)
827825
return stat;
828826
}
829827

830-
void MCDispatch::cleanup(IO_handle stream, char *linkname, char *bname)
828+
void MCDispatch::cleanup(IO_handle stream, MCStringRef linkname, MCStringRef bname)
831829
{
832-
MCAutoStringRef t_linkname_string, t_bname_string;
833-
/* UNCHECKED */ MCStringCreateWithCString(linkname, &t_linkname_string);
834-
/* UNCHECKED */ MCStringCreateWithCString(bname, &t_bname_string);
835830
if (stream != NULL)
836831
MCS_close(stream);
837-
MCS_unlink(*t_linkname_string);
832+
MCS_unlink(linkname);
838833
if (bname != NULL)
839-
MCS_unbackup(*t_bname_string, *t_linkname_string);
840-
delete linkname;
841-
delete bname;
834+
MCS_unbackup(bname, linkname);
842835
}
843836

844837
IO_stat MCDispatch::savestack(MCStack *sptr, const MCStringRef p_fname)
@@ -859,7 +852,6 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
859852
char *linkname;
860853

861854
MCAutoStringRef t_linkname;
862-
/* UNCHECKED */ MCStringCreateWithCString(linkname, &t_linkname);
863855

864856
if (MCStringGetLength(p_fname) != 0)
865857
linkname = strclone(MCStringGetCString(p_fname));
@@ -874,6 +866,7 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
874866
MCresult->sets("can't open stack file, bad path");
875867
return IO_ERROR;
876868
}
869+
/* UNCHECKED */ MCStringCreateWithCString(linkname, &t_linkname);
877870
if (MCS_noperm(*t_linkname))
878871
{
879872
MCresult->sets("can't open stack file, no permission");
@@ -882,31 +875,25 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
882875
}
883876
char *oldfiletype = MCfiletype;
884877
MCfiletype = MCstackfiletype;
885-
char *backup = new char[strlen(linkname) + 2];
886-
strcpy(backup, linkname);
887-
strcat(backup, "~");
888-
889878

890879
MCAutoStringRef t_backup;
891-
/* UNCHECKED */ MCStringCreateWithCString(backup, &t_backup);
880+
MCStringFormat(&t_backup, "%s~", linkname);
892881

893882
MCS_unlink(*t_backup);
894883
if (MCS_exists(*t_linkname, True) && !MCS_backup(*t_linkname, *t_backup))
895884
{
896885
MCresult->sets("can't open stack backup file");
897886
MCfiletype = oldfiletype;
898887
delete linkname;
899-
delete backup;
888+
900889
return IO_ERROR;
901890
}
902891
IO_handle stream;
903-
MCAutoStringRef io_write_mode_string;
904-
/* UNCHECKED */ MCStringCreateWithCString(IO_WRITE_MODE, &io_write_mode_string);
905892

906-
if ((stream = MCS_open(*t_linkname, *io_write_mode_string, True, False, 0)) == NULL)
893+
if ((stream = MCS_open(*t_linkname, kMCSOpenFileModeWrite, True, False, 0)) == NULL)
907894
{
908895
MCresult->sets("can't open stack file");
909-
cleanup(stream, linkname, backup);
896+
cleanup(stream, *t_linkname, *t_backup);
910897
MCfiletype = oldfiletype;
911898
return IO_ERROR;
912899
}
@@ -927,15 +914,15 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
927914
|| IO_write_uint1(CHARSET, stream) != IO_NORMAL)
928915
{
929916
MCresult->sets(errstring);
930-
cleanup(stream, linkname, backup);
917+
cleanup(stream, *t_linkname, *t_backup);
931918
return IO_ERROR;
932919
}
933920

934921
if (IO_write_uint1(OT_NOTHOME, stream) != IO_NORMAL
935922
|| IO_write_string(NULL, stream) != IO_NORMAL)
936923
{ // was stackfiles
937924
MCresult->sets(errstring);
938-
cleanup(stream, linkname, backup);
925+
cleanup(stream, *t_linkname, *t_backup);
939926
return IO_ERROR;
940927
}
941928

@@ -949,7 +936,7 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
949936
{
950937
if (MCresult -> isclear())
951938
MCresult->sets(errstring);
952-
cleanup(stream, linkname, backup);
939+
cleanup(stream, *t_linkname, *t_backup);
953940
return IO_ERROR;
954941
}
955942
MCS_close(stream);
@@ -981,10 +968,9 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
981968
MCS_copyresourcefork(*t_backup, *t_linkname);
982969

983970
sptr->setfilename(linkname);
984-
if (backup != NULL)
971+
if (*t_backup != kMCEmptyString)
985972
{
986973
MCS_unlink(*t_backup);
987-
delete backup;
988974
}
989975
return IO_NORMAL;
990976
}

engine/src/dispatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MCDispatch : public MCObject
8585
// Load the given external from within the app bundle
8686
bool loadexternal(const char *p_external);
8787

88-
void cleanup(IO_handle stream, char *lname, char *bname);
88+
void cleanup(IO_handle stream, MCStringRef lname, MCStringRef bname);
8989
IO_stat savestack(MCStack *sptr, const MCStringRef);
9090
IO_stat startup(void);
9191

engine/src/exec-files.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,12 @@ void MCFilesExecLaunchApp(MCExecContext& ctxt, MCNameRef p_app, MCStringRef p_do
810810
}
811811

812812
uindex_t index;
813-
MCAutoStringRef p_empty;
814-
/* UNCHECKED */ MCStringCreateWithCString(strclone(""), &p_empty);
813+
//MCAutoStringRef p_empty;
814+
//* UNCHECKED */ MCStringCreateWithCString(strclone(""), &p_empty);
815815

816816
if (!IO_findprocess(p_app, index))
817817
MCS_startprocess(p_app,
818-
p_document == NULL ? *p_empty : p_document,
818+
p_document == NULL ? kMCEmptyString : p_document,
819819
OM_NEITHER, False);
820820
else
821821
ctxt . SetTheResultToStaticCString("process is already open");
@@ -866,28 +866,22 @@ void MCFilesExecPerformOpen(MCExecContext& ctxt, MCNameRef p_name, int p_mode, b
866866

867867
IO_handle istream = NULL;
868868
IO_handle ostream = NULL;
869-
870-
MCAutoStringRef io_append_mode_string, io_read_mode_string, io_write_mode_string, io_update_mode_string ;
871-
/* UNCHECKED */ MCStringCreateWithCString(IO_APPEND_MODE, &io_append_mode_string);
872-
/* UNCHECKED */ MCStringCreateWithCString(IO_READ_MODE, &io_read_mode_string);
873-
/* UNCHECKED */ MCStringCreateWithCString(IO_WRITE_MODE, &io_write_mode_string);
874-
/* UNCHECKED */ MCStringCreateWithCString(IO_UPDATE_MODE, &io_update_mode_string);
875869

876870
switch (p_mode)
877871
{
878872
case OM_APPEND:
879-
ostream = MCS_open(MCNameGetString(p_name), *io_append_mode_string, False, p_is_driver, 0);
873+
ostream = MCS_open(MCNameGetString(p_name), kMCSOpenFileModeAppend, False, p_is_driver, 0);
880874
break;
881875
case OM_NEITHER:
882876
break;
883877
case OM_READ:
884-
istream = MCS_open(MCNameGetString(p_name), *io_read_mode_string, True, p_is_driver, 0);
878+
istream = MCS_open(MCNameGetString(p_name), kMCSOpenFileModeRead, True, p_is_driver, 0);
885879
break;
886880
case OM_WRITE:
887-
ostream = MCS_open(MCNameGetString(p_name), *io_write_mode_string, False, p_is_driver, 0);
881+
ostream = MCS_open(MCNameGetString(p_name), kMCSOpenFileModeWrite, False, p_is_driver, 0);
888882
break;
889883
case OM_UPDATE:
890-
istream = ostream = MCS_open(MCNameGetString(p_name), *io_update_mode_string, False, p_is_driver, 0);
884+
istream = ostream = MCS_open(MCNameGetString(p_name), kMCSOpenFileModeUpdate, False, p_is_driver, 0);
891885
break;
892886
default:
893887
break;

engine/src/exec-interface.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,10 +3354,7 @@ void MCInterfaceExecImportGetStream(MCExecContext& ctxt, MCStringRef p_filename,
33543354
return;
33553355
}
33563356

3357-
MCAutoStringRef io_read_mode_string;
3358-
/* UNCHECKED */ MCStringCreateWithCString(IO_READ_MODE, &io_read_mode_string);
3359-
3360-
r_stream = MCS_open(p_filename, *io_read_mode_string, True, False, 0);
3357+
r_stream = MCS_open(p_filename, kMCSOpenFileModeRead, True, False, 0);
33613358
}
33623359

33633360
void MCInterfaceExecImportAudioClip(MCExecContext& ctxt, MCStringRef p_filename)
@@ -3499,22 +3496,19 @@ void MCInterfaceExportBitmapToFile(MCExecContext& ctxt, MCImageBitmap *p_bitmap,
34993496
{
35003497
if (!ctxt . EnsureDiskAccessIsAllowed())
35013498
return;
3502-
3503-
MCAutoStringRef io_write_mode_string;
3504-
/* UNCHECKED */ MCStringCreateWithCString(IO_WRITE_MODE, &io_write_mode_string);
35053499

35063500
IO_handle t_mstream = nil;
35073501
if (p_mask_filename != nil)
35083502
{
35093503

3510-
if ((t_mstream = MCS_open(p_mask_filename, *io_write_mode_string, False, False, 0)) == nil)
3504+
if ((t_mstream = MCS_open(p_mask_filename, kMCSOpenFileModeWrite, False, False, 0)) == nil)
35113505
{
35123506
ctxt . LegacyThrow(EE_EXPORT_CANTOPEN);
35133507
return;
35143508
}
35153509
}
35163510
IO_handle t_fstream;
3517-
if ((t_fstream = MCS_open(p_filename, *io_write_mode_string, False, False, 0)) == nil)
3511+
if ((t_fstream = MCS_open(p_filename, kMCSOpenFileModeWrite, False, False, 0)) == nil)
35183512
{
35193513
ctxt . LegacyThrow(EE_EXPORT_CANTOPEN);
35203514
if (t_mstream != nil)

0 commit comments

Comments
 (0)