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

Commit efe18dd

Browse files
committed
Modifications on globals after Mark's feedback livecode#6
1 parent ee15a29 commit efe18dd

17 files changed

Lines changed: 110 additions & 200 deletions

engine/src/deploy_sign.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,7 @@ static bool MCDeploySignWindowsAddTimeStamp(const MCDeploySignParameters& p_para
906906
if (t_success)
907907
{
908908
// Set the HTTP headers appropriately to make sure no unpleasant caching goes on.
909-
MCValueRelease(MChttpheaders);
910-
MChttpheaders = MCSTR("Content-Type: application/octet-stream\nAccept: application/octet-stream\nUser-Agent: Transport\nCache-Control: no-cache");
909+
MCValueAssign(MChttpheaders, MCSTR("Content-Type: application/octet-stream\nAccept: application/octet-stream\nUser-Agent: Transport\nCache-Control: no-cache"));
911910

912911
// Use libURL to do the post - we attempt this 5 times with increasing sleep
913912
// periods. This is because it looks like the timestamping service is a little

engine/src/dispatch.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,9 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
854854
return IO_ERROR;
855855
}
856856

857-
char *oldfiletype = strdup(MCStringGetCString(MCfiletype));
858-
MCfiletype = MCValueRetain(MCstackfiletype);
857+
MCStringRef oldfiletype;
858+
oldfiletype = MCfiletype;
859+
MCfiletype = MCstackfiletype;
859860

860861
MCAutoStringRef t_backup;
861862
/* UNCHECKED */ MCStringFormat(&t_backup, "%s~", MCStringGetCString(*t_linkname));
@@ -865,7 +866,7 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
865866
{
866867
MCresult->sets("can't open stack backup file");
867868

868-
/* UNCHECKED */ MCStringCreateWithCString(oldfiletype, MCfiletype);
869+
MCfiletype = oldfiletype;
869870
return IO_ERROR;
870871
}
871872
IO_handle stream;
@@ -874,10 +875,10 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
874875
{
875876
MCresult->sets("can't open stack file");
876877
cleanup(stream, *t_linkname, *t_backup);
877-
/* UNCHECKED */ MCStringCreateWithCString(oldfiletype, MCfiletype);
878+
MCfiletype = oldfiletype;
878879
return IO_ERROR;
879880
}
880-
/* UNCHECKED */ MCStringCreateWithCString(oldfiletype, MCfiletype);
881+
MCfiletype = oldfiletype;
881882
MCString errstring = "Error writing stack (disk full?)";
882883

883884
// MW-2012-03-04: [[ StackFile5500 ]] Work out what header to emit, and the size.

engine/src/dskmain.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ static void create_var(char *v)
5252
/* UNCHECKED */ MCVariable::ensureglobal_cstring(vname, tvar);
5353
tvar->copysvalue(v);
5454

55-
MCStringRef *t_MCstacknames;
56-
t_MCstacknames = (MCStringRef *)realloc(MCstacknames, sizeof(MCStringRef) * (MCnstacks + 1));
57-
//MCU_realloc((char **)&MCstacknames, MCnstacks, MCnstacks + 1, sizeof(char *));
58-
//MCstacknames[MCnstacks++] = v;
59-
MCstacknames = t_MCstacknames;
60-
MCstacknames[MCnstacks] = nil;
61-
/* UNCHECHED */ MCStringCreateWithCString(v, MCstacknames[MCnstacks++]);
55+
MCU_realloc((char **)&MCstacknames, MCnstacks, MCnstacks + 1, sizeof(MCStringRef));
56+
/* UNCHECKED */ MCStringCreateWithCString(v, MCstacknames[MCnstacks++]);
6257
}
6358

6459
static void create_var(uint4 p_v)
@@ -154,28 +149,11 @@ bool X_init(int argc, char *argv[], char *envp[])
154149
#endif
155150

156151
#if defined(_LINUX_DESKTOP) || defined(_MAC_DESKTOP) //get fullpath
157-
if (!(MCStringBeginsWithCString(MCcmd, (const char_t*)"/", kMCCompareExact)))
158-
{//not c:/mc/xxx, not /mc/xxx
159-
MCAutoStringRef tpath_str;
160-
161-
/* UNCHECKED */ MCS_getcurdir(&tpath_str);
162-
char *tpath = strdup(MCStringGetCString(*tpath_str));
163-
164-
if (tpath && MCStringGetLength(MCcmd) + strlen(tpath) < PATH_MAX)
165-
{
166-
strcpy(apppath,tpath);
167-
strcat(apppath, "/");
168-
char *tempmccmd = strdup(MCStringGetCString(MCcmd));
169-
if (*tempmccmd == '.' && tempmccmd[1] != '.')
170-
tempmccmd++;
171-
if (*tempmccmd == '/')
172-
tempmccmd++;
173-
strcat(apppath, tempmccmd);
174-
if (strdup(MCStringGetCString(MCcmd)) != argv[0])
175-
MCValueRelease(MCcmd);
176-
/* UNCHECKED */ MCStringCreateWithCString(appath, MCcmd);
177-
delete tpath;
178-
}
152+
{
153+
MCAutoStringRef t_resolved_cmd;
154+
MCS_resolvepath(MCcmd, &t_resolved_cmd);
155+
MCValueRelease(MCcmd);
156+
MCcmd = MCValueRetain(*t_resolved_cmd);
179157
}
180158
#endif
181159

engine/src/exec-files.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,10 +2139,6 @@ void MCFilesSetUMask(MCExecContext& ctxt, uinteger_t p_value)
21392139
void MCFilesGetFileType(MCExecContext& ctxt, MCStringRef& r_value)
21402140
{
21412141
r_value = MCValueRetain(MCfiletype);
2142-
if (MCStringIsEqualTo(MCfiletype, r_value, kMCStringOptionCompareExact))
2143-
return;
2144-
2145-
ctxt . Throw();
21462142
}
21472143
void MCFilesSetFileType(MCExecContext& ctxt, MCStringRef p_value)
21482144
{
@@ -2158,8 +2154,7 @@ void MCFilesGetSerialControlString(MCExecContext& ctxt, MCStringRef& r_value)
21582154

21592155
void MCFilesSetSerialControlString(MCExecContext& ctxt, MCStringRef p_value)
21602156
{
2161-
MCValueRelease(MCserialcontrolsettings);
2162-
MCserialcontrolsettings = MCValueRetain(p_value);
2157+
MCValueAssign(MCserialcontrolsettings, p_value);
21632158
}
21642159

21652160
void MCFilesGetHideConsoleWindows(MCExecContext& ctxt, bool& r_value)
@@ -2181,8 +2176,7 @@ void MCFilesGetShellCommand(MCExecContext& ctxt, MCStringRef& r_value)
21812176

21822177
void MCFilesSetShellCommand(MCExecContext& ctxt, MCStringRef p_value)
21832178
{
2184-
MCValueRelease(MCshellcmd);
2185-
MCshellcmd = MCValueRetain(p_value);
2179+
MCValueAssign(MCshellcmd, p_value);
21862180
}
21872181

21882182
void MCFilesGetCurrentFolder(MCExecContext& ctxt, MCStringRef& r_value)

engine/src/exec-interface2.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,7 @@ void MCInterfaceGetStackFileType(MCExecContext& ctxt, MCStringRef& r_value)
12101210

12111211
void MCInterfaceSetStackFileType(MCExecContext& ctxt, MCStringRef p_value)
12121212
{
1213-
MCValueRelease(MCstackfiletype);
1214-
MCstackfiletype = MCValueRetain(p_value);
1213+
MCValueAssign(MCstackfiletype, p_value);
12151214
}
12161215

12171216

engine/src/exec-legacy.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -479,18 +479,11 @@ void MCLegacySetRevRuntimeBehaviour(MCExecContext& ctxt, uint4 p_value)
479479
void MCLegacyGetHcImportStat(MCExecContext& ctxt, MCStringRef& r_value)
480480
{
481481
r_value = MCValueRetain(MChcstat);
482-
if (MCStringIsEqualTo(MChcstat, r_value, kMCStringOptionCompareExact))
483-
return;
484-
485-
ctxt . Throw();
486482
}
487483

488484
void MCLegacySetHcImportStat(MCExecContext& ctxt, MCStringRef p_value)
489485
{
490-
if (MCStringCopy(p_value, MChcstat))
491-
return;
492-
493-
ctxt . Throw();
486+
MCValueAssign(MChcstat, p_value);
494487
}
495488

496489
void MCLegacyGetScriptTextFont(MCExecContext& ctxt, MCStringRef& r_value)
@@ -501,8 +494,7 @@ void MCLegacyGetScriptTextFont(MCExecContext& ctxt, MCStringRef& r_value)
501494

502495
void MCLegacySetScriptTextFont(MCExecContext& ctxt, MCStringRef p_value)
503496
{
504-
MCValueRelease(MCscriptfont);
505-
MCscriptfont = MCValueRetain(p_value);
497+
MCValueAssign(MCscriptfont, p_value);
506498
}
507499

508500
void MCLegacyGetScriptTextSize(MCExecContext& ctxt, uinteger_t &r_value)
@@ -834,8 +826,7 @@ void MCLegacyGetVcPlayer(MCExecContext& ctxt, MCStringRef& r_value)
834826

835827
void MCLegacySetVcPlayer(MCExecContext& ctxt, MCStringRef p_value)
836828
{
837-
MCValueRelease(MCvcplayer);
838-
MCvcplayer = MCValueRetain(p_value);
829+
MCValueAssign(MCvcplayer, p_value);
839830
}
840831

841832
////////////////////////////////////////////////////////////////////////////////

engine/src/exec-network.cpp

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ void MCNetworkGetUrlResponse(MCExecContext& ctxt, MCStringRef& r_value)
659659
void MCNetworkGetFtpProxy(MCExecContext& ctxt, MCStringRef& r_value)
660660
{
661661

662-
if (MCftpproxyhost == nil)
662+
if (MCStringIsEmpty(MCftpproxyhost))
663663
{
664664
r_value = (MCStringRef)MCValueRetain(kMCEmptyString);
665665
return;
@@ -675,71 +675,35 @@ void MCNetworkGetFtpProxy(MCExecContext& ctxt, MCStringRef& r_value)
675675

676676
void MCNetworkSetFtpProxy(MCExecContext& ctxt, MCStringRef p_value)
677677
{
678-
MCValueRelease(MCftpproxyhost);
679-
if (MCStringGetLength(p_value) == 0)
680-
MCftpproxyhost = NULL;
678+
679+
MCAutoStringRef t_host, t_port;
680+
/* UNCHECKED */ MCStringDivideAtChar(p_value, ':', kMCCompareCaseless, &t_host, &t_port);
681+
if (*t_port != nil)
682+
/* UNCHECKED */ MCStringToUInt16(*t_port, MCftpproxyport);
681683
else
682-
{
683-
char *eptr = NULL;
684-
MCAutoStringRef t_port_string;
685-
/* UNCHECKED */ MCStringDivideAtChar(p_value, ':', kMCCompareCaseless, MCftpproxyhost, &t_port_string);
686-
if (*t_port_string != nil)
687-
MCftpproxyport = (uint2)strtol(MCStringGetCString(*t_port_string), NULL, 10);
688-
else
689-
MCftpproxyport = 80;
690-
}
684+
MCftpproxyport = 80;
685+
MCValueAssign(MCftpproxyhost, *t_host);
686+
691687
}
692688

693689
void MCNetworkGetHttpProxy(MCExecContext& ctxt, MCStringRef& r_value)
694690
{
695-
if (MChttpproxy == nil)
696-
{
697-
r_value = (MCStringRef)MCValueRetain(kMCEmptyString);
698-
return;
699-
}
700-
else
701-
{
702-
r_value = MCValueRetain(MChttpproxy);
703-
if (MCStringIsEqualTo(MChttpproxy, r_value, kMCStringOptionCompareExact))
704-
return;
705-
}
706-
707-
ctxt . Throw();
691+
r_value = MCValueRetain(MChttpproxy);
708692
}
709693

710694
void MCNetworkSetHttpProxy(MCExecContext& ctxt, MCStringRef p_value)
711695
{
712-
MCValueRelease(MChttpproxy);
713-
if (MCStringGetLength(p_value) == 0)
714-
MChttpproxy = NULL;
715-
else
716-
MChttpproxy = MCValueRetain(p_value);
696+
MCValueAssign(MChttpproxy, p_value);
717697
}
718698

719699
void MCNetworkGetHttpHeaders(MCExecContext& ctxt, MCStringRef& r_value)
720700
{
721-
if (MChttpheaders == nil)
722-
{
723-
r_value = (MCStringRef)MCValueRetain(kMCEmptyString);
724-
return;
725-
}
726-
else
727-
{
728701
r_value = MCValueRetain(MChttpheaders);
729-
if (MCStringIsEqualTo(MChttpheaders, r_value, kMCStringOptionCompareExact))
730-
return;
731-
}
732-
733-
ctxt . Throw();
734702
}
735703

736704
void MCNetworkSetHttpHeaders(MCExecContext& ctxt, MCStringRef p_value)
737705
{
738-
MCValueRelease(MChttpheaders);
739-
if (MCStringGetLength(p_value) == 0)
740-
MChttpheaders = NULL;
741-
else
742-
MChttpheaders = MCValueRetain(p_value);
706+
MCValueAssign(MChttpheaders, p_value);
743707
}
744708

745709
void MCNetworkGetSocketTimeout(MCExecContext& ctxt, double& r_value)

engine/src/globals.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Boolean MCvcshm;
165165
Boolean MCmmap = True;
166166
Boolean MCshmpix;
167167
Boolean MCnoui;
168-
MCStringRef MCdisplayname = NULL;
168+
char *MCdisplayname = NULL;
169169
Boolean MCshmoff;
170170
Boolean MCshmon;
171171
uint4 MCvisualid;
@@ -508,8 +508,8 @@ void X_clear_globals(void)
508508
MCquitisexplicit = False;
509509
MCidleRate = 200;
510510
MCcmd = nil;
511-
MCfiletype = nil;
512-
MCstackfiletype = nil;
511+
MCfiletype = MCValueRetain(kMCEmptyString);
512+
MCstackfiletype = MCValueRetain(kMCEmptyString);
513513
MCstacknames = nil;
514514
MCnstacks = 0;
515515
MCnofiles = False;
@@ -544,7 +544,7 @@ void X_clear_globals(void)
544544
MCmmap = True;
545545
MCshmpix = False;
546546
MCnoui = False;
547-
MCdisplayname = nil;
547+
MCdisplayname = NULL;
548548
MCshmoff = False;
549549
MCshmon = False;
550550
MCvisualid = 0;
@@ -666,7 +666,7 @@ void X_clear_globals(void)
666666
MCscreen = nil;
667667
MCsystemprinter = nil;
668668
MCprinter = nil;
669-
MCscriptfont = nil;
669+
MCscriptfont = MCValueRetain(kMCEmptyString);
670670
MCscriptsize = 0;
671671
MCscrollbarwidth = DEFAULT_SB_WIDTH;
672672
uint2 MCfocuswidth = 2;
@@ -703,13 +703,13 @@ void X_clear_globals(void)
703703
MCsystemPS = True;
704704
MChidewindows = False;
705705
MCbufferimages = False;
706-
MCserialcontrolsettings = nil;
707-
MCshellcmd = nil;
708-
MCvcplayer = nil;
709-
MCftpproxyhost = nil;
706+
MCserialcontrolsettings = MCValueRetain(kMCEmptyString);
707+
MCshellcmd = MCValueRetain(kMCEmptyString);
708+
MCvcplayer = MCValueRetain(kMCEmptyString);
709+
MCftpproxyhost = MCValueRetain(kMCEmptyString);
710710
MCftpproxyport = 0;
711-
MChttpproxy = nil;
712-
MChttpheaders = nil;
711+
MChttpproxy = MCValueRetain(kMCEmptyString);
712+
MChttpheaders = MCValueRetain(kMCEmptyString);
713713
MCrandomseed = 0;
714714
MCshowinvisibles = False;
715715
MCbackscripts = nil;
@@ -895,22 +895,22 @@ bool X_open(int argc, char *argv[], char *envp[])
895895
MCcstack = new MCCardlist;
896896

897897
#ifdef _LINUX_DESKTOP
898-
MCvcplayer = MCSTR("xanim");
898+
MCValueAssign(MCvcplayer, MCSTR("xanim"));
899899
#else
900-
MCvcplayer = MCSTR("");
900+
MCValueAssign(MCvcplayer, MCSTR(""));
901901
#endif
902902

903-
MCfiletype = MCSTR("ttxtTEXT");
903+
MCValueAssign(MCfiletype, MCSTR("ttxtTEXT"));
904904
const char *tname = strrchr(MCStringGetCString(MCcmd), PATH_SEPARATOR);
905905
if (tname == NULL)
906906
tname = MCStringGetCString(MCcmd);
907907
else
908908
tname++;
909909
if (MCU_strncasecmp(tname, "rev", 3))
910-
MCstackfiletype = MCSTR("MCRDMSTK");
910+
MCValueAssign(MCstackfiletype, MCSTR("MCRDMSTK"));
911911
else
912-
MCstackfiletype = MCSTR("RevoRSTK");
913-
MCserialcontrolsettings = MCSTR("baud=9600 parity=N data=8 stop=1");
912+
MCValueAssign(MCstackfiletype, MCSTR("RevoRSTK"));
913+
MCValueAssign(MCserialcontrolsettings, MCSTR("baud=9600 parity=N data=8 stop=1"));
914914

915915
MCdispatcher = new MCDispatch;
916916

@@ -1148,6 +1148,8 @@ int X_close(void)
11481148
for(uint4 i = 0; i < MCnstacks; ++i)
11491149
MCValueRelease(MCstacknames[i]);
11501150

1151+
delete MCstacknames;
1152+
11511153
// Cleanup the parentscript stuff
11521154
MCParentScript::Cleanup();
11531155

engine/src/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extern Boolean MCshmpix ;
9292
extern Boolean MCvcshm;
9393
extern Boolean MCmmap;
9494
extern Boolean MCnoui;
95-
extern MCStringRef MCdisplayname;
95+
extern char *MCdisplayname;
9696
extern Boolean MCshmoff;
9797
extern Boolean MCshmon;
9898
extern uint4 MCvisualid;

0 commit comments

Comments
 (0)