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

Commit e096b9b

Browse files
committed
libfoundation: Add type checks to exported MCSet functions.
1 parent 3c55877 commit e096b9b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

libfoundation/src/foundation-set.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ bool MCSetCreateSingleton(uindex_t p_element, MCSetRef& r_set)
3131

3232
bool MCSetCreateWithIndices(uindex_t *p_elements, uindex_t p_element_count, MCSetRef& r_set)
3333
{
34+
if (p_element_count == 0)
35+
{
36+
if (nil != kMCEmptySet)
37+
{
38+
r_set = MCValueRetain(kMCEmptySet);
39+
return true;
40+
}
41+
}
42+
else
43+
{
44+
MCAssert(nil != p_elements);
45+
}
46+
3447
MCSetRef t_set;
3548
if (!MCSetCreateMutable(t_set))
3649
return false;
@@ -43,6 +56,8 @@ bool MCSetCreateWithIndices(uindex_t *p_elements, uindex_t p_element_count, MCSe
4356

4457
bool MCSetCreateWithLimbsAndRelease(uindex_t *p_limbs, uindex_t p_limb_count, MCSetRef& r_set)
4558
{
59+
MCAssert(nil != p_limbs);
60+
4661
__MCSet *self;
4762
if (!__MCValueCreate(kMCValueTypeCodeSet, self))
4863
return false;
@@ -72,6 +87,8 @@ bool MCSetCreateMutable(MCSetRef& r_set)
7287

7388
bool MCSetCopy(MCSetRef self, MCSetRef& r_new_set)
7489
{
90+
__MCAssertIsSet(self);
91+
7592
if (!MCSetIsMutable(self))
7693
{
7794
r_new_set = MCValueRetain(self);
@@ -82,6 +99,8 @@ bool MCSetCopy(MCSetRef self, MCSetRef& r_new_set)
8299

83100
bool MCSetCopyAndRelease(MCSetRef self, MCSetRef& r_new_set)
84101
{
102+
__MCAssertIsSet(self);
103+
85104
if (!MCSetIsMutable(self))
86105
{
87106
r_new_set = self;
@@ -100,11 +119,14 @@ bool MCSetCopyAndRelease(MCSetRef self, MCSetRef& r_new_set)
100119

101120
bool MCSetMutableCopy(MCSetRef self, MCSetRef& r_new_set)
102121
{
122+
__MCAssertIsSet(self);
103123
return __MCSetClone(self, true, r_new_set);
104124
}
105125

106126
bool MCSetMutableCopyAndRelease(MCSetRef self, MCSetRef& r_new_set)
107127
{
128+
__MCAssertIsSet(self);
129+
108130
if (self -> references == 1)
109131
{
110132
self -> flags |= kMCSetFlagIsMutable;
@@ -119,13 +141,17 @@ bool MCSetMutableCopyAndRelease(MCSetRef self, MCSetRef& r_new_set)
119141

120142
bool MCSetIsMutable(MCSetRef self)
121143
{
144+
__MCAssertIsSet(self);
145+
122146
return (self -> flags & kMCSetFlagIsMutable) != 0;
123147
}
124148

125149
////////////////////////////////////////////////////////////////////////////////
126150

127151
bool MCSetIsEmpty(MCSetRef self)
128152
{
153+
__MCAssertIsSet(self);
154+
129155
for(uindex_t i = 0; i < self -> limb_count; i++)
130156
if (self -> limbs[i] != 0)
131157
return false;
@@ -134,6 +160,9 @@ bool MCSetIsEmpty(MCSetRef self)
134160

135161
bool MCSetIsEqualTo(MCSetRef self, MCSetRef other_self)
136162
{
163+
__MCAssertIsSet(self);
164+
__MCAssertIsSet(other_self);
165+
137166
for(uindex_t i = 0; i < MCMax(self -> limb_count, other_self -> limb_count); i++)
138167
{
139168
uindex_t t_left_limb, t_right_limb;
@@ -148,6 +177,9 @@ bool MCSetIsEqualTo(MCSetRef self, MCSetRef other_self)
148177

149178
bool MCSetContains(MCSetRef self, MCSetRef other_self)
150179
{
180+
__MCAssertIsSet(self);
181+
__MCAssertIsSet(other_self);
182+
151183
for(uindex_t i = 0; i < MCMax(self -> limb_count, other_self -> limb_count); i++)
152184
{
153185
uindex_t t_left_limb, t_right_limb;
@@ -161,6 +193,9 @@ bool MCSetContains(MCSetRef self, MCSetRef other_self)
161193

162194
bool MCSetIntersects(MCSetRef self, MCSetRef other_self)
163195
{
196+
__MCAssertIsSet(self);
197+
__MCAssertIsSet(other_self);
198+
164199
for(uindex_t i = 0; i < MCMax(self -> limb_count, other_self -> limb_count); i++)
165200
{
166201
uindex_t t_left_limb, t_right_limb;
@@ -174,6 +209,8 @@ bool MCSetIntersects(MCSetRef self, MCSetRef other_self)
174209

175210
bool MCSetContainsIndex(MCSetRef self, uindex_t p_element)
176211
{
212+
__MCAssertIsSet(self);
213+
177214
if (p_element >= self -> limb_count * 32)
178215
return false;
179216
return (self -> limbs[p_element / 32] & (1 << (p_element % 32))) != 0;
@@ -253,6 +290,8 @@ bool MCSetIntersect(MCSetRef self, MCSetRef p_other_set)
253290

254291
bool MCSetIterate(MCSetRef self, uindex_t& x_iterator, uindex_t& r_element)
255292
{
293+
__MCAssertIsSet(self);
294+
256295
while(x_iterator < self -> limb_count * 32)
257296
{
258297
x_iterator++;

0 commit comments

Comments
 (0)