Skip to content
Snippets Groups Projects
Select Git revision
  • 37f25f066869f4f5645288a9913ed65d53b14cfd
  • master default protected
  • 9.0
  • marcus/wix3
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

mapping.c

Blame
  • mapping.c 70.95 KiB
    /*
    || 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.
    */
    
    #include "global.h"
    #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 "pike_types.h"
    #include "dynamic_buffer.h"
    #include "interpret.h"
    #include "las.h"
    #include "gc.h"
    #include "stralloc.h"
    #include "pike_security.h"
    #include "block_allocator.h"
    #include "opcodes.h"
    #include "stuff.h"
    
    #define AVG_LINK_LENGTH 4
    #define MIN_LINK_LENGTH 1
    #define MAP_SLOTS(X) ((X)?((X)+((X)>>4)+8):0)
    
    struct mapping *first_mapping;
    
    struct mapping *gc_internal_mapping = 0;
    static struct mapping *gc_mark_mapping_pos = 0;
    
    #define unlink_mapping_data(M) do{				\
     struct mapping_data *md_=(M);					\
     if(md_->hardlinks) { md_->hardlinks--; md_->valrefs--; }	\
     free_mapping_data(M);						\
    }while(0)
    
    #define MAPPING_DATA_SIZE(HSIZE, KEYPAIRS) \
       PTR_TO_INT(MD_KEYPAIRS(0, HSIZE) + KEYPAIRS)
    
    static struct block_allocator mapping_allocator = BA_INIT_PAGES(sizeof(struct mapping), 2);
    void count_memory_in_mappings(size_t * num, size_t * size) {
        struct mapping *m;
        double datasize = 0.0;
        ba_count_all(&mapping_allocator, num, size);
        for(m=first_mapping;m;m=m->next) {
    	datasize+=MAPPING_DATA_SIZE(m->data->hashsize, m->data->num_keypairs) / (double) m->data->refs;
        }
        *size += (size_t) datasize;
    }
    
    void really_free_mapping(struct mapping * m) {
    #ifdef PIKE_DEBUG
      if (m->refs) {
    # ifdef DEBUG_MALLOC
        describe_something(m, T_MAPPING, 0,2,0, NULL);
    # endif
        Pike_fatal("really free mapping on mapping with %d refs.\n", m->refs);
      }
    #endif
      FREE_PROT(m);
      unlink_mapping_data(m->data);
      DOUBLEUNLINK(first_mapping, m);
      GC_FREE(m);
      ba_free(&mapping_allocator, m);
    }