cvsuser     02/11/18 02:12:18

  Modified:    include/parrot misc.h
               .        spf_vtable.c string.c
  Log:
  GC related string fixes
  
  Revision  Changes    Path
  1.9       +3 -3      parrot/include/parrot/misc.h
  
  Index: misc.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/misc.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- misc.h    3 Nov 2002 21:15:17 -0000       1.8
  +++ misc.h    18 Nov 2002 10:12:17 -0000      1.9
  @@ -1,7 +1,7 @@
   /* misc.h
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: misc.h,v 1.8 2002/11/03 21:15:17 leo Exp $
  + *     $Id: misc.h,v 1.9 2002/11/18 10:12:17 leo Exp $
    *  Overview:
    *     Miscellaneous functions, mainly the Parrot_sprintf family
    *  Data Structure and Algorithms:
  @@ -58,8 +58,8 @@
        */
   #   define PARROT_SPRINTF_MAX_PREC 3 * PARROT_SPRINTF_BUFFER_SIZE / 4
   
  -#   define cstr2pstr(cstr) string_make(interpreter, cstr, strlen(cstr), NULL, 0, 
NULL)
  -#   define char2pstr(ch)   string_make(interpreter, &ch , 1,            NULL, 0, 
NULL)
  +#   define cstr2pstr(cstr) string_make(interpreter, cstr, strlen(cstr), NULL, 
BUFFER_external_FLAG, NULL)
  +#   define char2pstr(ch)   string_make(interpreter, &ch , 1,            NULL, 
BUFFER_external_FLAG, NULL)
   
       /* SPRINTF DATA STRUCTURE AND FLAGS */
   
  
  
  
  1.8       +3 -5      parrot/spf_vtable.c
  
  Index: spf_vtable.c
  ===================================================================
  RCS file: /cvs/public/parrot/spf_vtable.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- spf_vtable.c      3 Nov 2002 21:15:11 -0000       1.7
  +++ spf_vtable.c      18 Nov 2002 10:12:18 -0000      1.8
  @@ -1,7 +1,7 @@
   /* spf_vtable.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: spf_vtable.c,v 1.7 2002/11/03 21:15:11 leo Exp $
  + *     $Id: spf_vtable.c,v 1.8 2002/11/18 10:12:18 leo Exp $
    *  Overview:
    *     Implements the two families of functions Parrot_sprintf
    *     may use to retrieve arguments.
  @@ -173,9 +173,8 @@
       case SIZE_PSTR:
           {
               STRING *s = (STRING *)va_arg(*arg, STRING *);
  +            return string_copy(interpreter, s);
   
  -            /* XXX string_copy like below? */
  -            return string_make(interpreter, s->strstart, s->bufused, 0, 0, 0);
           }
   
       case SIZE_PMC:
  @@ -183,8 +182,7 @@
               PMC *pmc = (PMC *)va_arg(*arg, PMC *);
               STRING *s = pmc->vtable->get_string(interpreter, pmc);
   
  -            /* XXX string_copy like below? */
  -            return string_make(interpreter, s->strstart, s->bufused, 0, 0, 0);
  +            return string_copy(interpreter, s);
           }
   
       default:
  
  
  
  1.112     +16 -40    parrot/string.c
  
  Index: string.c
  ===================================================================
  RCS file: /cvs/public/parrot/string.c,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -w -r1.111 -r1.112
  --- string.c  11 Nov 2002 14:49:52 -0000      1.111
  +++ string.c  18 Nov 2002 10:12:18 -0000      1.112
  @@ -1,7 +1,7 @@
   /* string.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: string.c,v 1.111 2002/11/11 14:49:52 leo Exp $
  + *     $Id: string.c,v 1.112 2002/11/18 10:12:18 leo Exp $
    *  Overview:
    *     This is the api definitions for the string subsystem
    *  Data Structure and Algorithms:
  @@ -42,7 +42,8 @@
   static void
   unmake_COW(struct Parrot_Interp *interpreter, STRING *s)
   {
  -    if (s->flags & (BUFFER_COW_FLAG|BUFFER_constant_FLAG)) {
  +    if (s->flags &
  +            (BUFFER_COW_FLAG|BUFFER_constant_FLAG|BUFFER_external_FLAG)) {
           void *p;
           UINTVAL size, bsize;
           if (interpreter) {
  @@ -62,7 +63,7 @@
           Parrot_allocate_string(interpreter, s, bsize);
           mem_sys_memcopy(s->strstart, p, size);
           s->flags &= ~(UINTVAL)(BUFFER_COW_FLAG | BUFFER_external_FLAG |
  -                BUFFER_bufstart_external_FLAG);
  +                BUFFER_bufstart_external_FLAG | BUFFER_immobile_FLAG);
           if (interpreter) {
               Parrot_unblock_GC(interpreter);
               Parrot_unblock_DOD(interpreter);
  @@ -170,8 +171,7 @@
       }
   
       /* Is A real? */
  -    /* XXX w/o test for a->strlen s. below */
  -    if (a != NULL && a->strlen != 0) {
  +    if (a != NULL) {
           /* If the destination's constant, then just fall back to
              string_concat */
           if (a->flags & BUFFER_constant_FLAG) {
  @@ -198,40 +198,6 @@
           a->strlen += b->strlen;
           return a;
       }
  -    else {
  -        /* A isn't real. Does it exist at all? */
  -        if (a != NULL) {
  -/* XXX
  - * Why should appending an ascii string to an empty unicode string
  - * yield an ascii string (above transcodes b, which is always correct)?
  - * Why are the flags copied?
  - * I would just drop this and handle a->strlen == 0 like above
  - * -leo
  - */
  -            if (a->flags & BUFFER_constant_FLAG) {
  -                return string_concat(interpreter, a, b, Uflags);
  -            }
  -            /* There's at least a string header for A. Make it a copy
  -               of B */
  -            if (a->buflen < b->bufused) {
  -                a = string_grow(interpreter, a, b->bufused + EXTRA_SIZE);
  -            }
  -            else
  -                unmake_COW(interpreter, a);
  -            a->flags = b->flags;
  -            a->flags &= ~(UINTVAL)(BUFFER_constant_FLAG
  -                                   |BUFFER_COW_FLAG
  -                                   |BUFFER_bufstart_external_FLAG
  -                                   |BUFFER_external_FLAG);
  -            a->bufused = b->bufused;
  -            a->strlen = b->strlen;
  -            a->encoding = b->encoding;
  -            a->type = b->type;
  -            a->language = b->language;
  -            memcpy(a->strstart, b->strstart, b->bufused);
  -            return a;
  -        }
  -    }
       /* If we got here, A was NULL. So clone B. */
       return string_copy(interpreter, b);
   }
  @@ -1095,7 +1061,17 @@
       else
           unmake_COW(interpreter, s);
   
  -    s->flags |= BUFFER_immobile_FLAG;
  +    /* s->flags |= BUFFER_immobile_FLAG;
  +     *
  +     * XXX we don't know, how this cstring gets used by external code
  +     * so setting the string to immobile would be the best thing, but
  +     * immobile strings don't get moved - yes - but they get freed in
  +     * compact_pool :-(
  +     * The correct way to handle this is probably to malloc the memory
  +     * and set the BUFFER_sysmem_FLAG
  +     * -leo
  +     */
  +
       ((char *)s->strstart)[s->bufused] = 0;
       /* don't return local vars, return the right thing */
       return (char*)s->strstart;
  
  
  


Reply via email to