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

Re: [sc-dev] writing primitives

On Tuesday, November 26, 2002, at 09:50  AM, crucial felix wrote:

On Monday, November 25, 2002, at 07:41 PM, James McCartney wrote:
those two args appear to be at :

	PyrSlot *defaultPath = g->sp;
	PyrSlot *prompt = g->sp + 1;

g->sp - 1 is the class File

All offsets from the stack pointer g->sp should be negative. If you are getting values at positive offsets, then you have declared the number of arguments incorrectly in definePrimitive() or in the >> method.

	//returns an array of strings for the file's full paths
	// nil if cancelled
	*prGetPathsDialog { arg defaultPath="",prompt="";


void initCocoaFilePrimitives()
	int base, index;
	base = nextPrimitiveIndex();
	index = 0;

definePrimitive(base, index++, "_File_GetPathsDialog", prGetPathsDialog, 2, 0);

and these are the two args:

	PyrSlot *defaultPath = g->sp;
	PyrSlot *prompt = g->sp + 1;

-1 is the receiver which is the class File

anything look wrong ?

Yes. The receiver counts as an argument.
It should be:

definePrimitive(base, index++, "_File_GetPathsDialog", prGetPathsDialog, 3, 0);
	PyrSlot *classobj = g->sp - 2;
	PyrSlot *defaultPath = g->sp - 1;
	PyrSlot *prompt = g->sp;

When you do fill in slots in an object with other objects, you must call g->gc->GCWrite(obj, slot) in order to notify the garbage collector that you have modified a slot that it may have already scanned.

and SetObject doesn't do that. the GC isn't even aware of my object yet, right ?

You can safely set slots of the most recently created object without calling GCWrite.

i'm setting slots on my new object:

            putIndexedSlot(g ,scArray,(PyrSlot*)pyrPathString  ,count);

		so after setting each slot do i have to call
			g->gc->GCWrite(scArray, slot);

or does this only matter after i've put it into the receiver / stack position ?

It matters if any object has been created since yours was created. Because creating an object runs the gc.

If you create more than one object in a primitive you must make sure that all the previously created objects are reachable before you allocate another. In other words you must store them on the stack or in another object's slots before creating another.

so i should put the scArray into the receiver straight away.
then for each:
	put slot,


--- james mccartney   james@xxxxxxxxxxxxxx   <http://www.audiosynth.com>
SuperCollider - a real time synthesis programming language for the PowerMac.