diff --git a/src/array.c b/src/array.c index 0ea63a25f17f87c314ad156416e250b99383c093..621c47911b4c1dd3338e2d43c797336dfbb46e1f 100644 --- a/src/array.c +++ b/src/array.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: array.c,v 1.210 2008/06/23 16:05:02 mast Exp $ +|| $Id: array.c,v 1.211 2008/07/01 09:36:28 mast Exp $ */ #include "global.h" @@ -529,16 +529,20 @@ PMOD_EXPORT struct array *array_shrink(struct array *v, ptrdiff_t size) Pike_fatal("Illegal argument to array_shrink.\n"); #endif - if (size == v->size) return v; - + /* Ensure that one of the empty arrays are returned if size is zero. */ if( !size ) { - free_array(v); - /* FIXME: What about weak markers etc? */ - add_ref(&empty_array); - return &empty_array; + struct array *e = (v->flags & ARRAY_WEAK_FLAG ? + &weak_empty_array : &empty_array); + if (e != v) { + free_array (v); + add_ref (e); + } + return e; } + if (size == v->size) return v; + /* Free items outside the new array. */ free_svalues(ITEM(v) + size, v->size - size, v->type_field); v->size=size; @@ -568,6 +572,9 @@ PMOD_EXPORT struct array *resize_array(struct array *a, INT32 size) if(d_flag > 1) array_check_type_field(a); #endif + /* Ensure that one of the empty arrays are returned if size is zero. */ + if (!size) return array_shrink (a, size); + if(a->size == size) return a; if(size > a->size) { diff --git a/src/array.h b/src/array.h index 05408556fe64e9b020364f8d9a258bfdf95c425c..ceed976a3078cfe2b6f6784841c44c6c5f49647b 100644 --- a/src/array.h +++ b/src/array.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: array.h,v 1.75 2008/05/11 14:55:53 mast Exp $ +|| $Id: array.h,v 1.76 2008/07/01 09:36:29 mast Exp $ */ #ifndef ARRAY_H @@ -242,7 +242,7 @@ PMOD_EXPORT struct array *implode_array(struct array *a, struct array *b); #define DO_AGGREGATE_ARRAY(max_keep_on_stack) \ do { \ ptrdiff_t diff__ = Pike_sp - base__; \ - if (diff__ > (max_keep_on_stack)) { \ + if (!(max_keep_on_stack) || diff__ > (max_keep_on_stack)) { \ INT32 oldsize__ = base__[-1].u.array->size; \ ACCEPT_UNFINISHED_TYPE_FIELDS { \ base__[-1].u.array = \