Select Git revision
stralloc.c 8.17 KiB
#include "global.h"
#include "stralloc.h"
#include "macros.h"
#include "dynamic_buffer.h"
#include "macros.h"
#include "memory.h"
#include "error.h"
static struct lpc_string *base_table[HTABLE_SIZE];
static unsigned INT32 full_hash_value;
/*
*/
static unsigned int StrHash(const char *s,int len)
{
full_hash_value=hashmem((unsigned char *)s, len, 20);
return full_hash_value % HTABLE_SIZE;
}
#ifdef DEBUG
void check_string(struct lpc_string *s)
{
if(debug_findstring(s) !=s)
fatal("Shared string not shared.\n");
checked((void *)s,1);
}
void verify_shared_strings_tables(int pass)
{
unsigned int e, h;
struct lpc_string *s;
for(e=0;e<HTABLE_SIZE;e++)
{
h=0;
for(s=base_table[e];s;s=s->next)
{
if(pass)
{
if(checked((void *)s,0)!=s->refs)
{
fatal("Shared string has wrong number of refs '%s'.\n",s->str);
}
continue;
}
h++;
if(s->len < 0)
fatal("Shared string shorter than zero bytes.\n");
if(s->refs <= 0)
fatal("Shared string had too few references.\n");
if(s->str[s->len])
fatal("Shared string didn't end with a zero.\n");
if(StrHash(s->str, s->len) != e)
fatal("Shared string hashed to wrong place.\n");
if(s->hval != full_hash_value)
fatal("Shared string hashed to other number.\n");
if(h>10000)
{
struct lpc_string *s2;
for(s2=s;s2;s2=s2->next)
if(s2 == s)
fatal("Shared string table is cyclic.\n");
h=0;
}