Branch: Tag:

2006-01-19

2006-01-19 18:54:59 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Rewrote mapping_rehash_backwards_{good,evil}() to not eat stack.
Fixes out of C-stack errors when resizing unbalanced mappings.

Rev: src/mapping.c:1.186

2:   || 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: mapping.c,v 1.185 2005/09/11 00:40:10 grendel Exp $ + || $Id: mapping.c,v 1.186 2006/01/19 18:54:59 grubba Exp $   */      #include "global.h"
278:    struct keypair *from)   {    unsigned INT32 h; -  struct keypair *k; +  struct keypair *k, *prev = NULL, *next;    -  if(!from) return; -  mapping_rehash_backwards_evil(md,from->next); +  if(!(k = from)) return;    -  +  /* Reverse the hash chain. */ +  while ((next = k->next)) { +  k->next = prev; +  prev = k; +  k = next; +  } +  k->next = prev; +  +  from = k; +  +  /* Rehash and reverse the hash chain. */ +  while (from) {    /* unlink */    k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP
307:    md->ind_types |= 1<< (k->ind.type);    md->val_types |= 1<< (k->val.type);    md->size++; +  +  /* Reverse */ +  prev = from->next; +  from->next = next; +  next = from; +  from = prev;    } -  + }      static void mapping_rehash_backwards_good(struct mapping_data *md,    struct keypair *from)   {    unsigned INT32 h; -  struct keypair *k; +  struct keypair *k, *prev = NULL, *next;    -  if(!from) return; -  mapping_rehash_backwards_good(md,from->next); +  if(!(k = from)) return;    -  +  /* Reverse the hash chain. */ +  while ((next = k->next)) { +  k->next = prev; +  prev = k; +  k = next; +  } +  k->next = prev; +  +  from = k; +  +  /* Rehash and reverse the hash chain. */ +  while (from) {    /* unlink */    k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP
344:    md->ind_types |= 1<< (k->ind.type);    md->val_types |= 1<< (k->val.type);    md->size++; +  +  /* Reverse */ +  prev = from->next; +  from->next = next; +  next = from; +  from = prev;    } -  + }      /** This function re-allocates a mapping. It adjusts the max no. of    * values can be fitted into the mapping. It takes a bit of time to