Select Git revision
Forked from
Nettle / nettle
Source project has a limited visibility.
-
Niels Möller authoredNiels Möller authored
mapping.c 70.57 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);
}