@@ -60,6 +60,20 @@ static bool __MCArrayFindKeyValueSlot(__MCArray *self, bool case_sensitive, MCNa
6060MC_DLLEXPORT_DEF
6161bool MCArrayCreate (bool p_case_sensitive, const MCNameRef *p_keys, const MCValueRef *p_values, uindex_t p_length, MCArrayRef& r_array)
6262{
63+ if (p_length == 0 )
64+ {
65+ if (nil != kMCEmptyArray )
66+ {
67+ r_array = MCValueRetain (kMCEmptyArray );
68+ return true ;
69+ }
70+ }
71+ else
72+ {
73+ MCAssert (nil != p_keys);
74+ MCAssert (nil != p_values);
75+ }
76+
6377 bool t_success;
6478 t_success = true ;
6579
@@ -132,6 +146,8 @@ bool MCArrayCreateMutableWithOptions(MCArrayRef& r_array, bool p_case_sensitive,
132146MC_DLLEXPORT_DEF
133147bool MCArrayCopy (MCArrayRef self, MCArrayRef& r_new_array)
134148{
149+ __MCAssertIsArray (self);
150+
135151 // If we aren't mutable, then we can just copy directly.
136152 if (!MCArrayIsMutable (self))
137153 {
@@ -162,6 +178,8 @@ bool MCArrayCopy(MCArrayRef self, MCArrayRef& r_new_array)
162178MC_DLLEXPORT_DEF
163179bool MCArrayCopyAndRelease (MCArrayRef self, MCArrayRef& r_new_array)
164180{
181+ __MCAssertIsArray (self);
182+
165183 // If we aren't mutable, then new array is just us.
166184 if (!MCArrayIsMutable (self))
167185 {
@@ -208,6 +226,8 @@ bool MCArrayCopyAndRelease(MCArrayRef self, MCArrayRef& r_new_array)
208226MC_DLLEXPORT_DEF
209227bool MCArrayMutableCopy (MCArrayRef self, MCArrayRef& r_new_array)
210228{
229+ __MCAssertIsArray (self);
230+
211231 // If the array is immutable, then the new mutable array will be indirect
212232 // referencing it. [ non-mutable arrays cannot be indirect so self does not
213233 // need resolving ].
@@ -235,6 +255,8 @@ bool MCArrayMutableCopy(MCArrayRef self, MCArrayRef& r_new_array)
235255MC_DLLEXPORT_DEF
236256bool MCArrayMutableCopyAndRelease (MCArrayRef self, MCArrayRef& r_new_array)
237257{
258+ __MCAssertIsArray (self);
259+
238260 if (self -> references == 1 )
239261 {
240262 if (!MCArrayIsMutable (self))
@@ -254,6 +276,9 @@ bool MCArrayMutableCopyAndRelease(MCArrayRef self, MCArrayRef& r_new_array)
254276MC_DLLEXPORT_DEF
255277bool MCArrayApply (MCArrayRef self, MCArrayApplyCallback p_callback, void *p_context)
256278{
279+ __MCAssertIsArray (self);
280+ MCAssert (nil != p_callback);
281+
257282 // Make sure we are iterating over the correct contents.
258283 MCArrayRef t_contents;
259284 if (!__MCArrayIsIndirect (self))
@@ -283,6 +308,8 @@ bool MCArrayApply(MCArrayRef self, MCArrayApplyCallback p_callback, void *p_cont
283308MC_DLLEXPORT_DEF
284309bool MCArrayIterate (MCArrayRef self, uintptr_t & x_iterator, MCNameRef& r_key, MCValueRef& r_value)
285310{
311+ __MCAssertIsArray (self);
312+
286313 // Make sure we are iterating over the correct contents.
287314 MCArrayRef t_contents;
288315 if (!__MCArrayIsIndirect (self))
@@ -314,12 +341,16 @@ bool MCArrayIterate(MCArrayRef self, uintptr_t& x_iterator, MCNameRef& r_key, MC
314341MC_DLLEXPORT_DEF
315342bool MCArrayIsMutable (MCArrayRef self)
316343{
344+ __MCAssertIsArray (self);
345+
317346 return (self -> flags & kMCArrayFlagIsMutable ) != 0 ;
318347}
319348
320349MC_DLLEXPORT_DEF
321350uindex_t MCArrayGetCount (MCArrayRef self)
322351{
352+ __MCAssertIsArray (self);
353+
323354 if (!__MCArrayIsIndirect (self))
324355 return self -> key_value_count;
325356 return self -> contents -> key_value_count;
@@ -348,6 +379,11 @@ bool MCArrayFetchValue(MCArrayRef self, bool p_case_sensitive, MCNameRef p_key,
348379MC_DLLEXPORT_DEF
349380bool MCArrayFetchValueOnPath (MCArrayRef self, bool p_case_sensitive, const MCNameRef *p_path, uindex_t p_path_length, MCValueRef& r_value)
350381{
382+ __MCAssertIsArray (self);
383+ MCAssert (nil != p_path);
384+ MCAssert (0 < p_path_length);
385+ __MCAssertIsName (p_path[0 ]);
386+
351387 // If the array is indirect, get the contents.
352388 MCArrayRef t_contents;
353389 if (!__MCArrayIsIndirect (self))
@@ -392,6 +428,9 @@ bool MCArrayStoreValueOnPath(MCArrayRef self, bool p_case_sensitive, const MCNam
392428{
393429 // The array must be mutable.
394430 MCAssert (MCArrayIsMutable (self));
431+ MCAssert (nil != p_path);
432+ MCAssert (0 < p_path_length);
433+ __MCAssertIsName (p_path[0 ]);
395434
396435 // Ensure it is not indirect.
397436 if (__MCArrayIsIndirect (self))
@@ -493,6 +532,8 @@ bool MCArrayRemoveValueOnPath(MCArrayRef self, bool p_case_sensitive, const MCNa
493532{
494533 // The array must be mutable.
495534 MCAssert (MCArrayIsMutable (self));
535+ MCAssert (nil != p_path);
536+ MCAssert (0 < p_path_length);
496537
497538 // Ensure it is not indirect.
498539 if (__MCArrayIsIndirect (self))
@@ -551,6 +592,8 @@ bool MCArrayRemoveValueOnPath(MCArrayRef self, bool p_case_sensitive, const MCNa
551592MC_DLLEXPORT_DEF
552593bool MCArrayFetchValueAtIndex (MCArrayRef self, index_t p_index, MCValueRef& r_value)
553594{
595+ __MCAssertIsArray (self);
596+
554597 char t_index_str[16 ];
555598 sprintf (t_index_str, " %d" , p_index);
556599
@@ -564,6 +607,8 @@ bool MCArrayFetchValueAtIndex(MCArrayRef self, index_t p_index, MCValueRef& r_va
564607MC_DLLEXPORT_DEF
565608bool MCArrayStoreValueAtIndex (MCArrayRef self, index_t p_index, MCValueRef p_value)
566609{
610+ __MCAssertIsArray (self);
611+
567612 char t_index_str[16 ];
568613 sprintf (t_index_str, " %d" , p_index);
569614
0 commit comments