Skip to content

Commit ae1a43a

Browse files
Turn MCObject::parent into an MCObjectHandle
This helps catch any erroneous accesses to parents that have been deleted. Conflicts: engine/src/exec-interface2.cpp engine/src/styledtext.cpp
1 parent a9c9a92 commit ae1a43a

24 files changed

+101
-104
lines changed

engine/src/button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ void MCButton::activate(Boolean notify, KeySym p_key)
19871987
// MH-2007-03-20: [[ Bug 2581 ]] If a radio button is hilited using the keyboard, others in the group are not unhilited (when radioBehavior is set).
19881988
if (parent->gettype() == CT_GROUP)
19891989
{
1990-
MCGroup *gptr = (MCGroup *)parent;
1990+
MCGroup *gptr = parent.GetAs<MCGroup>();
19911991
gptr->radio(0, this);
19921992
}
19931993
reseticon();

engine/src/card.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ void MCCard::timer(MCNameRef mptr, MCParameter *params)
10921092

10931093
bool MCCard::isdeletable(bool p_check_flag)
10941094
{
1095-
if (parent == NULL || scriptdepth != 0 ||
1095+
if (!parent || scriptdepth != 0 ||
10961096
(p_check_flag && getflag(F_C_CANT_DELETE)) ||
10971097
getstack() -> isediting())
10981098
{
@@ -1280,7 +1280,7 @@ Exec_stat MCCard::handle(Handler_type htype, MCNameRef mess, MCParameter *params
12801280
stat = ES_PASS;
12811281
}
12821282

1283-
if (parent != NULL && (stat == ES_PASS || stat == ES_NOT_HANDLED))
1283+
if (parent && (stat == ES_PASS || stat == ES_NOT_HANDLED))
12841284
{
12851285
Exec_stat oldstat = stat;
12861286
stat = parent->handle(htype, mess, params, this);

engine/src/control.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,21 +503,21 @@ Boolean MCControl::del(bool p_check_flag)
503503
{
504504
case CT_CARD:
505505
{
506-
MCCard *cptr = (MCCard *)parent;
506+
MCCard *cptr = parent.GetAs<MCCard>();
507507
if (!cptr->removecontrol(this, False, True))
508508
return False;
509509
getstack()->removecontrol(this);
510510
break;
511511
}
512512
case CT_GROUP:
513513
{
514-
MCGroup *gptr = (MCGroup *)parent;
514+
MCGroup *gptr = parent.GetAs<MCGroup>();
515515
gptr->removecontrol(this, True);
516516
break;
517517
}
518518
default:
519519
{ //stack
520-
MCStack *sptr = (MCStack *)parent;
520+
MCStack *sptr = parent.GetAs<MCStack>();
521521
sptr->removecontrol(this);
522522
}
523523
}
@@ -545,7 +545,7 @@ void MCControl::paste(void)
545545
return;
546546

547547
parent = MCdefaultstackptr->getchild(CT_THIS, kMCEmptyString, CT_CARD);
548-
MCCard *cptr = (MCCard *)parent;
548+
MCCard *cptr = parent.GetAs<MCCard>();
549549
obj_id = 0;
550550
//newcontrol->resetfontindex(oldstack);
551551
if (!MCU_point_in_rect(cptr->getrect(), rect.x + (rect.width >> 1),
@@ -748,7 +748,7 @@ void MCControl::attach(Object_pos p, bool invisible)
748748
if (invisible)
749749
setflag(False, F_VISIBLE);
750750

751-
if (parent == NULL || parent->gettype() == CT_CARD
751+
if (!parent || parent->gettype() == CT_CARD
752752
|| parent->gettype() == CT_STACK)
753753
{
754754
MCCard *card = getcard(cid);
@@ -757,7 +757,7 @@ void MCControl::attach(Object_pos p, bool invisible)
757757
}
758758
else
759759
{
760-
MCGroup *gptr = (MCGroup *)parent;
760+
MCGroup *gptr = parent.GetAs<MCGroup>();
761761
gptr->appendcontrol(this);
762762
}
763763
newmessage();

engine/src/exec-interface-button.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ void MCButton::UpdateIconAndMenus(void)
4949
reseticon();
5050
freemenu(False);
5151
findmenu(true);
52-
if (parent != NULL && parent->gettype() == CT_GROUP)
52+
if (parent && parent->gettype() == CT_GROUP)
5353
{
5454
parent->setstate(True, CS_NEED_UPDATE);
55-
if ((parent == MCmenubar || parent == MCdefaultmenubar) && !MClockmenus)
55+
if ((parent.GetAs<MCGroup>() == MCmenubar || parent.GetAs<MCGroup>() == MCdefaultmenubar) && !MClockmenus)
5656
MCscreen->updatemenubar(True);
5757
}
5858
Redraw();
@@ -1131,10 +1131,10 @@ void MCButton::SetText(MCExecContext& ctxt, MCStringRef p_text)
11311131

11321132
bool t_dirty = (resetlabel() || menumode == WM_TOP_LEVEL);
11331133

1134-
if (parent != NULL && parent->gettype() == CT_GROUP)
1134+
if (parent && parent->gettype() == CT_GROUP)
11351135
{
11361136
parent->setstate(True, CS_NEED_UPDATE);
1137-
if ((parent == MCmenubar || parent == MCdefaultmenubar) && !MClockmenus)
1137+
if ((parent.GetAs<MCGroup>() == MCmenubar || parent.GetAs<MCGroup>() == MCdefaultmenubar) && !MClockmenus)
11381138
MCscreen->updatemenubar(True);
11391139
}
11401140
if (t_dirty)
@@ -1212,7 +1212,7 @@ void MCButton::SetHilite(MCExecContext& ctxt, uint32_t p_part, const MCInterface
12121212
// MH-2007-03-20: [[ Bug 4035 ]] If the hilite of a radio button is set programmatically, other radio buttons were not unhilited if the radiobehavior of the group is set.
12131213
if (getstyleint(flags) == F_RADIO && parent -> gettype() == CT_GROUP)
12141214
{
1215-
MCGroup *gptr = (MCGroup *)parent;
1215+
MCGroup *gptr = parent.GetAs<MCGroup>();
12161216
gptr->radio(p_part, this);
12171217
}
12181218
radio();

engine/src/exec-interface-card.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void MCCard::GetLayer(MCExecContext &ctxt, MCInterfaceLayer &r_layer)
5757

5858
void MCCard::SetLayer(MCExecContext &ctxt, const MCInterfaceLayer &p_layer)
5959
{
60-
if (parent != NULL)
60+
if (parent)
6161
getstack()->renumber(this, p_layer.layer);
6262
}
6363

engine/src/exec-interface-group.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ void MCGroup::SetBackgroundBehavior(MCExecContext& ctxt, bool setting)
492492
void MCGroup::GetSharedBehavior(MCExecContext& ctxt, bool& r_setting)
493493
{
494494
// MW-2011-08-09: [[ Groups ]] Returns whether the group is shared.
495-
r_setting = isshared() && (parent == nil || parent -> gettype() == CT_CARD);
495+
r_setting = isshared() && (!parent || parent -> gettype() == CT_CARD);
496496
}
497497

498498
void MCGroup::SetSharedBehavior(MCExecContext& ctxt, bool setting)

engine/src/exec-interface-object.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ void MCObject::SetId(MCExecContext& ctxt, uint32_t p_new_id)
13551355

13561356
// MW-2011-02-08: Don't allow id change if the parent is nil as this means its a template
13571357
// object which doesn't really have an id.
1358-
if (parent == nil)
1358+
if (!parent)
13591359
return;
13601360

13611361
MCStack *t_stack;
@@ -1394,7 +1394,7 @@ void MCObject::SetId(MCExecContext& ctxt, uint32_t p_new_id)
13941394
t_stack -> visit(VISIT_STYLE_DEPTH_FIRST, 0, &t_visitor);
13951395
}
13961396
else if (parent -> gettype() == CT_CARD)
1397-
static_cast<MCCard *>(parent) -> resetid(obj_id, p_new_id);
1397+
parent.GetAs<MCCard>()->resetid(obj_id, p_new_id);
13981398

13991399
// MW-2012-10-10: [[ IdCache ]] If the object is in the cache, then remove
14001400
// it since its id is changing.
@@ -1520,7 +1520,7 @@ void MCObject::GetLayer(MCExecContext& ctxt, uint32_t part, MCInterfaceLayer& r_
15201520
// the group being edited in edit group mode.
15211521

15221522
uint2 num = 0;
1523-
if (parent != nil)
1523+
if (parent)
15241524
{
15251525
MCCard *t_card;
15261526
t_card = getcard(part);
@@ -1543,7 +1543,7 @@ void MCObject::GetLayer(MCExecContext& ctxt, uint32_t part, MCInterfaceLayer& r_
15431543

15441544
void MCObject::SetLayer(MCExecContext& ctxt, uint32_t part, const MCInterfaceLayer& p_layer)
15451545
{
1546-
if (parent == NULL || getcard(part)->relayer((MCControl *)this, p_layer . layer) != ES_NORMAL)
1546+
if (!parent || getcard(part)->relayer((MCControl *)this, p_layer . layer) != ES_NORMAL)
15471547
ctxt . LegacyThrow(EE_OBJECT_BADRELAYER);
15481548
}
15491549

@@ -2110,7 +2110,7 @@ bool MCObject::GetColor(MCExecContext& ctxt, Properties which, bool effective, M
21102110
bool t_found;
21112111
t_found = false;
21122112

2113-
if (parent != NULL)
2113+
if (parent)
21142114
t_found = parent -> GetColor(ctxt, which, effective, r_color, true);
21152115

21162116
if (!t_found && !recursive)
@@ -2447,7 +2447,7 @@ bool MCObject::GetPattern(MCExecContext& ctxt, Properties which, bool effective,
24472447
{
24482448
if (effective)
24492449
{
2450-
if (parent != NULL)
2450+
if (parent)
24512451
return parent->GetPattern(ctxt, which, effective, r_pattern);
24522452
else
24532453
{
@@ -2781,7 +2781,7 @@ bool MCObject::TextPropertyMapFont()
27812781
// *not* to attempt to mapfonts on it!
27822782
// MW-2013-03-28: [[ Bug 10791 ]] Exceptions to every rule - the home stack
27832783
// can be open but with no font...
2784-
if ((opened == 0 || m_font == nil) && gettype() == CT_STACK && parent != nil)
2784+
if ((opened == 0 || m_font == nil) && gettype() == CT_STACK && parent)
27852785
{
27862786
mapfont();
27872787
return true;
@@ -2895,7 +2895,7 @@ void MCObject::SetTextFont(MCExecContext& ctxt, MCStringRef font)
28952895
// to ensure substacks update properly.
28962896
// MW-2013-03-21: [[ Bug ]] Unless its the templateStack (parent == nil) in which
28972897
// case we don't want to do any font recomputation.
2898-
if ((gettype() == CT_STACK && parent != nil) || opened)
2898+
if ((gettype() == CT_STACK && parent) || opened)
28992899
{
29002900
if (recomputefonts(parent -> getfontref()))
29012901
{
@@ -2960,7 +2960,7 @@ void MCObject::SetTextSize(MCExecContext& ctxt, uinteger_t* size)
29602960
// to ensure substacks update properly.
29612961
// MW-2013-03-21: [[ Bug ]] Unless its the templateStack (parent == nil) in which
29622962
// case we don't want to do any font recomputation.
2963-
if ((gettype() == CT_STACK && parent != nil) || opened)
2963+
if ((gettype() == CT_STACK && parent) || opened)
29642964
{
29652965
if (recomputefonts(parent -> getfontref()))
29662966
{
@@ -3015,7 +3015,7 @@ void MCObject::SetTextStyle(MCExecContext& ctxt, const MCInterfaceTextStyle& p_s
30153015
// to ensure substacks update properly.
30163016
// MW-2013-03-21: [[ Bug ]] Unless its the templateStack (parent == nil) in which
30173017
// case we don't want to do any font recomputation.
3018-
if ((gettype() == CT_STACK && parent != nil) || opened)
3018+
if ((gettype() == CT_STACK && parent) || opened)
30193019
{
30203020
if (recomputefonts(parent -> getfontref()))
30213021
{
@@ -3034,7 +3034,7 @@ void MCObject::GetEffectiveTextStyle(MCExecContext& ctxt, MCInterfaceTextStyle&
30343034
{
30353035
if ((m_font_flags & FF_HAS_TEXTSIZE) == 0)
30363036
{
3037-
if (parent != nil)
3037+
if (parent)
30383038
parent -> GetEffectiveTextStyle(ctxt, r_style);
30393039
else
30403040
MCdispatcher -> GetDefaultTextStyle(ctxt, r_style);
@@ -3274,25 +3274,25 @@ void MCObject::SetTraversalOn(MCExecContext& ctxt, bool setting)
32743274

32753275
void MCObject::GetOwner(MCExecContext& ctxt, MCStringRef& r_owner)
32763276
{
3277-
if (parent != nil)
3277+
if (parent)
32783278
parent -> GetName(ctxt, r_owner);
32793279
}
32803280

32813281
void MCObject::GetShortOwner(MCExecContext& ctxt, MCStringRef& r_owner)
32823282
{
3283-
if (parent != nil)
3283+
if (parent)
32843284
parent -> GetShortName(ctxt, r_owner);
32853285
}
32863286

32873287
void MCObject::GetAbbrevOwner(MCExecContext& ctxt, MCStringRef& r_owner)
32883288
{
3289-
if (parent != nil)
3289+
if (parent)
32903290
parent -> GetAbbrevName(ctxt, r_owner);
32913291
}
32923292

32933293
void MCObject::GetLongOwner(MCExecContext& ctxt, uint32_t p_part_id, MCStringRef& r_owner)
32943294
{
3295-
if (parent != nil)
3295+
if (parent)
32963296
parent -> GetLongName(ctxt, p_part_id, r_owner);
32973297
}
32983298

@@ -3713,7 +3713,7 @@ void MCObject::SetBlendLevel(MCExecContext& ctxt, uinteger_t level)
37133713
if (gettype() < CT_GROUP || !static_cast<MCControl *>(this) -> layer_issprite())
37143714
Redraw();
37153715
else
3716-
static_cast<MCCard *>(parent) -> layer_dirtyrect(static_cast<MCControl *>(this) -> geteffectiverect());
3716+
parent.GetAs<MCCard>()->layer_dirtyrect(static_cast<MCControl *>(this) -> geteffectiverect());
37173717
}
37183718
}
37193719

engine/src/exec-interface-stack.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,10 @@ void MCStack::GetNumber(MCExecContext& ctxt, uinteger_t& r_number)
495495
{
496496
uint2 num;
497497

498-
if (parent != nil && !MCdispatcher -> ismainstack(this))
498+
if (parent && !MCdispatcher -> ismainstack(this))
499499
{
500500
MCStack *sptr;
501-
sptr = (MCStack *)parent;
501+
sptr = parent.GetAs<MCStack>();
502502
sptr -> count(CT_STACK, CT_UNDEFINED, this, num);
503503
}
504504
else
@@ -534,7 +534,7 @@ void MCStack::GetEffectiveFileName(MCExecContext& ctxt, MCStringRef& r_file_name
534534
if (!MCdispatcher -> ismainstack(this))
535535
{
536536
MCStack *sptr;
537-
sptr = (MCStack *)parent;
537+
sptr = parent.GetAs<MCStack>();
538538
sptr -> GetEffectiveFileName(ctxt, r_file_name);
539539
return;
540540
}
@@ -1006,16 +1006,16 @@ void MCStack::SetIcon(MCExecContext& ctxt, uinteger_t p_id)
10061006

10071007
void MCStack::GetOwner(MCExecContext& ctxt, MCStringRef& r_owner)
10081008
{
1009-
if (parent != nil && !MCdispatcher -> ismainstack(this))
1009+
if (parent && !MCdispatcher -> ismainstack(this))
10101010
parent -> GetLongId(ctxt, 0, r_owner);
10111011
}
10121012

10131013
void MCStack::GetMainStack(MCExecContext& ctxt, MCStringRef& r_main_stack)
10141014
{
10151015
MCStack *sptr = this;
10161016

1017-
if (parent != nil && !MCdispatcher->ismainstack(sptr))
1018-
sptr = (MCStack *)parent;
1017+
if (parent && !MCdispatcher->ismainstack(sptr))
1018+
sptr = parent.GetAs<MCStack>();
10191019

10201020
r_main_stack = MCValueRetain(MCNameGetString(sptr->getname()));
10211021
}
@@ -1038,7 +1038,7 @@ void MCStack::SetMainStack(MCExecContext& ctxt, MCStringRef p_main_stack)
10381038
return;
10391039
}
10401040

1041-
if (parent != nil && this != MCdispatcher -> gethome() && (substacks == nil || stackptr == this))
1041+
if (parent && this != MCdispatcher -> gethome() && (substacks == nil || stackptr == this))
10421042
{
10431043
bool t_this_is_mainstack;
10441044
t_this_is_mainstack = MCdispatcher -> ismainstack(this) == True;
@@ -1058,7 +1058,7 @@ void MCStack::SetMainStack(MCExecContext& ctxt, MCStringRef p_main_stack)
10581058
MCdispatcher -> removestack(this);
10591059
else
10601060
{
1061-
MCStack *pstack = (MCStack *)parent;
1061+
MCStack *pstack = parent.GetAs<MCStack>();
10621062
remove(pstack -> substacks);
10631063
// MW-2012-09-07: [[ Bug 10372 ]] If the stack no longer has substacks, then
10641064
// make sure we undo the extraopen.

engine/src/exec-interface2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ void MCInterfaceDoRelayer(MCExecContext& ctxt, int p_relation, MCObjectPtr p_sou
37723772
MCObjectHandle t_source_handle, t_new_owner_handle, t_new_target_handle;
37733773
t_source_handle = p_source . object -> GetHandle();
37743774
t_new_owner_handle = t_new_owner -> GetHandle();
3775-
t_new_target_handle = t_new_target != nil ? t_new_target -> GetHandle() : nil;
3775+
t_new_target_handle = t_new_target != nil ? t_new_target : nil;
37763776

37773777
// Make sure we remove focus from the control.
37783778
bool t_was_mfocused, t_was_kfocused;

engine/src/group.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ void MCGroup::applyrect(const MCRectangle &nrect)
10331033

10341034
bool MCGroup::isdeletable(bool p_check_flag)
10351035
{
1036-
if (parent == NULL || scriptdepth != 0 ||
1036+
if (!parent || scriptdepth != 0 ||
10371037
(p_check_flag && getflag(F_G_CANT_DELETE)))
10381038
{
10391039
MCAutoValueRef t_long_name;
@@ -1868,9 +1868,9 @@ void MCGroup::clearfocus(MCControl *cptr)
18681868
kfocused = NULL;
18691869
state &= ~CS_KFOCUSED;
18701870
if (parent -> gettype() == CT_CARD)
1871-
static_cast<MCCard *>(parent) -> erasefocus(this);
1871+
parent.GetAs<MCCard>()->erasefocus(this);
18721872
else
1873-
static_cast<MCGroup *>(parent) -> clearfocus(this);
1873+
parent.GetAs<MCGroup>()->clearfocus(this);
18741874
}
18751875
}
18761876

0 commit comments

Comments
 (0)