Пример #1
0
bool PyrGC::SanityMarkObj(PyrObject *objA, PyrObject *fromObj, int level)
{
	if (objA->IsPermanent()) return true;
	if (objA->IsMarked()) return true;
	if (objA->size > MAXINDEXSIZE(objA)) {
		fprintf(stderr, "obj indexed size larger than max: %d > %ld\n", objA->size, MAXINDEXSIZE(objA));
		//dumpObject((PyrObject*)objA);
		return false;
	}

	objA->SetMark(); // mark it
	if (!BlackToWhiteCheck(objA))
		return false;

	if (objA->obj_format <= obj_slot) {
		// scan it
		int size = objA->size;
		if (size > 0) {
			PyrSlot *slot = objA->slots;
			for (int j=size; j--; ++slot) {
				PyrObject * objB = NULL;
				int tag = GetTag(slot);
				if (tag == tagObj && slotRawObject(slot))
					objB = slotRawObject(slot);

				if (objB) {
					/*
					if (level > 40) {
						fprintf(stderr, "40 levels deep!\n");
						dumpBadObject(objA);
						dumpBadObject(objB);
						return false;
					} */
					bool err = SanityMarkObj(objB, objA, level + 1);
					if (!err)
						return false;
				}
			}
		}
	}
	return true;
}
Пример #2
0
int prFileReadLine(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a, *b; // receiver(a File), string
	PyrFile *pfile;
	FILE *file;

	a = g->sp - 1;
	b = g->sp;

	pfile = (PyrFile*)slotRawObject(a);
	file = (FILE*)slotRawPtr(&pfile->fileptr);
	if (file == NULL) return errFailed;

	char* result = fgets(slotRawString(b)->s, (int)(MAXINDEXSIZE(slotRawObject(b)) - 1), file); // kengo:
	if (!result) {
		SetNil(a);
	} else {
		slotRawString(b)->size = (int)strlen(slotRawString(b)->s);
		if (slotRawString(b)->s[slotRawString(b)->size-1] == '\n') slotRawString(b)->size--;
		slotCopy(a,b);
	}
	return errNone;
}
Пример #3
0
bool PyrGC::SanityMarkObj(PyrObject *objA, PyrObject *fromObj, int level)
{
	int j, size, tag;
	PyrSlot *slot;
	PyrObject *objB;

	if (objA->IsPermanent()) return true;
	if (objA->IsMarked()) return true;
	if (objA->size > MAXINDEXSIZE(objA)) {
		fprintf(stderr, "obj indexed size larger than max: %d > %d\n", objA->size, MAXINDEXSIZE(objA));
		//dumpObject((PyrObject*)objA);
		return false;
	}
	objA->SetMark(); // mark it
	if (objA->obj_format <= obj_slot) {
		// scan it
		size = objA->size;
		if (size > 0) {
			slot = objA->slots;
			for (j=size; j--; ++slot) {
				objB = NULL;
				tag = slot->utag;
				if (tag == tagObj && slot->uo) {
					objB = slot->uo;
				}
				if (objB && (long)objB < 100) {
					fprintf(stderr, "weird obj ptr\n");
					return false;
				}
				if (objB) {
					if (objA == mStack) {
					} else if (objA->gc_color == mBlackColor && objA != mPartialScanObj) {
						if (objB->gc_color == mWhiteColor) {

							//debugf("black to white ref %p %p\n", objA, objB);
							//debugf("sizeclass %d %d\n",  objA->obj_sizeclass, objB->obj_sizeclass);
							//debugf("class %s %s\n",  objA->classptr->name.us->name, objB->classptr->name.us->name);

							fprintf(stderr, "black to white ref %p %p\n", objA, objB);
	#if DUMPINSANITY
							dumpBadObject(objA);
							dumpBadObject(objB);
							fprintf(stderr, "\n");
	#endif
							return false;
						}
					}
					/*if (level > 40) {
						fprintf(stderr, "40 levels deep!\n");
						dumpBadObject(objA);
						dumpBadObject(objB);
						return false;
					}*/
					bool err = SanityMarkObj(objB, objA, level + 1);
					if (!err) return false;
				}
			}
		}
	}
	return true;
}