pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:1:   /*   || 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.159 2003/06/02 16:35:33 mast Exp $ + || $Id: mapping.c,v 1.160 2003/09/08 15:28:14 mast Exp $   */      #include "global.h" - RCSID("$Id: mapping.c,v 1.159 2003/06/02 16:35:33 mast Exp $"); + RCSID("$Id: mapping.c,v 1.160 2003/09/08 15:28:14 mast Exp $");   #include "main.h"   #include "object.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "pike_error.h"   #include "pike_memory.h"   #include "dynamic_buffer.h"   #include "interpret.h"
pike.git/src/mapping.c:2078: Inside #if defined(PIKE_DEBUG)
   check_mapping(m);   }   #endif      #ifdef MAPPING_SIZE_DEBUG   #define DO_IF_MAPPING_SIZE_DEBUG(x) x   #else   #define DO_IF_MAPPING_SIZE_DEBUG(x)   #endif    - #define GC_RECURSE_MD_IN_USE(MD, RECURSE_FN, IND_TYPES, VAL_TYPES) do { \ + #define GC_RECURSE_MD_IN_USE(M, MD, RECURSE_FN, IND_TYPES, VAL_TYPES) do { \    INT32 e; \    struct keypair *k; \    IND_TYPES = MD->ind_types; \    NEW_MAPPING_LOOP(MD) { \ -  if (!IS_DESTRUCTED(&k->ind) && RECURSE_FN(&k->ind, 1)) { \ -  DO_IF_DEBUG(Pike_fatal("Didn't expect an svalue zapping now.\n")); \ +  if (!IS_DESTRUCTED(&k->ind) && \ +  RECURSE_FN(&k->ind, 1, T_MAPPING, M)) { \ +  DO_IF_DEBUG(Pike_fatal("Didn't expect an svalue zapping now.\n")); \    } \ -  RECURSE_FN(&k->val, 1); \ +  RECURSE_FN(&k->val, 1, T_MAPPING, M); \    VAL_TYPES |= 1 << k->val.type; \    } \   } while (0)    - #define GC_RECURSE(MD, REC_KEYPAIR, TYPE, IND_TYPES, VAL_TYPES) do { \ + #define GC_RECURSE(M, MD, REC_KEYPAIR, TYPE, IND_TYPES, VAL_TYPES) do { \    INT32 e; \    int remove; \    struct keypair *k,**prev; \    /* no locking required (no is_eq) */ \    for(e=0;e<MD->hashsize;e++) \    { \    for(prev= MD->hash + e;(k=*prev);) \    { \ -  REC_KEYPAIR(remove, \ +  REC_KEYPAIR(M, remove, \    PIKE_CONCAT(TYPE, _svalues), \    PIKE_CONCAT(TYPE, _weak_svalues), \    PIKE_CONCAT(TYPE, _without_recurse), \    PIKE_CONCAT(TYPE, _weak_without_recurse)); \    if (remove) \    { \    *prev=k->next; \    FREE_KEYPAIR(MD, k); \    MD->free_list->ind.type = T_INT; \    MD->free_list->val.type = T_INT; \    MD->size--; \    DO_IF_MAPPING_SIZE_DEBUG( \ -  if(m->data ==MD) \ -  m->debug_size--; \ +  if(M->data ==MD) \ +  M->debug_size--; \    ); \    }else{ \    VAL_TYPES |= 1 << k->val.type; \    IND_TYPES |= 1 << k->ind.type; \    prev=&k->next; \    } \    } \    } \   } while (0)    - #define GC_REC_KP(REMOVE, N_REC, W_REC, N_TST, W_TST) do { \ -  if ((REMOVE = N_REC(&k->ind, 1))) \ + #define GC_REC_KP(M, REMOVE, N_REC, W_REC, N_TST, W_TST) do { \ +  if ((REMOVE = N_REC(&k->ind, 1, T_MAPPING, M))) \    gc_free_svalue(&k->val); \    else \ -  N_REC(&k->val, 1); \ +  N_REC(&k->val, 1, T_MAPPING, M); \   } while (0)    - #define GC_REC_KP_IND(REMOVE, N_REC, W_REC, N_TST, W_TST) do { \ -  if ((REMOVE = W_REC(&k->ind, 1))) \ + #define GC_REC_KP_IND(M, REMOVE, N_REC, W_REC, N_TST, W_TST) do { \ +  if ((REMOVE = W_REC(&k->ind, 1, T_MAPPING, M))) \    gc_free_svalue(&k->val); \    else \ -  N_REC(&k->val, 1); \ +  N_REC(&k->val, 1, T_MAPPING, M); \   } while (0)    - #define GC_REC_KP_VAL(REMOVE, N_REC, W_REC, N_TST, W_TST) do { \ + #define GC_REC_KP_VAL(M, REMOVE, N_REC, W_REC, N_TST, W_TST) do { \    if ((REMOVE = N_TST(&k->ind))) /* Don't recurse now. */ \    gc_free_svalue(&k->val); \ -  else if ((REMOVE = W_REC(&k->val, 1))) \ +  else if ((REMOVE = W_REC(&k->val, 1, T_MAPPING, M))) \    gc_free_svalue(&k->ind); \    else \ -  N_REC(&k->ind, 1); /* Now we can recurse the index. */ \ +  N_REC(&k->ind, 1, T_MAPPING, M); /* Now we can recurse the index. */ \   } while (0)    - #define GC_REC_KP_BOTH(REMOVE, N_REC, W_REC, N_TST, W_TST) do { \ + #define GC_REC_KP_BOTH(M, REMOVE, N_REC, W_REC, N_TST, W_TST) do { \    if ((REMOVE = W_TST(&k->ind))) /* Don't recurse now. */ \    gc_free_svalue(&k->val); \ -  else if ((REMOVE = W_REC(&k->val, 1))) \ +  else if ((REMOVE = W_REC(&k->val, 1, T_MAPPING, M))) \    gc_free_svalue(&k->ind); \    else \ -  W_REC(&k->ind, 1); /* Now we can recurse the index. */ \ +  W_REC(&k->ind, 1, T_MAPPING, M); /* Now we can recurse the index. */ \   } while (0)      void gc_mark_mapping_as_referenced(struct mapping *m)   {   #ifdef PIKE_DEBUG    if(m->data->refs <=0)    Pike_fatal("Zero refs in mapping->data\n");   #endif    debug_malloc_touch(m);    debug_malloc_touch(m->data);
pike.git/src/mapping.c:2182:    gc_internal_mapping = m->next;    else {    DOUBLEUNLINK(first_mapping, m);    DOUBLELINK(first_mapping, m); /* Linked in first. */    }       if(gc_mark(md) && ((md->ind_types | md->val_types) & BIT_COMPLEX)) {    TYPE_FIELD ind_types = 0, val_types = 0;    if (MAPPING_DATA_IN_USE(md)) {    /* Must leave the mapping data untouched if it's busy. */ -  GC_RECURSE_MD_IN_USE(md, gc_mark_svalues, ind_types, val_types); +  debug_malloc_touch(m); +  debug_malloc_touch(md); +  GC_RECURSE_MD_IN_USE(m, md, debug_gc_mark_svalues, ind_types, val_types);    gc_assert_checked_as_nonweak(md);    }    else    switch (md->flags & MAPPING_WEAK) {    case 0: -  GC_RECURSE(md, GC_REC_KP, gc_mark, ind_types, val_types); +  debug_malloc_touch(m); +  debug_malloc_touch(md); +  GC_RECURSE(m, md, GC_REC_KP, debug_gc_mark, ind_types, val_types);    gc_assert_checked_as_nonweak(md);    break;    case MAPPING_WEAK_INDICES: -  GC_RECURSE(md, GC_REC_KP_IND, gc_mark, ind_types, val_types); +  debug_malloc_touch(m); +  debug_malloc_touch(md); +  GC_RECURSE(m, md, GC_REC_KP_IND, debug_gc_mark, ind_types, val_types);    gc_assert_checked_as_weak(md);    break;    case MAPPING_WEAK_VALUES: -  GC_RECURSE(md, GC_REC_KP_VAL, gc_mark, ind_types, val_types); +  debug_malloc_touch(m); +  debug_malloc_touch(md); +  GC_RECURSE(m, md, GC_REC_KP_VAL, debug_gc_mark, ind_types, val_types);    gc_assert_checked_as_weak(md);    break;    default: -  GC_RECURSE(md, GC_REC_KP_BOTH, gc_mark, ind_types, val_types); +  debug_malloc_touch(m); +  debug_malloc_touch(md); +  GC_RECURSE(m, md, GC_REC_KP_BOTH, debug_gc_mark, ind_types, val_types);    gc_assert_checked_as_weak(md);    break;    }    md->val_types = val_types;    md->ind_types = ind_types;    }    }   }      void real_gc_cycle_check_mapping(struct mapping *m, int weak)
pike.git/src/mapping.c:2228: Inside #if defined(PIKE_DEBUG)
   if(md->refs <=0)    Pike_fatal("Zero refs in mapping->data\n");   #endif       if ((md->ind_types | md->val_types) & BIT_COMPLEX) {    TYPE_FIELD ind_types = 0, val_types = 0;    if (MAPPING_DATA_IN_USE(md)) {    /* Must leave the mapping data untouched if it's busy. */    debug_malloc_touch(m);    debug_malloc_touch(md); -  GC_RECURSE_MD_IN_USE(md, gc_cycle_check_svalues, ind_types, val_types); +  GC_RECURSE_MD_IN_USE(m, md, debug_gc_cycle_check_svalues, ind_types, val_types);    gc_assert_checked_as_nonweak(md);    }    else    switch (md->flags & MAPPING_WEAK) {    case 0:    debug_malloc_touch(m);    debug_malloc_touch(md); -  GC_RECURSE(md, GC_REC_KP, gc_cycle_check, ind_types, val_types); +  GC_RECURSE(m, md, GC_REC_KP, debug_gc_cycle_check, ind_types, val_types);    gc_assert_checked_as_nonweak(md);    break;    case MAPPING_WEAK_INDICES:    debug_malloc_touch(m);    debug_malloc_touch(md); -  GC_RECURSE(md, GC_REC_KP_IND, gc_cycle_check, ind_types, val_types); +  GC_RECURSE(m, md, GC_REC_KP_IND, debug_gc_cycle_check, ind_types, val_types);    gc_assert_checked_as_weak(md);    break;    case MAPPING_WEAK_VALUES:    debug_malloc_touch(m);    debug_malloc_touch(md); -  GC_RECURSE(md, GC_REC_KP_VAL, gc_cycle_check, ind_types, val_types); +  GC_RECURSE(m, md, GC_REC_KP_VAL, debug_gc_cycle_check, ind_types, val_types);    gc_assert_checked_as_weak(md);    break;    default:    debug_malloc_touch(m);    debug_malloc_touch(md); -  GC_RECURSE(md, GC_REC_KP_BOTH, gc_cycle_check, ind_types, val_types); +  GC_RECURSE(m, md, GC_REC_KP_BOTH, debug_gc_cycle_check, ind_types, val_types);    gc_assert_checked_as_weak(md);    break;    }    md->val_types = val_types;    md->ind_types = ind_types;    }    } GC_CYCLE_LEAVE;   }      static void gc_check_mapping(struct mapping *m)
pike.git/src/mapping.c:2381:   }      void gc_zap_ext_weak_refs_in_mappings(void)   {    gc_mark_mapping_pos = first_mapping;    while (gc_mark_mapping_pos != gc_internal_mapping && gc_ext_weak_refs) {    struct mapping *m = gc_mark_mapping_pos;    gc_mark_mapping_pos = m->next;    gc_mark_mapping_as_referenced(m);    } -  discard_queue(&gc_mark_queue); +  gc_mark_discard_queue();   }      void gc_free_all_unreferenced_mappings(void)   {    struct mapping *m,*next;    struct mapping_data *md;       for(m=gc_internal_mapping;m;m=next)    {    debug_malloc_touch(m);