Branch: Tag:

2008-05-11

2008-05-11 02:36:00 by Martin Stjernholm <mast@lysator.liu.se>

Implemented visit functions for the visit_thing_fn interface. The gc
check/mark functions are restored to how they were before the
GC_PASS_COUNT_MEMORY stuff.

Rev: src/array.c:1.206
Rev: src/array.h:1.74
Rev: src/constants.c:1.59
Rev: src/constants.h:1.36
Rev: src/mapping.c:1.200
Rev: src/mapping.h:1.67
Rev: src/multiset.c:1.110
Rev: src/multiset.h:1.43
Rev: src/object.c:1.290
Rev: src/object.h:1.95
Rev: src/pike_types.c:1.331
Rev: src/pike_types.h:1.114
Rev: src/program.c:1.691
Rev: src/program.h:1.242
Rev: src/stralloc.c:1.218
Rev: src/stralloc.h:1.103

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: pike_types.c,v 1.330 2008/05/10 11:53:41 grubba Exp $ + || $Id: pike_types.c,v 1.331 2008/05/11 02:35:22 mast Exp $   */      #include "global.h"
7837:   #endif /* DO_PIKE_CLEANUP */   }    - /* This is only enough gc stuff to detect leaking pike_type structs -  * and to get _locate_references and Pike.count_memory working. More -  * is needed if types are extended to contain pointers to other memory -  * objects or if they might contain cycles. */ -  - void gc_check_type (struct pike_type *t) + void visit_type (struct pike_type *t, int action)   { -  debug_malloc_touch (t); +  switch (action) { + #ifdef PIKE_DEBUG +  default: +  Pike_fatal ("Unknown visit action %d.\n", action); +  case VISIT_NORMAL: +  break; + #endif +  case VISIT_COMPLEX_ONLY: +  return; +  case VISIT_COUNT_BYTES: +  mc_counted_bytes += sizeof (struct pike_type); +  break; +  }    -  GC_ENTER (t, T_TYPE) { +     switch (t->type) {    case T_FUNCTION:    case T_MANY:
7855:    case T_OR:    case T_AND:    case PIKE_T_RING: -  case PIKE_T_ATTRIBUTE: -  case PIKE_T_NAME: -  debug_gc_check (t->car, " as car in a type"); -  debug_gc_check (t->cdr, " as cdr in a type"); +  visit_type_ref (t->car, REF_TYPE_INTERNAL); +  /* FALL_THROUGH */ +  case T_SCOPE: +  case T_ASSIGN: +  visit_type_ref (t->cdr, REF_TYPE_INTERNAL);    break;    case T_ARRAY:    case T_MULTISET:
7866:    case T_TYPE:    case T_PROGRAM:    case T_STRING: -  debug_gc_check (t->car, " as car in a type"); +  visit_type_ref (t->car, REF_TYPE_INTERNAL);    break; -  case T_SCOPE: -  case T_ASSIGN: -  debug_gc_check (t->cdr, " as cdr in a type"); +  case PIKE_T_ATTRIBUTE: +  case PIKE_T_NAME: +  visit_string_ref ((struct pike_string *) t->car, REF_TYPE_INTERNAL); +  visit_type_ref (t->cdr, REF_TYPE_INTERNAL);    break;   #ifdef PIKE_DEBUG    case '0':
7892: Inside #if defined(PIKE_DEBUG)
   case T_OBJECT:    break;    default: -  Pike_fatal("gc_check_type: " -  "Unhandled type-node: %d\n", t->type); +  Pike_fatal("visit_type: Unhandled type-node: %d\n", t->type);    break;   #endif /* PIKE_DEBUG */    } -  } GC_LEAVE; +    }    -  + #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP) +  + /* This is only enough gc stuff to detect leaking pike_type structs +  * and to locate references to them. More is needed if types are +  * extended to contain pointers to other memory objects or if they +  * might contain cycles. */ +    void gc_mark_type_as_referenced(struct pike_type *t)   {    if (gc_mark(t)) { -  if (Pike_in_gc == GC_PASS_COUNT_MEMORY) { -  gc_counted_bytes += sizeof (struct pike_type); -  gc_check_type (t); -  } -  +     GC_ENTER(t, PIKE_T_TYPE) {    switch(t->type) {    case PIKE_T_SCOPE:
7937:    }   }    - #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP) -  +    #ifdef PIKE_DEBUG   static void gc_mark_external_types(struct callback *cb, void *a, void *b)   {
7995: Inside #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP)
  }   #endif    + void gc_check_type (struct pike_type *t) + { +  debug_malloc_touch (t); +  +  GC_ENTER (t, T_TYPE) { +  switch (t->type) { +  case T_FUNCTION: +  case T_MANY: +  case T_TUPLE: +  case T_MAPPING: +  case T_OR: +  case T_AND: +  case PIKE_T_RING: +  case PIKE_T_ATTRIBUTE: +  case PIKE_T_NAME: +  debug_gc_check (t->car, " as car in a type"); +  debug_gc_check (t->cdr, " as cdr in a type"); +  break; +  case T_ARRAY: +  case T_MULTISET: +  case T_NOT: +  case T_TYPE: +  case T_PROGRAM: +  case T_STRING: +  debug_gc_check (t->car, " as car in a type"); +  break; +  case T_SCOPE: +  case T_ASSIGN: +  debug_gc_check (t->cdr, " as cdr in a type"); +  break; + #ifdef PIKE_DEBUG +  case '0': +  case '1': +  case '2': +  case '3': +  case '4': +  case '5': +  case '6': +  case '7': +  case '8': +  case '9': +  case T_FLOAT: +  case T_MIXED: +  case T_VOID: +  case T_ZERO: +  case PIKE_T_UNKNOWN: +  case T_INT: +  case T_OBJECT: +  break; +  default: +  Pike_fatal("gc_check_type: " +  "Unhandled type-node: %d\n", t->type); +  break; + #endif /* PIKE_DEBUG */ +  } +  } GC_LEAVE; + } +    void gc_check_all_types (void)   {    unsigned INT32 e;