cvsuser     03/01/11 01:48:08

  Modified:    classes  scratchpad.pmc
               .        sub.c
               t/pmc    scratchpad.t
  Log:
  scratchpad mem leak fix
  
  Revision  Changes    Path
  1.6       +5 -16     parrot/classes/scratchpad.pmc
  
  Index: scratchpad.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/scratchpad.pmc,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- scratchpad.pmc    10 Jan 2003 17:04:03 -0000      1.5
  +++ scratchpad.pmc    11 Jan 2003 09:47:58 -0000      1.6
  @@ -1,7 +1,7 @@
   /* Scratchpad.pmc
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: scratchpad.pmc,v 1.5 2003/01/10 17:04:03 leo Exp $
  + *     $Id: scratchpad.pmc,v 1.6 2003/01/11 09:47:58 leo Exp $
    *  Overview:
    *     These are the vtable functions for the Scratchpad base class.
    *  Data Structure and Algorithms:
  @@ -25,24 +25,12 @@
           struct Parrot_Lexicals * lex;
   
        for (j = 0; j < SELF->cache.int_val; j++) {
  -            lex = ((struct Parrot_Lexicals **)SELF->data)[j];
  +            lex = &(((struct Parrot_Lexicals *)SELF->data)[j]);
               lexicals_mark(INTERP, lex);
           }
       }
   
       void destroy () {
  -#if 0
  -     /* XXX leo cloning scratch_pad duplicates these data
  -      * so they can't easily be freed
  -      */
  -     int j;
  -        struct Parrot_Lexicals * lex;
  -
  -     for (j = 0; j < SELF->cache.int_val; j++) {
  -            lex = ((struct Parrot_Lexicals **)SELF->data)[j];
  -         mem_sys_free(lex);
  -     }
  -#endif
        mem_sys_free(SELF->data);
       }
   
  @@ -52,10 +40,11 @@
   
       void clone (PMC *ret) {
           PObj_custom_mark_destroy_SETALL(ret);
  -     ret->data = mem_sys_allocate(SELF->cache.int_val * sizeof(PMC *));
  +     ret->data = mem_sys_allocate(SELF->cache.int_val * 
  +                                     sizeof(struct Parrot_Lexicals));
        ret->cache.int_val = SELF->cache.int_val;
        mem_sys_memcopy(ret->data, SELF->data,
  -                     SELF->cache.int_val * sizeof(PMC *));
  +                     SELF->cache.int_val * sizeof(struct Parrot_Lexicals));
       }
   
       INTVAL elements () {
  
  
  
  1.16      +12 -13    parrot/sub.c
  
  Index: sub.c
  ===================================================================
  RCS file: /cvs/public/parrot/sub.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -w -r1.15 -r1.16
  --- sub.c     10 Jan 2003 17:04:11 -0000      1.15
  +++ sub.c     11 Jan 2003 09:48:02 -0000      1.16
  @@ -1,7 +1,7 @@
   /*  sub.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: sub.c,v 1.15 2003/01/10 17:04:11 leo Exp $
  + *     $Id: sub.c,v 1.16 2003/01/11 09:48:02 leo Exp $
    *  Overview:
    *     Sub-routines, co-routines and other fun stuff...
    *  Data Structure and Algorithms:
  @@ -79,7 +79,7 @@
           return NULL;
       }
   
  -    return ((struct Parrot_Lexicals **)pad->data)[scope_index];
  +    return &(((struct Parrot_Lexicals *)pad->data)[scope_index]);
   }
   
   /*
  @@ -126,7 +126,7 @@
       struct Parrot_Lexicals * lex = NULL;
   
       for (i = pad->cache.int_val - 1; i >= 0; i--) {
  -        lex = ((struct Parrot_Lexicals **)pad->data)[i];
  +        lex = &(((struct Parrot_Lexicals *)pad->data)[i]);
           pos = lexicals_get_position(interp, lex, name);
           if (pos == list_length(interp, lex->names))
               lex = NULL;
  @@ -144,7 +144,6 @@
   PMC*
   scratchpad_new(struct Parrot_Interp * interp, PMC * base, INTVAL depth)
   {
  -    struct Parrot_Lexicals * lex;
       PMC * pad_pmc;
   
       Parrot_block_DOD(interp);
  @@ -170,16 +169,16 @@
                  sizeof(struct Parrot_Lexicals));
       }
   
  -    lex = mem_sys_allocate(sizeof(struct Parrot_Lexicals));
  -    lex->names = NULL;
  -    lex->values = NULL;
  -    /* the list_new below might trigger GC, so anchor the lex structure
  -     * early
  -     */
  -    ((struct Parrot_Lexicals **)pad_pmc->data)[depth] = lex;
       pad_pmc->cache.int_val = depth + 1;
  -    lex->values = list_new(interp, enum_type_PMC);
  -    lex->names = list_new(interp, enum_type_STRING);
  +
  +    /* in case call to list_new triggers gc */
  +    ((struct Parrot_Lexicals *)pad_pmc->data)[depth].values = NULL;
  +    ((struct Parrot_Lexicals *)pad_pmc->data)[depth].names = NULL;
  +
  +    ((struct Parrot_Lexicals *)pad_pmc->data)[depth].values = 
  +        list_new(interp, enum_type_PMC);
  +    ((struct Parrot_Lexicals *)pad_pmc->data)[depth].names = 
  +        list_new(interp, enum_type_STRING);
   
       Parrot_unblock_DOD(interp);
   
  
  
  
  1.2       +28 -1     parrot/t/pmc/scratchpad.t
  
  Index: scratchpad.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/scratchpad.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- scratchpad.t      15 Nov 2002 05:49:10 -0000      1.1
  +++ scratchpad.t      11 Jan 2003 09:48:08 -0000      1.2
  @@ -1,6 +1,6 @@
   #! perl -w
   
  -use Parrot::Test tests => 3;
  +use Parrot::Test tests => 4;
   
   output_is(<<CODE, <<OUTPUT, "direct set and get on scratchpad pmc");
        new_pad P20, 0
  @@ -162,6 +162,33 @@
   202
   102
   202
  +101
  +OUTPUT
  +
  +output_is(<<CODE, <<OUTPUT, "clone scratchpads");
  +     new_pad P20, 0
  +     new P0, .PerlInt
  +     set P0, 100
  +     new P1, .PerlInt
  +     set P1, 101
  +
  +        set P20[0;"var0"], P0
  +        set P20[0;"var1"], P1
  +
  +        clone P21, P20
  +
  +        new P20, .PerlInt
  +
  +        set P22, P21[0;"var0"] # original pad should be gc'ed
  +        set P23, P21[0;"var1"]
  +
  +        print P22
  +        print "\\n"
  +        print P23
  +        print "\\n"
  +     end
  +CODE
  +100
   101
   OUTPUT
   
  
  
  


Reply via email to