Ignore:
Timestamp:
Apr 30, 2011, 12:24:57 AM (8 years ago)
Author:
Sam Hocevar
Message:

lisp: fix a memory leak in the grow stack objets and refactor the class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/lisp/lisp.cpp

    r560 r561  
    8686{
    8787    dprintf("Main program\n");
    88     if (max_lev==-1) max_lev=PtrRef::stack.son;
    89     else if (max_lev>=PtrRef::stack.son) max_lev=PtrRef::stack.son-1;
    90 
    91     for (int i=0; i<max_lev; i++)
     88    if (max_lev == -1)
     89        max_lev = PtrRef::stack.m_size;
     90    else if (max_lev >= (int)PtrRef::stack.m_size)
     91        max_lev = PtrRef::stack.m_size - 1;
     92
     93    for (int i = 0; i < max_lev; i++)
    9294    {
    9395        dprintf("%d> ", i);
     
    15651567  void **arg_on=(void **)malloc(sizeof(void *)*num_args);
    15661568  LList *list_on=(LList *)CDR(arg_list);
    1567   long old_ptr_son=PtrRef::stack.son;
     1569  long old_ptr_son=PtrRef::stack.m_size;
    15681570
    15691571  for (i=0; i<num_args; i++)
     
    16191621  }
    16201622  while (!stop);
    1621   PtrRef::stack.son=old_ptr_son;
     1623  PtrRef::stack.m_size=old_ptr_son;
    16221624
    16231625  free(arg_on);
     
    16401642    {
    16411643      void **str_eval=(void **)malloc(elements*sizeof(void *));
    1642       int i, old_ptr_stack_start=PtrRef::stack.son;
     1644      int i, old_ptr_stack_start=PtrRef::stack.m_size;
    16431645
    16441646      // evalaute all the strings and count their lengths
     
    17021704      }
    17031705      free(str_eval);
    1704       PtrRef::stack.son=old_ptr_stack_start;   // restore pointer GC stack
     1706      PtrRef::stack.m_size=old_ptr_stack_start;   // restore pointer GC stack
    17051707      *s=0;
    17061708      ret=st;
     
    20812083        LObject *block_list = CDR(arg_list);
    20822084        PtrRef r1(block_list), r2(var_list);
    2083         long stack_start = l_user_stack.son;
     2085        long stack_start = l_user_stack.m_size;
    20842086
    20852087        while (var_list)
     
    21172119            var_list = CDR(var_list);
    21182120        }
    2119         l_user_stack.son = stack_start; // restore the stack
     2121        l_user_stack.m_size = stack_start; // restore the stack
    21202122        break;
    21212123    }
     
    27682770        LObject *init_var = CAR(arg_list);
    27692771        PtrRef r1(init_var);
    2770         int ustack_start = l_user_stack.son; // restore stack at end
     2772        int ustack_start = l_user_stack.m_size; // restore stack at end
    27712773        LSymbol *sym = NULL;
    27722774        PtrRef r2(sym);
     
    27842786        }
    27852787
    2786         void **do_evaled = l_user_stack.sdata + l_user_stack.son;
     2788        void **do_evaled = l_user_stack.sdata + l_user_stack.m_size;
    27872789        // push all of the init forms, so we can set the symbol
    27882790        for (init_var = CAR(arg_list); init_var; init_var = CDR(init_var))
     
    28192821        }
    28202822
    2821         l_user_stack.son = ustack_start;
     2823        l_user_stack.m_size = ustack_start;
    28222824        break;
    28232825    }
     
    30103012
    30113013    // mark the start start, so we can restore when done
    3012     long stack_start = l_user_stack.son;
     3014    long stack_start = l_user_stack.m_size;
    30133015
    30143016    // first push all of the old symbol values
     
    30253027    // open block so that local vars aren't saved on the stack
    30263028    {
    3027         int new_start = l_user_stack.son;
     3029        int new_start = l_user_stack.m_size;
    30283030        int i = new_start;
    30293031        // now push all the values we wish to gather
     
    30443046            ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[i++]);
    30453047
    3046         l_user_stack.son = new_start;
     3048        l_user_stack.m_size = new_start;
    30473049    }
    30483050
     
    30653067        ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[cur_stack++]);
    30663068
    3067     l_user_stack.son = stack_start;
     3069    l_user_stack.m_size = stack_start;
    30683070
    30693071#ifdef L_PROFILE
     
    30883090            dprintf("%d (%d, %d, %d) TRACE : ", trace_level,
    30893091                    get_free_size(PERM_SPACE), get_free_size(TMP_SPACE),
    3090                     PtrRef::stack.son);
     3092                    PtrRef::stack.m_size);
    30913093            Print();
    30923094            dprintf("\n");
     
    31373139            dprintf("%d (%d, %d, %d) TRACE ==> ", trace_level,
    31383140                    get_free_size(PERM_SPACE), get_free_size(TMP_SPACE),
    3139                     PtrRef::stack.son);
     3141                    PtrRef::stack.m_size);
    31403142        ret->Print();
    31413143        dprintf("\n");
Note: See TracChangeset for help on using the changeset viewer.