[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sc-devel] [] can cause instability: tests in primitives?



On 21.11.2007, at 16:51, Dan Stowell wrote:
wrapAt's primitive uses basicWrapAt(), and plot uses unlace which uses
prArrayUnlace(), both in PyrArrayPrimitives.cpp. Looks like they both
fail to account for an empty array.

Could there be some generic way to catch these problems? e.g. this
line could (I guess) return nil if empty:

 if(obj->size==0) {SetNil(a); return errNone; }

yes, basicWrapAt is missing the check for obj->size == 0, also for the array-as-index case.

but would need slightly different versions adding to each primitive.
Any better way?

the solution wouldn't be quite correct for unlace:

[].unlace(3)

[[],[],[]]

i guess (jmc will correct me if i'm wrong), that the newly created subarrays (and the result array) need to be reconsidered by the garbage collector:

	SetObject(slots2 + i, obj3);
	g->gc->GCWriteNew(obj2, obj3);

, likewise for the sublist elements:

	PyrSlot* tmp = slots + (i*clump + k + j*numLists);
	slots3[j+k].ucopy = tmp->ucopy;
	g->gc->GCWrite(obj3, tmp->uo);

[ cannot test properly now, still at work :P ]

<sk>