@@ -59,6 +59,20 @@ static bool __MCArrayFindKeyValueSlot(__MCArray *self, bool case_sensitive, MCNa
5959
6060bool MCArrayCreate (bool p_case_sensitive, const MCNameRef *p_keys, const MCValueRef *p_values, uindex_t p_length, MCArrayRef& r_array)
6161{
62+ if (p_length == 0 )
63+ {
64+ if (nil != kMCEmptyArray )
65+ {
66+ r_array = MCValueRetain (kMCEmptyArray );
67+ return true ;
68+ }
69+ }
70+ else
71+ {
72+ MCAssert (nil != p_keys);
73+ MCAssert (nil != p_values);
74+ }
75+
6276 bool t_success;
6377 t_success = true ;
6478
@@ -93,6 +107,8 @@ bool MCArrayCreateMutable(MCArrayRef& r_array)
93107
94108bool MCArrayCopy (MCArrayRef self, MCArrayRef& r_new_array)
95109{
110+ __MCAssertIsArray (self);
111+
96112 // If we aren't mutable, then we can just copy directly.
97113 if (!MCArrayIsMutable (self))
98114 {
@@ -122,6 +138,8 @@ bool MCArrayCopy(MCArrayRef self, MCArrayRef& r_new_array)
122138
123139bool MCArrayCopyAndRelease (MCArrayRef self, MCArrayRef& r_new_array)
124140{
141+ __MCAssertIsArray (self);
142+
125143 // If we aren't mutable, then new array is just us.
126144 if (!MCArrayIsMutable (self))
127145 {
@@ -167,6 +185,8 @@ bool MCArrayCopyAndRelease(MCArrayRef self, MCArrayRef& r_new_array)
167185
168186bool MCArrayMutableCopy (MCArrayRef self, MCArrayRef& r_new_array)
169187{
188+ __MCAssertIsArray (self);
189+
170190 // If the array is immutable, then the new mutable array will be indirect
171191 // referencing it. [ non-mutable arrays cannot be indirect so self does not
172192 // need resolving ].
@@ -193,6 +213,8 @@ bool MCArrayMutableCopy(MCArrayRef self, MCArrayRef& r_new_array)
193213
194214bool MCArrayMutableCopyAndRelease (MCArrayRef self, MCArrayRef& r_new_array)
195215{
216+ __MCAssertIsArray (self);
217+
196218 if (self -> references == 1 )
197219 {
198220 if (!MCArrayIsMutable (self))
@@ -211,6 +233,9 @@ bool MCArrayMutableCopyAndRelease(MCArrayRef self, MCArrayRef& r_new_array)
211233
212234bool MCArrayApply (MCArrayRef self, MCArrayApplyCallback p_callback, void *p_context)
213235{
236+ __MCAssertIsArray (self);
237+ MCAssert (nil != p_callback);
238+
214239 // Make sure we are iterating over the correct contents.
215240 MCArrayRef t_contents;
216241 if (!__MCArrayIsIndirect (self))
@@ -239,6 +264,8 @@ bool MCArrayApply(MCArrayRef self, MCArrayApplyCallback p_callback, void *p_cont
239264
240265bool MCArrayIterate (MCArrayRef self, uintptr_t & x_iterator, MCNameRef& r_key, MCValueRef& r_value)
241266{
267+ __MCAssertIsArray (self);
268+
242269 // Make sure we are iterating over the correct contents.
243270 MCArrayRef t_contents;
244271 if (!__MCArrayIsIndirect (self))
@@ -269,11 +296,15 @@ bool MCArrayIterate(MCArrayRef self, uintptr_t& x_iterator, MCNameRef& r_key, MC
269296
270297bool MCArrayIsMutable (MCArrayRef self)
271298{
299+ __MCAssertIsArray (self);
300+
272301 return (self -> flags & kMCArrayFlagIsMutable ) != 0 ;
273302}
274303
275304uindex_t MCArrayGetCount (MCArrayRef self)
276305{
306+ __MCAssertIsArray (self);
307+
277308 if (!__MCArrayIsIndirect (self))
278309 return self -> key_value_count;
279310 return self -> contents -> key_value_count;
@@ -288,6 +319,11 @@ bool MCArrayFetchValue(MCArrayRef self, bool p_case_sensitive, MCNameRef p_key,
288319
289320bool MCArrayFetchValueOnPath (MCArrayRef self, bool p_case_sensitive, const MCNameRef *p_path, uindex_t p_path_length, MCValueRef& r_value)
290321{
322+ __MCAssertIsArray (self);
323+ MCAssert (nil != p_path);
324+ MCAssert (0 < p_path_length);
325+ __MCAssertIsName (p_path[0 ]);
326+
291327 // If the array is indirect, get the contents.
292328 MCArrayRef t_contents;
293329 if (!__MCArrayIsIndirect (self))
@@ -330,6 +366,9 @@ bool MCArrayStoreValueOnPath(MCArrayRef self, bool p_case_sensitive, const MCNam
330366{
331367 // The array must be mutable.
332368 MCAssert (MCArrayIsMutable (self));
369+ MCAssert (nil != p_path);
370+ MCAssert (0 < p_path_length);
371+ __MCAssertIsName (p_path[0 ]);
333372
334373 // Ensure it is not indirect.
335374 if (__MCArrayIsIndirect (self))
@@ -429,6 +468,8 @@ bool MCArrayRemoveValueOnPath(MCArrayRef self, bool p_case_sensitive, const MCNa
429468{
430469 // The array must be mutable.
431470 MCAssert (MCArrayIsMutable (self));
471+ MCAssert (nil != p_path);
472+ MCAssert (0 < p_path_length);
432473
433474 // Ensure it is not indirect.
434475 if (__MCArrayIsIndirect (self))
@@ -486,6 +527,8 @@ bool MCArrayRemoveValueOnPath(MCArrayRef self, bool p_case_sensitive, const MCNa
486527
487528bool MCArrayFetchValueAtIndex (MCArrayRef self, index_t p_index, MCValueRef& r_value)
488529{
530+ __MCAssertIsArray (self);
531+
489532 char t_index_str[16 ];
490533 sprintf (t_index_str, " %d" , p_index);
491534
@@ -498,6 +541,8 @@ bool MCArrayFetchValueAtIndex(MCArrayRef self, index_t p_index, MCValueRef& r_va
498541
499542bool MCArrayStoreValueAtIndex (MCArrayRef self, index_t p_index, MCValueRef p_value)
500543{
544+ __MCAssertIsArray (self);
545+
501546 char t_index_str[16 ];
502547 sprintf (t_index_str, " %d" , p_index);
503548
0 commit comments