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

Commit c7d9de2

Browse files
committed
[[ Bug 17199 ]] Remove unnecessary 'NumberExpected' context var.
The use-case for the NumberExpected state variable in ExecContext has been removed as it caused this bug. It's previous purpose (to optimize evaluation of numeric literals) should be more than catered for by the subsequent optimization of allowing an immutable StringRef to store its numeric value directly.
1 parent aa44f86 commit c7d9de2

7 files changed

Lines changed: 4 additions & 159 deletions

File tree

engine/src/cmdsm.cpp

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,10 @@ void MCAdd::exec_ctxt(MCExecContext &ctxt)
186186
#endif /* MCAdd */
187187

188188
MCExecValue t_src;
189-
Boolean t_old_expectation;
190-
191-
// SN-2014-04-08 [[ NumberExpectation ]] Ensure we get a number when it's possible instead of a ValueRef
192-
t_old_expectation = ctxt . GetNumberExpected();
193-
ctxt . SetNumberExpected(True);
194-
189+
195190
if (!ctxt . EvaluateExpression(source, EE_ADD_BADSOURCE, t_src)
196191
|| !ctxt . ConvertToNumberOrArray(t_src))
197192
{
198-
ctxt . SetNumberExpected(t_old_expectation);
199193
return;
200194
}
201195

@@ -217,7 +211,6 @@ void MCAdd::exec_ctxt(MCExecContext &ctxt)
217211
{
218212
ctxt . LegacyThrow(EE_ADD_BADDEST);
219213
MCExecTypeRelease(t_src);
220-
ctxt . SetNumberExpected(t_old_expectation);
221214
return;
222215
}
223216

@@ -227,13 +220,9 @@ void MCAdd::exec_ctxt(MCExecContext &ctxt)
227220
if (!ctxt . EvaluateExpression(dest, EE_ADD_BADDEST, t_dst))
228221
{
229222
MCExecTypeRelease(t_src);
230-
ctxt . SetNumberExpected(t_old_expectation);
231223
return;
232224
}
233-
}
234-
235-
// Set the number expectation back to its previous state
236-
ctxt . SetNumberExpected(t_old_expectation);
225+
}
237226

238227
if (!ctxt . ConvertToNumberOrArray(t_dst))
239228
{
@@ -453,16 +442,10 @@ void MCDivide::exec_ctxt(MCExecContext &ctxt)
453442
#endif /* MCDivide */
454443

455444
MCExecValue t_src;
456-
Boolean t_old_expectation;
457-
458-
// SN-2014-04-08 [[ NumberExpectation ]] Ensure we get a number when it's possible instead of a ValueRef
459-
t_old_expectation = ctxt . GetNumberExpected();
460-
ctxt . SetNumberExpected(True);
461445

462446
if (!ctxt . EvaluateExpression(source, EE_DIVIDE_BADSOURCE, t_src)
463447
|| !ctxt . ConvertToNumberOrArray(t_src))
464448
{
465-
ctxt . SetNumberExpected(t_old_expectation);
466449
return;
467450
}
468451

@@ -484,7 +467,6 @@ void MCDivide::exec_ctxt(MCExecContext &ctxt)
484467
{
485468
ctxt . LegacyThrow(EE_DIVIDE_BADDEST);
486469
MCExecTypeRelease(t_src);
487-
ctxt . SetNumberExpected(t_old_expectation);
488470
return;
489471
}
490472
}
@@ -493,13 +475,9 @@ void MCDivide::exec_ctxt(MCExecContext &ctxt)
493475
if (!ctxt . EvaluateExpression(dest, EE_DIVIDE_BADDEST, t_dst))
494476
{
495477
MCExecTypeRelease(t_src);
496-
ctxt . SetNumberExpected(t_old_expectation);
497478
return;
498479
}
499480
}
500-
501-
// Set the number expectation back to its previous state
502-
ctxt . SetNumberExpected(t_old_expectation);
503481

504482
if (!ctxt . ConvertToNumberOrArray(t_dst))
505483
{
@@ -718,16 +696,10 @@ void MCMultiply::exec_ctxt(MCExecContext &ctxt)
718696
#endif /* MCMultiply */
719697

720698
MCExecValue t_src;
721-
Boolean t_old_expectation;
722-
723-
// SN-2014-04-08 [[ NumberExpectation ]] Ensure we get a number when it's possible instead of a ValueRef
724-
t_old_expectation = ctxt . GetNumberExpected();
725-
ctxt . SetNumberExpected(True);
726699

727700
if(!ctxt . EvaluateExpression(source, EE_MULTIPLY_BADSOURCE, t_src)
728701
|| !ctxt . ConvertToNumberOrArray(t_src))
729702
{
730-
ctxt . SetNumberExpected(t_old_expectation);
731703
return;
732704
}
733705

@@ -749,7 +721,6 @@ void MCMultiply::exec_ctxt(MCExecContext &ctxt)
749721
{
750722
ctxt . LegacyThrow(EE_MULTIPLY_BADDEST);
751723
MCExecTypeRelease(t_src);
752-
ctxt . SetNumberExpected(t_old_expectation);
753724
return;
754725
}
755726
}
@@ -758,13 +729,9 @@ void MCMultiply::exec_ctxt(MCExecContext &ctxt)
758729
if (!ctxt . EvaluateExpression(dest, EE_MULTIPLY_BADDEST, t_dst))
759730
{
760731
MCExecTypeRelease(t_src);
761-
ctxt . SetNumberExpected(t_old_expectation);
762732
return;
763733
}
764734
}
765-
766-
// Set the number expectation back to the previous state
767-
ctxt . SetNumberExpected(t_old_expectation);
768735

769736
if (!ctxt . ConvertToNumberOrArray(t_dst))
770737
{
@@ -966,16 +933,10 @@ void MCSubtract::exec_ctxt(MCExecContext &ctxt)
966933
#endif /* MCSubtract */
967934

968935
MCExecValue t_src;
969-
Boolean t_old_expectation;
970-
971-
// SN-2014-04-08 [[ NumberExpectation ]] Ensure we get a number when it's possible instead of a ValueRef
972-
t_old_expectation = ctxt . GetNumberExpected();
973-
ctxt . SetNumberExpected(True);
974936

975937
if (!ctxt . EvaluateExpression(source, EE_SUBTRACT_BADSOURCE, t_src)
976938
|| !ctxt . ConvertToNumberOrArray(t_src))
977939
{
978-
ctxt . SetNumberExpected(t_old_expectation);
979940
return;
980941
}
981942

@@ -997,7 +958,6 @@ void MCSubtract::exec_ctxt(MCExecContext &ctxt)
997958
{
998959
ctxt . LegacyThrow(EE_SUBTRACT_BADDEST);
999960
MCExecTypeRelease(t_src);
1000-
ctxt . SetNumberExpected(t_old_expectation);
1001961
return;
1002962
}
1003963
}
@@ -1006,13 +966,9 @@ void MCSubtract::exec_ctxt(MCExecContext &ctxt)
1006966
if (!ctxt . EvaluateExpression(dest, EE_SUBTRACT_BADDEST, t_dst))
1007967
{
1008968
MCExecTypeRelease(t_src);
1009-
ctxt . SetNumberExpected(t_old_expectation);
1010969
return;
1011970
}
1012971
}
1013-
1014-
// Set the number expectation back to its previous state
1015-
ctxt . SetNumberExpected(t_old_expectation);
1016972

1017973
if (!ctxt . ConvertToNumberOrArray(t_dst))
1018974
{

engine/src/exec.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,6 @@ bool MCExecContext::TryToEvaluateExpressionAsDouble(MCExpression *p_expr, uint2
821821

822822
bool t_failure, t_can_debug;
823823
t_can_debug = true;
824-
825-
// SN-2014-04-08 [[ NumberExpectation ]] Ensure we get a number when it's possible instead of a ValueRef
826-
Boolean t_old_expectation = m_numberexpected;
827-
m_numberexpected = True;
828824

829825
MCExecValue t_value;
830826
double t_result;
@@ -862,8 +858,7 @@ bool MCExecContext::TryToEvaluateExpressionAsDouble(MCExpression *p_expr, uint2
862858
r_result = t_value . float_value;
863859
else
864860
r_result = t_value . double_value;
865-
866-
m_numberexpected = t_old_expectation;
861+
867862
return true;
868863
}
869864

@@ -958,23 +953,17 @@ static bool EvalExprAsStrictNumber(MCExecContext* self, MCExpression *p_expr, Ex
958953
{
959954
MCAssert(p_expr != nil);
960955

961-
// SN-2014-04-08 [[ NumberExpectation ]] Ensure we get a number when it's possible instead of a ValueRef
962956
MCExecValue t_value;
963-
Boolean t_number_expected = self -> GetNumberExpected();
964-
self -> SetNumberExpected(True);
965-
957+
966958
p_expr -> eval_ctxt(*self, t_value);
967959

968960
if (t_value . type == kMCExecValueTypeNone
969961
|| (MCExecTypeIsValueRef(t_value . type) && MCValueIsEmpty(t_value . valueref_value)))
970962
{
971963
self -> LegacyThrow(p_error);
972-
973964
return false;
974965
}
975966

976-
self -> SetNumberExpected(t_number_expected);
977-
978967
if (!self -> HasError())
979968
MCExecTypeConvertAndReleaseAlways(*self, t_value . type, &t_value, p_type, &r_value);
980969

@@ -995,15 +984,10 @@ static bool EvalExprAsNumber(MCExecContext* self, MCExpression *p_expr, Exec_err
995984
{
996985
MCAssert(p_expr != nil);
997986

998-
// SN-2014-04-08 [[ NumberExpectation ]] Ensure we get a number when it's possible instead of a ValueRef
999987
MCExecValue t_value;
1000-
Boolean t_number_expected = self -> GetNumberExpected();
1001-
self -> SetNumberExpected(True);
1002988

1003989
p_expr -> eval_ctxt(*self, t_value);
1004990

1005-
self -> SetNumberExpected(t_number_expected);
1006-
1007991
if (!self -> HasError())
1008992
MCExecTypeConvertAndReleaseAlways(*self, t_value . type, &t_value, p_type, &r_value);
1009993

engine/src/exec.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,11 +1423,6 @@ class MCExecContext
14231423
{
14241424
return m_nfforce;
14251425
}
1426-
1427-
Boolean GetNumberExpected() const
1428-
{
1429-
return m_numberexpected;
1430-
}
14311426

14321427
//////////
14331428

@@ -1498,11 +1493,6 @@ class MCExecContext
14981493
{
14991494
MCValueAssign(m_rowdel, p_value);
15001495
}
1501-
1502-
void SetNumberExpected(Boolean p_value)
1503-
{
1504-
m_numberexpected = (bool)p_value;
1505-
}
15061496

15071497
//////////
15081498

@@ -1819,10 +1809,6 @@ class MCExecContext
18191809
bool m_wholematches : 1;
18201810
bool m_usesystemdate : 1;
18211811
bool m_useunicode : 1;
1822-
// SN-2014-04-08 [[ NumberExpectation ]]
1823-
// New property allowing to specify, when evaluating a literal number,
1824-
// that we expect a number over a valueref
1825-
bool m_numberexpected : 1;
18261812
};
18271813

18281814
////////////////////////////////////////////////////////////////////////////////

engine/src/literal.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,4 @@ void MCLiteral::compile(MCSyntaxFactoryRef ctxt)
5353
MCSyntaxFactoryEndExpression(ctxt);
5454
}
5555

56-
Parse_stat MCLiteralNumber::parse(MCScriptPoint &sp, Boolean the)
57-
{
58-
initpoint(sp);
59-
return PS_NORMAL;
60-
}
6156

62-
void MCLiteralNumber::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
63-
{
64-
// IM-2013-05-02: *TODO* the bugfix here cannot be applied to the syntax
65-
// refactor branch as MCExecPoint::setboth() does not exist there
66-
#ifdef OLD_EXEC
67-
// MW-2013-04-12: [[ Bug 10837 ]] Make sure we set 'both' when evaluating the
68-
// literal. Not doing this causes problems for things like 'numberFormat'.
69-
if (nvalue == BAD_NUMERIC)
70-
ep.setvalueref_nullable(value);
71-
else
72-
ep.setboth(MCNameGetOldString(value), nvalue);
73-
return ES_NORMAL;
74-
#else
75-
// SN-2014-04-08 [[ NumberExpectation ]]
76-
// Ensure we return a number when it's possible and asked for, instead of a ValueRef
77-
if (ctxt . GetNumberExpected() && nvalue != BAD_NUMERIC)
78-
{
79-
MCExecValueTraits<double>::set(r_value, nvalue);
80-
}
81-
else
82-
{
83-
r_value . type = kMCExecValueTypeValueRef;
84-
r_value . valueref_value = MCValueRetain(value);
85-
}
86-
#endif
87-
}

engine/src/literal.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,4 @@ class MCLiteral : public MCExpression
4040
virtual void compile(MCSyntaxFactoryRef ctxt);
4141
};
4242

43-
class MCLiteralNumber : public MCExpression
44-
{
45-
MCValueRef value;
46-
double nvalue;
47-
public:
48-
MCLiteralNumber(MCValueRef v, double n)
49-
{
50-
/* UNCHECKED */ value = MCValueRetain(v);
51-
nvalue = n;
52-
}
53-
~MCLiteralNumber(void)
54-
{
55-
MCValueRelease(value);
56-
}
57-
58-
virtual Parse_stat parse(MCScriptPoint &, Boolean the);
59-
virtual void eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value);
60-
};
61-
6243
#endif

engine/src/operator.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,6 @@ void MCMinus::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
621621
#endif /* MCMinus */
622622

623623
MCExecValue t_left, t_right;
624-
625-
Boolean t_old_expectation;
626-
627-
t_old_expectation = ctxt . GetNumberExpected();
628-
ctxt . SetNumberExpected(True);
629624

630625
if (left == nil)
631626
{
@@ -635,21 +630,16 @@ void MCMinus::eval_ctxt(MCExecContext &ctxt, MCExecValue &r_value)
635630
|| !ctxt . ConvertToNumberOrArray(t_left))
636631
{
637632
ctxt . LegacyThrow(EE_MINUS_BADLEFT);
638-
ctxt . SetNumberExpected(t_old_expectation);
639633
return;
640634
}
641635

642636
if (right -> eval_ctxt(ctxt, t_right), ctxt . HasError()
643637
|| !ctxt . ConvertToNumberOrArray(t_right))
644638
{
645639
ctxt . LegacyThrow(EE_MINUS_BADRIGHT);
646-
ctxt . SetNumberExpected(t_old_expectation);
647640
MCExecTypeRelease(t_left);
648641
return;
649642
}
650-
651-
// Set the number expectation back to its previous state
652-
ctxt . SetNumberExpected(t_old_expectation);
653643

654644
r_value . valueref_value = nil;
655645
if (t_left. type == kMCExecValueTypeArrayRef)

0 commit comments

Comments
 (0)