mirror of
https://github.com/json-c/json-c.git
synced 2026-04-04 21:09:06 +08:00
* printbuf.c - C. Watford (christopher dot watford at gmail dot com)
Added a Win32/Win64 compliant implementation of vasprintf
* debug.c - C. Watford (christopher dot watford at gmail dot com)
Removed usage of vsyslog on Win32/Win64 systems, needs to be handled
by a configure script
* json_object.c - C. Watford (christopher dot watford at gmail dot com)
Added scope operator to wrap usage of json_object_object_foreach, this
needs to be rethought to be more ANSI C friendly
* json_object.h - C. Watford (christopher dot watford at gmail dot com)
Added Microsoft C friendly version of json_object_object_foreach
* json_tokener.c - C. Watford (christopher dot watford at gmail dot com)
Added a Win32/Win64 compliant implementation of strndup
* json_util.c - C. Watford (christopher dot watford at gmail dot com)
Added cast and mask to suffice size_t v. unsigned int conversion
correctness
* json_tokener.c - sign reversal issue on error info for nested object parse
spotted by Johan Bj�rklund (johbjo09 at kth.se)
* json_object.c - escape " in json_escape_str
* Change to automake and libtool to build shared and static library
Michael Clark <michael@metaparadigm.com>
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@4 327403b1-1117-474d-bef2-5cb71233fd97
This commit is contained in:
25
linkhash.c
25
linkhash.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: linkhash.c,v 1.2 2004/07/21 01:24:33 mclark Exp $
|
||||
* $Id: linkhash.c,v 1.3 2005/06/14 22:41:51 mclark Exp $
|
||||
*
|
||||
* Copyright Metaparadigm Pte. Ltd. 2004.
|
||||
* Michael Clark <michael@metaparadigm.com>
|
||||
@@ -16,14 +16,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "linkhash.h"
|
||||
|
||||
|
||||
void lh_abort(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@@ -32,19 +35,17 @@ void lh_abort(const char *msg, ...)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
unsigned long lh_ptr_hash(void *k)
|
||||
{
|
||||
return ((long)k * LH_PRIME) >> 4;
|
||||
/* CAW: refactored to be 64bit nice */
|
||||
return (unsigned long)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
int lh_ptr_equal(void *k1, void *k2)
|
||||
{
|
||||
return (k1 == k2);
|
||||
}
|
||||
|
||||
|
||||
unsigned long lh_char_hash(void *k)
|
||||
{
|
||||
unsigned int h = 0;
|
||||
@@ -55,13 +56,11 @@ unsigned long lh_char_hash(void *k)
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
int lh_char_equal(void *k1, void *k2)
|
||||
{
|
||||
return (strcmp((char*)k1, (char*)k2) == 0);
|
||||
}
|
||||
|
||||
|
||||
struct lh_table* lh_table_new(int size, char *name,
|
||||
lh_entry_free_fn *free_fn,
|
||||
lh_hash_fn *hash_fn,
|
||||
@@ -84,21 +83,18 @@ struct lh_table* lh_table_new(int size, char *name,
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
struct lh_table* lh_kchar_table_new(int size, char *name,
|
||||
lh_entry_free_fn *free_fn)
|
||||
{
|
||||
return lh_table_new(size, name, free_fn, lh_char_hash, lh_char_equal);
|
||||
}
|
||||
|
||||
|
||||
struct lh_table* lh_kptr_table_new(int size, char *name,
|
||||
lh_entry_free_fn *free_fn)
|
||||
{
|
||||
return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal);
|
||||
}
|
||||
|
||||
|
||||
void lh_table_resize(struct lh_table *t, int new_size)
|
||||
{
|
||||
struct lh_table *new_t;
|
||||
@@ -119,7 +115,6 @@ void lh_table_resize(struct lh_table *t, int new_size)
|
||||
free(new_t);
|
||||
}
|
||||
|
||||
|
||||
void lh_table_free(struct lh_table *t)
|
||||
{
|
||||
struct lh_entry *c;
|
||||
@@ -193,7 +188,11 @@ void* lh_table_lookup(struct lh_table *t, void *k)
|
||||
|
||||
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
|
||||
{
|
||||
int n = e - t->table;
|
||||
ptrdiff_t n = (ptrdiff_t)(e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy negative case... */
|
||||
|
||||
/* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */
|
||||
if(n < 0) { return -2; }
|
||||
|
||||
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) return -1;
|
||||
t->count--;
|
||||
if(t->free_fn) t->free_fn(e);
|
||||
|
||||
Reference in New Issue
Block a user