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

Commit 50d9f62

Browse files
runrevmarkpeter-b
authored andcommitted
[[ VarAccess ]] Make MCContainer creation act on a reference
This patch changes the creation of MCContainers so that the constructors act on a reference, rather than returning a new object. This allows stack allocation of MCContainer classes in almost all cases.
1 parent 04db37c commit 50d9f62

File tree

13 files changed

+100
-94
lines changed

13 files changed

+100
-94
lines changed

engine/src/cmdse.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ Parse_stat MCDispatchCmd::parse(MCScriptPoint& sp)
597597
// This method follows along the same lines as MCComref::exec
598598
void MCDispatchCmd::exec_ctxt(MCExecContext &ctxt)
599599
{
600-
601600
MCNewAutoNameRef t_message;
602601
if (!ctxt . EvalExprAsNameRef(message, EE_DISPATCH_BADMESSAGEEXP, &t_message))
603602
return;
@@ -623,9 +622,9 @@ void MCDispatchCmd::exec_ctxt(MCExecContext &ctxt)
623622
while (tptr != NULL)
624623
{
625624
// AL-2014-08-20: [[ ArrayElementRefParams ]] Use containers for potential reference parameters
626-
MCContainer *t_container;
627-
if (tptr -> evalcontainer(ctxt, t_container))
628-
tptr -> set_argument_container(t_container);
625+
MCAutoPointer<MCContainer> t_container = new (nothrow) MCContainer;
626+
if (tptr -> evalcontainer(ctxt, **t_container))
627+
tptr -> set_argument_container(t_container.Release());
629628
else
630629
{
631630
MCExecValue t_value;

engine/src/cmdsm.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ void MCAdd::exec_ctxt(MCExecContext &ctxt)
9797
}
9898

9999
MCExecValue t_dst;
100-
MCAutoPointer<MCContainer> t_dst_container;
100+
MCContainer t_dst_container;
101101
if (destvar != nil)
102102
{
103103
bool t_success;
104104
if (destvar -> needsContainer())
105-
t_success = destvar -> evalcontainer(ctxt, &t_dst_container)
106-
&& t_dst_container -> eval_ctxt(ctxt, t_dst);
105+
t_success = destvar -> evalcontainer(ctxt, t_dst_container)
106+
&& t_dst_container.eval_ctxt(ctxt, t_dst);
107107
else
108108
{
109109
destvar -> eval_ctxt(ctxt, t_dst);
@@ -164,7 +164,7 @@ void MCAdd::exec_ctxt(MCExecContext &ctxt)
164164
{
165165
bool t_success;
166166
if (destvar -> needsContainer())
167-
t_success = t_dst_container -> give_value(ctxt, t_result);
167+
t_success = t_dst_container.give_value(ctxt, t_result);
168168
else
169169
t_success = destvar -> give_value(ctxt, t_result);
170170

@@ -259,13 +259,13 @@ void MCDivide::exec_ctxt(MCExecContext &ctxt)
259259
}
260260

261261
MCExecValue t_dst;
262-
MCAutoPointer<MCContainer> t_dst_container;
262+
MCContainer t_dst_container;
263263
if (destvar != nil)
264264
{
265265
bool t_success;
266266
if (destvar -> needsContainer())
267-
t_success = destvar -> evalcontainer(ctxt, &t_dst_container)
268-
&& t_dst_container -> eval_ctxt(ctxt, t_dst);
267+
t_success = destvar -> evalcontainer(ctxt, t_dst_container)
268+
&& t_dst_container.eval_ctxt(ctxt, t_dst);
269269
else
270270
{
271271
destvar -> eval_ctxt(ctxt, t_dst);
@@ -326,7 +326,7 @@ void MCDivide::exec_ctxt(MCExecContext &ctxt)
326326
bool t_success;
327327

328328
if (destvar -> needsContainer())
329-
t_success = t_dst_container -> give_value(ctxt, t_result);
329+
t_success = t_dst_container.give_value(ctxt, t_result);
330330
else
331331
t_success = destvar -> give_value(ctxt, t_result);
332332

@@ -425,13 +425,13 @@ void MCMultiply::exec_ctxt(MCExecContext &ctxt)
425425
}
426426

427427
MCExecValue t_dst;
428-
MCAutoPointer<MCContainer> t_dst_container;
428+
MCContainer t_dst_container;
429429
if (destvar != nil)
430430
{
431431
bool t_success;
432432
if (destvar -> needsContainer())
433-
t_success = destvar -> evalcontainer(ctxt, &t_dst_container)
434-
&& t_dst_container -> eval_ctxt(ctxt, t_dst);
433+
t_success = destvar -> evalcontainer(ctxt, t_dst_container)
434+
&& t_dst_container.eval_ctxt(ctxt, t_dst);
435435
else
436436
{
437437
destvar -> eval_ctxt(ctxt, t_dst);
@@ -492,7 +492,7 @@ void MCMultiply::exec_ctxt(MCExecContext &ctxt)
492492
bool t_success;
493493

494494
if (destvar -> needsContainer())
495-
t_success = t_dst_container -> give_value(ctxt, t_result);
495+
t_success = t_dst_container.give_value(ctxt, t_result);
496496
else
497497
t_success = destvar -> give_value(ctxt, t_result);
498498

@@ -591,13 +591,13 @@ void MCSubtract::exec_ctxt(MCExecContext &ctxt)
591591
}
592592

593593
MCExecValue t_dst;
594-
MCAutoPointer<MCContainer> t_dst_container;
594+
MCContainer t_dst_container;
595595
if (destvar != nil)
596596
{
597597
bool t_success;
598598
if (destvar -> needsContainer())
599-
t_success = destvar -> evalcontainer(ctxt, &t_dst_container)
600-
&& t_dst_container -> eval_ctxt(ctxt, t_dst);
599+
t_success = destvar -> evalcontainer(ctxt, t_dst_container)
600+
&& t_dst_container.eval_ctxt(ctxt, t_dst);
601601
else
602602
{
603603
destvar -> eval_ctxt(ctxt, t_dst);
@@ -658,7 +658,7 @@ void MCSubtract::exec_ctxt(MCExecContext &ctxt)
658658
bool t_success;
659659

660660
if (destvar -> needsContainer())
661-
t_success = t_dst_container -> give_value(ctxt, t_result);
661+
t_success = t_dst_container.give_value(ctxt, t_result);
662662
else
663663
t_success = destvar -> give_value(ctxt, t_result);
664664

@@ -805,15 +805,15 @@ void MCArrayOp::exec_ctxt(MCExecContext &ctxt)
805805
return;
806806
}
807807

808-
MCAutoPointer<MCContainer> t_container;
808+
MCContainer t_container;
809809
MCAutoValueRef t_container_value;
810-
if (!destvar -> evalcontainer(ctxt, &t_container))
810+
if (!destvar -> evalcontainer(ctxt, t_container))
811811
{
812812
ctxt . LegacyThrow(EE_ARRAYOP_BADEXP);
813813
return;
814814
}
815815

816-
if (!t_container -> eval(ctxt, &t_container_value))
816+
if (!t_container.eval(ctxt, &t_container_value))
817817
{
818818
ctxt . Throw();
819819
return;
@@ -841,7 +841,7 @@ void MCArrayOp::exec_ctxt(MCExecContext &ctxt)
841841
MCArraysExecCombineAsSet(ctxt, *t_array, *t_element_del, &t_string);
842842

843843
if (!ctxt . HasError())
844-
t_container -> set(ctxt, *t_string);
844+
t_container.set(ctxt, *t_string);
845845
}
846846
else
847847
{
@@ -861,7 +861,7 @@ void MCArrayOp::exec_ctxt(MCExecContext &ctxt)
861861
MCArraysExecSplitAsSet(ctxt, *t_string, *t_element_del, &t_array);
862862

863863
if (!ctxt . HasError())
864-
t_container -> set(ctxt, *t_array);
864+
t_container.set(ctxt, *t_array);
865865
}
866866
}
867867

@@ -960,15 +960,15 @@ void MCSetOp::exec_ctxt(MCExecContext &ctxt)
960960
if (!ctxt . EvalExprAsValueRef(source, EE_ARRAYOP_BADEXP, &t_src))
961961
return;
962962

963-
MCAutoPointer<MCContainer> t_container;
964-
if (!destvar -> evalcontainer(ctxt, &t_container))
963+
MCContainer t_container;
964+
if (!destvar -> evalcontainer(ctxt, t_container))
965965
{
966966
ctxt . LegacyThrow(EE_ARRAYOP_BADEXP);
967967
return;
968968
}
969969

970970
MCAutoValueRef t_dst;
971-
if (!t_container -> eval(ctxt, &t_dst))
971+
if (!t_container.eval(ctxt, &t_dst))
972972
return;
973973

974974
MCAutoValueRef t_dst_value;
@@ -990,7 +990,7 @@ void MCSetOp::exec_ctxt(MCExecContext &ctxt)
990990
}
991991

992992
if (!ctxt . HasError())
993-
t_container -> set(ctxt, *t_dst_value);
993+
t_container.set(ctxt, *t_dst_value);
994994
}
995995

996996
void MCSetOp::compile(MCSyntaxFactoryRef ctxt)

engine/src/exec-extension.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,12 @@ Exec_stat MCEngineHandleLibraryMessage(MCNameRef p_message, MCParameter *p_param
503503

504504
if (t_mode != kMCHandlerTypeFieldModeIn)
505505
{
506-
MCContainer *t_container;
506+
MCContainer t_container;
507507
if (t_param -> evalcontainer(*MCECptr, t_container))
508508
{
509509
if (!MCExtensionConvertToScriptType(*MCECptr, t_arguments[i]) ||
510-
!t_container -> set(*MCECptr, t_arguments[i]))
510+
!t_container.set(*MCECptr, t_arguments[i]))
511511
t_success = false;
512-
delete t_container;
513512
}
514513
else
515514
t_param -> set_argument(*MCECptr, t_arguments[i]);

engine/src/exec-keywords.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ void MCKeywordsExecCommandOrFunction(MCExecContext& ctxt, bool resolved, MCHandl
149149
while (tptr != NULL)
150150
{
151151
// AL-2014-08-20: [[ ArrayElementRefParams ]] Use containers for potential reference parameters
152-
MCContainer *t_container;
153-
if (tptr -> evalcontainer(ctxt, t_container))
154-
tptr -> set_argument_container(t_container);
152+
MCAutoPointer<MCContainer> t_container = new (nothrow) MCContainer;
153+
if (tptr -> evalcontainer(ctxt, **t_container))
154+
tptr -> set_argument_container(t_container.Release());
155155
else
156156
{
157157
tptr -> clear_argument();

engine/src/express.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ MCVariable *MCExpression::evalvar(MCExecContext& ctxt)
6565
return NULL;
6666
}
6767

68-
bool MCExpression::evalcontainer(MCExecContext& ctxt, MCContainer*& r_container)
68+
bool MCExpression::evalcontainer(MCExecContext& ctxt, MCContainer& r_container)
6969
{
7070
return false;
7171
}

engine/src/express.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MCExpression
5858
// Evaluate the expression as a container, and place the reference to
5959
// the container's value in r_ref.
6060
// EP-less version of evaluation functions
61-
virtual bool evalcontainer(MCExecContext& ctxt, MCContainer*& r_container);
61+
virtual bool evalcontainer(MCExecContext& ctxt, MCContainer& r_container);
6262
virtual MCVariable *evalvar(MCExecContext& ctxt);
6363

6464
// Return the var-ref which lies at the root of this expression.

engine/src/externalv0.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ static Exec_stat getvarptr(MCExecContext& ctxt, const MCString &vname,MCVariable
411411
if ((*tvar = newvar->evalvar(ctxt)) == NULL)
412412
{
413413
// SN-2014-10-21: [[ Bug 13728 ]] The variable might be held in a container.
414-
MCAutoPointer<MCContainer> t_container;
414+
MCContainer t_container;
415415

416-
if (!newvar->evalcontainer(*MCECptr, &t_container) ||
417-
(*tvar = t_container->getvar()) == NULL)
416+
if (!newvar->evalcontainer(*MCECptr, t_container) ||
417+
(*tvar = t_container.getvar()) == NULL)
418418
{
419419
delete newvar;
420420
return ES_ERROR;

engine/src/funcs.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ void MCBinaryDecode::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
339339
{
340340
// AL-2014-09-09: [[ Bug 13359 ]] Make sure containers are used in case a param is a handler variable
341341
// AL-2014-09-18: [[ Bug 13465 ]] Use auto class to prevent memory leak
342-
MCAutoPointer<MCContainer> t_container;
343-
if (!t_params->evalcontainer(ctxt, &t_container))
342+
MCContainer t_container;
343+
if (!t_params->evalcontainer(ctxt, t_container))
344344
{
345345
ctxt . LegacyThrow(EE_BINARYD_BADDEST);
346346
return;
347347
}
348348

349-
/* UNCHECKED */ t_container->set_valueref(t_results[i]);
349+
/* UNCHECKED */ t_container.set_valueref(t_results[i]);
350350
}
351351
else
352352
{
@@ -1363,14 +1363,14 @@ void MCMatch::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
13631363
{
13641364
// AL-2014-09-09: [[ Bug 13359 ]] Make sure containers are used in case a param is a handler variable
13651365
// AL-2014-09-18: [[ Bug 13465 ]] Use auto class to prevent memory leak
1366-
MCAutoPointer<MCContainer> t_container;
1367-
if (!t_result_params->evalcontainer(ctxt, &t_container))
1366+
MCContainer t_container;
1367+
if (!t_result_params->evalcontainer(ctxt, t_container))
13681368
{
13691369
ctxt . LegacyThrow(EE_MATCH_BADDEST);
13701370
return;
13711371
}
13721372

1373-
/* UNCHECKED */ t_container->set_valueref(t_results[i]);
1373+
/* UNCHECKED */ t_container.set_valueref(t_results[i]);
13741374

13751375
t_result_params = t_result_params->getnext();
13761376
}
@@ -2518,11 +2518,11 @@ void MCQueryRegistry::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
25182518
if (!ctxt . EvalExprAsStringRef(key, EE_QUERYREGISTRY_BADEXP, &t_key))
25192519
return;
25202520

2521-
MCAutoPointer<MCContainer> t_container;
2521+
MCContainer t_container;
25222522
MCAutoStringRef t_type;
25232523
if (type != NULL)
25242524
{
2525-
if (!type -> evalcontainer(ctxt, &t_container))
2525+
if (!type -> evalcontainer(ctxt, t_container))
25262526
{
25272527
ctxt . LegacyThrow(EE_QUERYREGISTRY_BADDEST);
25282528
return;
@@ -2539,8 +2539,8 @@ void MCQueryRegistry::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
25392539

25402540
if (!ctxt.HasError())
25412541
{
2542-
if (*t_container != nil)
2543-
/* UNCHECKED */ t_container->set_valueref(*t_type);
2542+
if (type != NULL)
2543+
/* UNCHECKED */ t_container.set_valueref(*t_type);
25442544
}
25452545
}
25462546

engine/src/handler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,9 @@ Exec_stat MCHandler::exec(MCExecContext& ctxt, MCParameter *plist)
358358
}
359359

360360
MCVariable *t_new_var;
361+
/* UNCHECKED */ newparams[i] = new(nothrow) MCContainer;
361362
/* UNCHECKED */ MCVariable::createwithname(i < npnames ? pinfo[i] . name : kMCEmptyName, t_new_var);
362-
/* UNCHECKED */ MCContainer::createwithvariable(t_new_var, newparams[i]);
363+
/* UNCHECKED */ MCContainer::createwithvariable(t_new_var, *newparams[i]);
363364

364365
newparams[i]->give_value(ctxt, t_value);
365366
}
@@ -379,8 +380,9 @@ Exec_stat MCHandler::exec(MCExecContext& ctxt, MCParameter *plist)
379380
break;
380381
}
381382
MCVariable *t_new_var;
383+
/* UNCHECKED */ newparams[i] = new(nothrow) MCContainer;
382384
/* UNCHECKED */ MCVariable::createwithname(i < npnames ? pinfo[i] . name : kMCEmptyName, t_new_var);
383-
/* UNCHECKED */ MCContainer::createwithvariable(t_new_var, newparams[i]);
385+
/* UNCHECKED */ MCContainer::createwithvariable(t_new_var, *newparams[i]);
384386
}
385387
}
386388
if (err)

engine/src/param.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ bool MCParameter::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
144144
return true;
145145
}
146146

147-
bool MCParameter::evalcontainer(MCExecContext &ctxt, MCContainer *&r_container)
147+
bool MCParameter::evalcontainer(MCExecContext &ctxt, MCContainer& r_container)
148148
{
149149
if (exp == NULL)
150150
return false;

0 commit comments

Comments
 (0)