From: Armin R. <ar...@us...> - 2005-04-10 21:48:28
|
Update of /cvsroot/psyco/psyco/c/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7448/c/Objects Modified Files: pobject.c pobject.h Log Message: Don't delete objects earlier than the source code suggest (unless the object is of a simple atomic type, in which case it doesn't have observable effects). This should close bugs #1144094 and #1122673. Not fully tested so far. Index: pobject.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/Objects/pobject.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** pobject.c 11 Aug 2004 23:03:38 -0000 1.21 --- pobject.c 10 Apr 2005 21:48:20 -0000 1.22 *************** *** 587,590 **** --- 587,664 ---- } + static vinfo_t* collect_undeletable_vars(vinfo_t* vi, vinfo_t* link) + { + int i; + PyTypeObject* tp; + switch (gettime(vi->source)) { + + case RunTime: + if (vi->tmp != NULL || (vi->source & RunTime_NoRef) != 0) + break; /* already seen or not holding a ref */ + tp = Psyco_KnownType(vi); + if (tp && (tp == &PyInt_Type || tp == &PyString_Type || + #if BOOLEAN_TYPE + tp == &PyBool_Type || + #endif + tp == &PyFloat_Type || tp == &PyLong_Type || + tp == &PyRange_Type)) + break; /* known safe type */ + /* make a linked list of results */ + vi->tmp = link; + link = vi; + break; + + case VirtualTime: + for (i=vi->array->count; i--; ) + if (vi->array->items[i] != NULL) + link = collect_undeletable_vars( + vi->array->items[i], link); + break; + + default: + break; + } + return link; + } + + DEFINEFN + vinfo_t* Psyco_SafelyDeleteVar(PsycoObject* po, vinfo_t* vi) + { + vinfo_t* result; + vinfo_t* head; + vinfo_t* queue = (vinfo_t*) 1; + vinfo_t* p; + int count; + vi->tmp = NULL; + clear_tmp_marks(vi->array); + + head = collect_undeletable_vars(vi, queue); + count = 0; + for (p = head; p != queue; p = p->tmp) { + vinfo_array_t* a = p->array; + p->array = NullArray; + array_delete(a, po); + count++; + } + if (count == 0) { + result = psyco_vi_Zero(); + } + else if (count == 1) { + result = head; + vinfo_incref(result); + } + else { + result = vinfo_new( + VirtualTime_New(&psyco_vsource_not_important)); + count += iOB_TYPE + 1; + result->array = array_new(count); + for (p = head; p != queue; p = p->tmp) { + vinfo_incref(p); + result->array->items[--count] = p; + } + } + return result; + } + INITIALIZATIONFN Index: pobject.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/Objects/pobject.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** pobject.h 18 May 2003 22:26:47 -0000 1.14 --- pobject.h 10 Apr 2005 21:48:20 -0000 1.15 *************** *** 182,185 **** --- 182,188 ---- #endif + /* for dispatcher.c */ + EXTERNFN vinfo_t* Psyco_SafelyDeleteVar(PsycoObject* po, vinfo_t* vi); + #endif /* _PSY_OBJECT_H */ |