Branch: Tag:

2001-06-06

2001-06-06 02:22:36 by Martin Stjernholm <mast@lysator.liu.se>

Fixed [bug 1728 (#1728)] where setting the weak flag on an empty array or multiset
caused multisets created later to also be weak.

Rev: src/array.c:1.102
Rev: src/array.h:1.31
Rev: src/builtin_functions.c:1.340
Rev: src/gc.c:1.145
Rev: src/testsuite.in:1.386

23:   #include "stuff.h"   #include "bignum.h"    - RCSID("$Id: array.c,v 1.101 2001/01/03 21:35:13 grubba Exp $"); + RCSID("$Id: array.c,v 1.102 2001/06/06 02:22:35 mast Exp $");      PMOD_EXPORT struct array empty_array=   {
31: Inside #if defined(PIKE_SECURITY)
  #ifdef PIKE_SECURITY    0,   #endif -  &empty_array, /* Next */ -  &empty_array, /* previous (circular) */ +  &weak_empty_array, /* Next */ +  &weak_shrink_empty_array, /* previous (circular) */    0, /* Size = 0 */    0, /* malloced Size = 0 */    0, /* no types */    0, /* no flags */   }; -  + PMOD_EXPORT struct array weak_empty_array= + { +  1, + #ifdef PIKE_SECURITY +  0, + #endif +  &weak_shrink_empty_array, &empty_array, 0, 0, 0, ARRAY_WEAK_FLAG + }; + PMOD_EXPORT struct array weak_shrink_empty_array= + { +  1, + #ifdef PIKE_SECURITY +  0, + #endif +  &empty_array, &weak_empty_array, 0, 0, 0, ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK + };      struct array *gc_internal_array = &empty_array;   static struct array *gc_mark_array_pos = 0;
106:   PMOD_EXPORT void really_free_array(struct array *v)   {   #ifdef PIKE_DEBUG -  if(v == & empty_array) -  fatal("Tried to free the empty_array.\n"); +  if(v == & empty_array || v == &weak_empty_array || v == &weak_shrink_empty_array) +  fatal("Tried to free some *_empty_array.\n");   #endif      #ifdef PIKE_DEBUG
127:    free_array(a);   }    + PMOD_EXPORT struct array *array_set_flags(struct array *a, int flags) + { +  if (a->size) +  a->flags = flags; +  else { +  free_array(a); +  switch (flags) { +  case 0: +  add_ref(a = &empty_array); break; +  case ARRAY_WEAK_FLAG: +  add_ref(a = &weak_empty_array); break; +  case ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK: +  add_ref(a = &weak_shrink_empty_array); break; +  default: +  fatal("Invalid flags %x\n", flags); +  } +  } +  return a; + } +    /*    * Extract an svalue from an array    */
1982:    int e;    if(gc_mark(a)) {   #ifdef PIKE_DEBUG -  if (a == &empty_array) fatal("Trying to gc mark empty_array.\n"); +  if (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array) +  fatal("Trying to gc mark some *_empty_array.\n");   #endif       if (a == gc_mark_array_pos)
2049:    GC_CYCLE_ENTER(a, weak) {    int e;   #ifdef PIKE_DEBUG -  if (a == &empty_array) fatal("Trying to gc cycle check empty_array.\n"); +  if (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array) +  fatal("Trying to gc cycle check some *_empty_array.\n");   #endif       if (a->type_field & BIT_COMPLEX)
2111:   {    gc_mark_array_pos = gc_internal_array;    gc_mark(&empty_array); +  gc_mark(&weak_empty_array); +  gc_mark(&weak_shrink_empty_array);    while (gc_mark_array_pos != &empty_array) {    struct array *a = gc_mark_array_pos;   #ifdef PIKE_DEBUG
2146:   {    struct array *a,*next;    -  for (a = gc_internal_array; a != &empty_array; a = next) +  for (a = gc_internal_array; a != &weak_empty_array; a = next)    {   #ifdef PIKE_DEBUG    if (!a)
2194: Inside #if defined(PIKE_DEBUG)
   a->flags,    a->size,    a->malloced_size, -  a == &empty_array ? " (the empty_array)" : ""); +  a == &empty_array ? " (the empty_array)" : +  a == &weak_empty_array ? " (the weak_empty_array)" : +  a == &weak_shrink_empty_array ? " (the weak_shrink_empty_array)" : +  "");    fprintf(stderr,"Type field = ");    debug_dump_type_field(a->type_field);    fprintf(stderr,"\n");
2212:    {      #if defined(PIKE_DEBUG) && defined(DEBUG_MALLOC) -  if(verbose_debug_exit && a!=&empty_array) +  if(verbose_debug_exit && a!=&empty_array && +  a!=&weak_empty_array && a!=&weak_shrink_empty_array)    describe(a);   #endif   
2232:   {    INT32 num=0, size=0;    struct array *m; -  for(m=empty_array.next;m!=&empty_array;m=m->next) +  for(m=empty_array.next;m!=&weak_empty_array;m=m->next)    {    num++;    size+=sizeof(struct array)+