summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2009-10-20 00:10:18 +0200
committerLudovic Courtès <ludo@gnu.org>2009-10-20 00:10:18 +0200
commitd587c9e8b27219e68f8813fb648fc6913c93be0f (patch)
treed407902e1f8a1bc25b365631be54f5d656b17662
parent416c9fb363a2b2f31382c5a488c6e27c31a3b62f (diff)
Use proper types for hash/assoc functions in `hashtab.h'.
Partly fixes bug #23681 ("Function declarators with empty parentheses should not be used"). * libguile/goops.c (scm_wrap_component): Cast `scm_sloppy_assq'. * libguile/hashtab.c (scm_hash_fn_get_handle): Update to take functions of type `scm_t_hash_fn' and `scm_t_assoc_fn'. Update callers. (scm_ihashx): Change to match `scm_t_hash_fn'. (scm_sloppy_assx): Change to match `scm_t_assoc_fn'. * libguile/hashtab.h (scm_t_hash_fn, scm_t_assoc_fn): New types. (scm_t_hashtable)[hash_fn]: Change to `scm_t_hash_fn'. (scm_i_rehash, scm_hash_fn_get_handle, scm_hash_fn_create_handle_x, scm_hash_fn_ref, scm_hash_fn_set_x, scm_hash_fn_remove_x): Change to take `scm_t_hash_fn' and `scm_t_assoc_fn' parameters. * libguile/srcprop.h (scm_whash_get_handle, scm_whash_create_handle, scm_whash_lookup): Implement in terms of `scm_hashq_*' instead of `scm_hash_fn_*'. * libguile/struct.c (scm_struct_ihashq): Change to match `scm_t_hash_fn'. (scm_struct_create_handle): Cast `scm_sloppy_assq'. * libguile/struct.h (scm_struct_ihashq): Update, make internal.
-rw-r--r--libguile/goops.c2
-rw-r--r--libguile/hashtab.c93
-rw-r--r--libguile/hashtab.h40
-rw-r--r--libguile/srcprop.h11
-rw-r--r--libguile/struct.c4
-rw-r--r--libguile/struct.h4
6 files changed, 116 insertions, 38 deletions
diff --git a/libguile/goops.c b/libguile/goops.c
index 4616fa240..44c277f75 100644
--- a/libguile/goops.c
+++ b/libguile/goops.c
@@ -3000,7 +3000,7 @@ scm_wrap_component (SCM class, SCM container, void *data)
obj,
SCM_BOOL_F,
scm_struct_ihashq,
- scm_sloppy_assq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
0);
SCM_SETCDR (handle, container);
return obj;
diff --git a/libguile/hashtab.c b/libguile/hashtab.c
index 5c03d281f..69d604a08 100644
--- a/libguile/hashtab.c
+++ b/libguile/hashtab.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -429,9 +429,13 @@ SCM_DEFINE (scm_doubly_weak_hash_table_p, "doubly-weak-hash-table?", 1, 0, 0,
}
#undef FUNC_NAME
+
+/* Accessing hash table entries. */
SCM
-scm_hash_fn_get_handle (SCM table, SCM obj, unsigned long (*hash_fn)(), SCM (*assoc_fn)(), void * closure)
+scm_hash_fn_get_handle (SCM table, SCM obj,
+ scm_t_hash_fn hash_fn, scm_t_assoc_fn assoc_fn,
+ void * closure)
#define FUNC_NAME "scm_hash_fn_get_handle"
{
int weak = 0;
@@ -659,7 +663,10 @@ SCM_DEFINE (scm_hashq_get_handle, "hashq-get-handle", 2, 0, 0,
"Uses @code{eq?} for equality testing.")
#define FUNC_NAME s_scm_hashq_get_handle
{
- return scm_hash_fn_get_handle (table, key, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_get_handle (table, key,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
@@ -671,7 +678,10 @@ SCM_DEFINE (scm_hashq_create_handle_x, "hashq-create-handle!", 3, 0, 0,
"associates @var{key} with @var{init}.")
#define FUNC_NAME s_scm_hashq_create_handle_x
{
- return scm_hash_fn_create_handle_x (table, key, init, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_create_handle_x (table, key, init,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
@@ -686,7 +696,10 @@ SCM_DEFINE (scm_hashq_ref, "hashq-ref", 2, 1, 0,
{
if (SCM_UNBNDP (dflt))
dflt = SCM_BOOL_F;
- return scm_hash_fn_ref (table, key, dflt, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_ref (table, key, dflt,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
@@ -698,7 +711,10 @@ SCM_DEFINE (scm_hashq_set_x, "hashq-set!", 3, 0, 0,
"store @var{value} there. Uses @code{eq?} for equality testing.")
#define FUNC_NAME s_scm_hashq_set_x
{
- return scm_hash_fn_set_x (table, key, val, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_set_x (table, key, val,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
@@ -710,7 +726,10 @@ SCM_DEFINE (scm_hashq_remove_x, "hashq-remove!", 2, 0, 0,
"@var{table}. Uses @code{eq?} for equality tests.")
#define FUNC_NAME s_scm_hashq_remove_x
{
- return scm_hash_fn_remove_x (table, key, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_remove_x (table, key,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
@@ -725,7 +744,10 @@ SCM_DEFINE (scm_hashv_get_handle, "hashv-get-handle", 2, 0, 0,
"Uses @code{eqv?} for equality testing.")
#define FUNC_NAME s_scm_hashv_get_handle
{
- return scm_hash_fn_get_handle (table, key, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_get_handle (table, key,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
@@ -737,8 +759,10 @@ SCM_DEFINE (scm_hashv_create_handle_x, "hashv-create-handle!", 3, 0, 0,
"associates @var{key} with @var{init}.")
#define FUNC_NAME s_scm_hashv_create_handle_x
{
- return scm_hash_fn_create_handle_x (table, key, init, scm_ihashv,
- scm_sloppy_assv, 0);
+ return scm_hash_fn_create_handle_x (table, key, init,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
@@ -753,7 +777,10 @@ SCM_DEFINE (scm_hashv_ref, "hashv-ref", 2, 1, 0,
{
if (SCM_UNBNDP (dflt))
dflt = SCM_BOOL_F;
- return scm_hash_fn_ref (table, key, dflt, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_ref (table, key, dflt,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
@@ -765,7 +792,10 @@ SCM_DEFINE (scm_hashv_set_x, "hashv-set!", 3, 0, 0,
"store @var{value} there. Uses @code{eqv?} for equality testing.")
#define FUNC_NAME s_scm_hashv_set_x
{
- return scm_hash_fn_set_x (table, key, val, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_set_x (table, key, val,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
@@ -776,7 +806,10 @@ SCM_DEFINE (scm_hashv_remove_x, "hashv-remove!", 2, 0, 0,
"@var{table}. Uses @code{eqv?} for equality tests.")
#define FUNC_NAME s_scm_hashv_remove_x
{
- return scm_hash_fn_remove_x (table, key, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_remove_x (table, key,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
@@ -790,7 +823,10 @@ SCM_DEFINE (scm_hash_get_handle, "hash-get-handle", 2, 0, 0,
"Uses @code{equal?} for equality testing.")
#define FUNC_NAME s_scm_hash_get_handle
{
- return scm_hash_fn_get_handle (table, key, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_get_handle (table, key,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
@@ -802,7 +838,10 @@ SCM_DEFINE (scm_hash_create_handle_x, "hash-create-handle!", 3, 0, 0,
"associates @var{key} with @var{init}.")
#define FUNC_NAME s_scm_hash_create_handle_x
{
- return scm_hash_fn_create_handle_x (table, key, init, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_create_handle_x (table, key, init,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
@@ -817,7 +856,10 @@ SCM_DEFINE (scm_hash_ref, "hash-ref", 2, 1, 0,
{
if (SCM_UNBNDP (dflt))
dflt = SCM_BOOL_F;
- return scm_hash_fn_ref (table, key, dflt, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_ref (table, key, dflt,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
@@ -830,7 +872,10 @@ SCM_DEFINE (scm_hash_set_x, "hash-set!", 3, 0, 0,
"testing.")
#define FUNC_NAME s_scm_hash_set_x
{
- return scm_hash_fn_set_x (table, key, val, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_set_x (table, key, val,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
@@ -842,7 +887,10 @@ SCM_DEFINE (scm_hash_remove_x, "hash-remove!", 2, 0, 0,
"@var{table}. Uses @code{equal?} for equality tests.")
#define FUNC_NAME s_scm_hash_remove_x
{
- return scm_hash_fn_remove_x (table, key, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_remove_x (table, key,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
@@ -858,17 +906,20 @@ typedef struct scm_t_ihashx_closure
static unsigned long
-scm_ihashx (SCM obj, unsigned long n, scm_t_ihashx_closure *closure)
+scm_ihashx (SCM obj, unsigned long n, void *arg)
{
- SCM answer = scm_call_2 (closure->hash, obj, scm_from_ulong (n));
+ SCM answer;
+ scm_t_ihashx_closure *closure = (scm_t_ihashx_closure *) arg;
+ answer = scm_call_2 (closure->hash, obj, scm_from_ulong (n));
return scm_to_ulong (answer);
}
static SCM
-scm_sloppy_assx (SCM obj, SCM alist, scm_t_ihashx_closure *closure)
+scm_sloppy_assx (SCM obj, SCM alist, void *arg)
{
+ scm_t_ihashx_closure *closure = (scm_t_ihashx_closure *) arg;
return scm_call_2 (closure->assoc, obj, alist);
}
diff --git a/libguile/hashtab.h b/libguile/hashtab.h
index 8f8ebf9ce..f72e8ab08 100644
--- a/libguile/hashtab.h
+++ b/libguile/hashtab.h
@@ -3,7 +3,7 @@
#ifndef SCM_HASHTAB_H
#define SCM_HASHTAB_H
-/* Copyright (C) 1995,1996,1999,2000,2001, 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1999,2000,2001, 2003, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -64,6 +64,14 @@ SCM_API scm_t_bits scm_tc16_hashtable;
#define SCM_SET_HASHTABLE_BUCKET(h, i, x) \
SCM_SIMPLE_VECTOR_SET (SCM_HASHTABLE_VECTOR (h), i, x)
+/* Function that computes a hash of OBJ modulo MAX. */
+typedef unsigned long (*scm_t_hash_fn) (SCM obj, unsigned long max,
+ void *closure);
+
+/* Function that returns the value associated with OBJ in ALIST according to
+ some equality predicate. */
+typedef SCM (*scm_t_assoc_fn) (SCM obj, SCM alist, void *closure);
+
typedef struct scm_t_hashtable {
int flags; /* properties of table */
unsigned long n_items; /* number of items in table */
@@ -71,7 +79,7 @@ typedef struct scm_t_hashtable {
unsigned long upper; /* when to grow */
int size_index; /* index into hashtable_size */
int min_size_index; /* minimum size_index */
- unsigned long (*hash_fn) (); /* for rehashing after a GC. */
+ scm_t_hash_fn hash_fn; /* for rehashing after a GC. */
} scm_t_hashtable;
@@ -94,14 +102,30 @@ SCM_API SCM scm_weak_key_hash_table_p (SCM h);
SCM_API SCM scm_weak_value_hash_table_p (SCM h);
SCM_API SCM scm_doubly_weak_hash_table_p (SCM h);
-SCM_INTERNAL void scm_i_rehash (SCM table, unsigned long (*hash_fn)(),
+SCM_INTERNAL void scm_i_rehash (SCM table, scm_t_hash_fn hash_fn,
void *closure, const char *func_name);
-SCM_API SCM scm_hash_fn_get_handle (SCM table, SCM obj, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_create_handle_x (SCM table, SCM obj, SCM init, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_ref (SCM table, SCM obj, SCM dflt, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_set_x (SCM table, SCM obj, SCM val, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_remove_x (SCM table, SCM obj, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
+
+SCM_API SCM scm_hash_fn_get_handle (SCM table, SCM obj,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+SCM_API SCM scm_hash_fn_create_handle_x (SCM table, SCM obj, SCM init,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+SCM_API SCM scm_hash_fn_ref (SCM table, SCM obj, SCM dflt,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+SCM_API SCM scm_hash_fn_set_x (SCM table, SCM obj, SCM val,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+SCM_API SCM scm_hash_fn_remove_x (SCM table, SCM obj,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
SCM_API SCM scm_internal_hash_fold (SCM (*fn) (), void *closure, SCM init, SCM table);
SCM_API void scm_internal_hash_for_each_handle (SCM (*fn) (), void *closure, SCM table);
SCM_API SCM scm_hash_clear_x (SCM table);
diff --git a/libguile/srcprop.h b/libguile/srcprop.h
index 89063bed4..ca8818ac4 100644
--- a/libguile/srcprop.h
+++ b/libguile/srcprop.h
@@ -3,7 +3,7 @@
#ifndef SCM_SRCPROP_H
#define SCM_SRCPROP_H
-/* Copyright (C) 1995,1996,2000,2001, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,2000,2001, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -35,12 +35,15 @@
#define scm_whash_handle SCM
-#define scm_whash_get_handle(whash, key) scm_hash_fn_get_handle (whash, key, scm_ihashq, scm_sloppy_assq, 0)
+#define scm_whash_get_handle(whash, key) \
+ scm_hashq_get_handle ((whash), (key))
#define SCM_WHASHFOUNDP(h) (scm_is_true (h))
#define SCM_WHASHREF(whash, handle) SCM_CDR (handle)
#define SCM_WHASHSET(whash, handle, obj) SCM_SETCDR (handle, obj)
-#define scm_whash_create_handle(whash, key) scm_hash_fn_create_handle_x (whash, key, SCM_UNSPECIFIED, scm_ihashq, scm_sloppy_assq, 0)
-#define scm_whash_lookup(whash, obj) scm_hash_fn_ref (whash, obj, SCM_BOOL_F, scm_ihashq, scm_sloppy_assq, 0)
+#define scm_whash_create_handle(whash, key) \
+ scm_hashq_create_handle_x ((whash), (key), SCM_UNSPECIFIED)
+#define scm_whash_lookup(whash, obj) \
+ scm_hashq_ref ((whash), (obj), SCM_BOOL_F)
#define scm_whash_insert(whash, key, obj) \
do { \
register SCM w = (whash); \
diff --git a/libguile/struct.c b/libguile/struct.c
index 7b25f7fef..9dd900e37 100644
--- a/libguile/struct.c
+++ b/libguile/struct.c
@@ -795,7 +795,7 @@ SCM_DEFINE (scm_struct_vtable_tag, "struct-vtable-tag", 1, 0, 0,
*/
unsigned long
-scm_struct_ihashq (SCM obj, unsigned long n)
+scm_struct_ihashq (SCM obj, unsigned long n, void *closure)
{
/* The length of the hash table should be a relative prime it's not
necessary to shift down the address. */
@@ -809,7 +809,7 @@ scm_struct_create_handle (SCM obj)
obj,
SCM_BOOL_F,
scm_struct_ihashq,
- scm_sloppy_assq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
0);
if (scm_is_false (SCM_CDR (handle)))
SCM_SETCDR (handle, scm_cons (SCM_BOOL_F, SCM_BOOL_F));
diff --git a/libguile/struct.h b/libguile/struct.h
index 12069b487..a4626f3dd 100644
--- a/libguile/struct.h
+++ b/libguile/struct.h
@@ -3,7 +3,7 @@
#ifndef SCM_STRUCT_H
#define SCM_STRUCT_H
-/* Copyright (C) 1995,1997,1999,2000,2001, 2006, 2007, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1997,1999,2000,2001, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -96,7 +96,7 @@ SCM_API SCM scm_struct_ref (SCM handle, SCM pos);
SCM_API SCM scm_struct_set_x (SCM handle, SCM pos, SCM val);
SCM_API SCM scm_struct_vtable (SCM handle);
SCM_API SCM scm_struct_vtable_tag (SCM handle);
-SCM_API unsigned long scm_struct_ihashq (SCM obj, unsigned long n);
+SCM_INTERNAL unsigned long scm_struct_ihashq (SCM, unsigned long, void *);
SCM_API SCM scm_struct_create_handle (SCM obj);
SCM_API SCM scm_struct_vtable_name (SCM vtable);
SCM_API SCM scm_set_struct_vtable_name_x (SCM vtable, SCM name);