[Super-tux-commit] supertux/src lispreader.cpp,1.18,1.18.2.1
Brought to you by:
wkendrick
From: Ryan F. <sik...@us...> - 2004-06-28 23:05:06
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31373 Modified Files: Tag: supertux_0_1_1_branch lispreader.cpp Log Message: - backported MatzeB's lisp_free() patch Index: lispreader.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/lispreader.cpp,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -u -d -r1.18 -r1.18.2.1 --- lispreader.cpp 3 May 2004 23:06:19 -0000 1.18 +++ lispreader.cpp 28 Jun 2004 23:04:57 -0000 1.18.2.1 @@ -22,6 +22,7 @@ */ #include <iostream> +#include <queue> #include <string> #include <assert.h> #include <ctype.h> @@ -503,28 +504,41 @@ if (obj == 0) return; - switch (obj->type) - { - case LISP_TYPE_INTERNAL : - case LISP_TYPE_PARSE_ERROR : - case LISP_TYPE_EOF : - return; + /** We have to use this iterative code because the recursion function + * produces a stack overflow and crashes on OSX 10.2 + */ + std::queue<lisp_object_t*> objs; + objs.push(obj); - case LISP_TYPE_SYMBOL : - case LISP_TYPE_STRING : - free(obj->v.string); - break; + while(!objs.empty()) + { + lisp_object_t* obj = objs.front(); + objs.pop(); - case LISP_TYPE_CONS : - case LISP_TYPE_PATTERN_CONS : - lisp_free(obj->v.cons.car); - lisp_free(obj->v.cons.cdr); - break; + switch (obj->type) + { + case LISP_TYPE_INTERNAL : + case LISP_TYPE_PARSE_ERROR : + case LISP_TYPE_EOF : + return; + case LISP_TYPE_SYMBOL : + case LISP_TYPE_STRING : + free(obj->v.string); + break; + case LISP_TYPE_CONS : + case LISP_TYPE_PATTERN_CONS : + if(obj->v.cons.car) + objs.push(obj->v.cons.car); + if(obj->v.cons.cdr) + objs.push(obj->v.cons.cdr); + break; - case LISP_TYPE_PATTERN_VAR : - lisp_free(obj->v.pattern.sub); - break; + case LISP_TYPE_PATTERN_VAR : + if(obj->v.pattern.sub) + objs.push(obj->v.pattern.sub); + break; } + } free(obj); } |