[Super-tux-commit] supertux/src lispreader.cpp,1.24,1.25
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-06-28 22:01:40
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17489/src Modified Files: lispreader.cpp Log Message: changed lisp_free to an iterative algorithm Index: lispreader.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/lispreader.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- lispreader.cpp 15 Jun 2004 12:18:59 -0000 1.24 +++ lispreader.cpp 28 Jun 2004 22:01:29 -0000 1.25 @@ -20,8 +20,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - #include <iostream> +#include <queue> #include <string> #include <cctype> #include <cstdlib> @@ -506,30 +506,43 @@ 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 recursive function + * produces a stack overflow and crashs 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(); + + switch (obj->type) { + case LISP_TYPE_INTERNAL : + case LISP_TYPE_PARSE_ERROR : + case LISP_TYPE_EOF : + return; - case LISP_TYPE_CONS : - case LISP_TYPE_PATTERN_CONS : - lisp_free(obj->v.cons.car); - lisp_free(obj->v.cons.cdr); - break; + case LISP_TYPE_SYMBOL : + case LISP_TYPE_STRING : + free(obj->v.string); + break; - case LISP_TYPE_PATTERN_VAR : - lisp_free(obj->v.pattern.sub); - 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 : + if(obj->v.pattern.sub) + objs.push(obj->v.pattern.sub); + break; } - free(obj); + free(obj); + } } lisp_object_t* |