Moved assert_type_hash_table() to hash.d and added more information to the error message.

This commit is contained in:
Juan Jose Garcia Ripoll 2010-02-25 21:55:03 +01:00
parent e664971e42
commit c41efce884
3 changed files with 21 additions and 22 deletions

View file

@ -27,6 +27,13 @@ static void corrupted_hash(cl_object hashtable) /*__attribute__((noreturn))*/;
#define SYMBOL_NAME(x) (Null(x)? Cnil_symbol->symbol.name : (x)->symbol.name)
static void
assert_type_hash_table(cl_object fun, cl_narg narg, cl_object p)
{
if (type_of(p) != t_hashtable)
FEwrong_type_nth_arg(function, narg, p, @'hash-table');
}
static void
corrupted_hash(cl_object hashtable)
{
@ -409,7 +416,7 @@ ecl_gethash(cl_object key, cl_object hashtable)
{
cl_object output;
assert_type_hash_table(hashtable);
assert_type_hash_table(@'gethash', 2, hashtable);
HASH_TABLE_LOCK(hashtable);
output = hashtable->hash.get(key, hashtable)->value;
HASH_TABLE_UNLOCK(hashtable);
@ -421,7 +428,7 @@ ecl_gethash_safe(cl_object key, cl_object hashtable, cl_object def)
{
struct ecl_hashtable_entry *e;
assert_type_hash_table(hashtable);
assert_type_hash_table(@'gethash', 2, hashtable);
HASH_TABLE_LOCK(hashtable);
e = hashtable->hash.get(key, hashtable);
if (e->key != OBJNULL)
@ -439,7 +446,7 @@ _ecl_sethash(cl_object key, cl_object hashtable, cl_object value)
cl_object
ecl_sethash(cl_object key, cl_object hashtable, cl_object value)
{
assert_type_hash_table(hashtable);
assert_type_hash_table(@'si::sethash', 2, hashtable);
HASH_TABLE_LOCK(hashtable);
hashtable = hashtable->hash.set(key, hashtable, value);
HASH_TABLE_UNLOCK(hashtable);
@ -453,7 +460,7 @@ ecl_extend_hashtable(cl_object hashtable)
cl_index old_size, new_size, i;
cl_object new_size_obj;
assert_type_hash_table(hashtable);
assert_type_hash_table(@'si::sethash', 2, hashtable);
old_size = hashtable->hash.size;
/* We do the computation with lisp datatypes, just in case the sizes contain
* weird numbers */
@ -632,7 +639,7 @@ cl_hash_table_p(cl_object ht)
@(defun gethash (key ht &optional (no_value Cnil))
struct ecl_hashtable_entry e;
@
assert_type_hash_table(ht);
assert_type_hash_table(@'gethash', 2, ht);
HASH_TABLE_LOCK(ht);
e = *(ht->hash.get(key, ht));
HASH_TABLE_UNLOCK(ht);
@ -656,7 +663,7 @@ ecl_remhash(cl_object key, cl_object hashtable)
struct ecl_hashtable_entry *e;
bool output;
assert_type_hash_table(hashtable);
assert_type_hash_table(@'remhash', 2, hashtable);
HASH_TABLE_LOCK(hashtable);
e = hashtable->hash.get(key, hashtable);
if (e->key == OBJNULL) {
@ -681,7 +688,7 @@ cl_remhash(cl_object key, cl_object ht)
cl_object
cl_clrhash(cl_object ht)
{
assert_type_hash_table(ht);
assert_type_hash_table(@'clrhash', 1, ht);
if (ht->hash.entries) {
HASH_TABLE_LOCK(ht);
do_clrhash(ht);
@ -694,7 +701,7 @@ cl_object
cl_hash_table_test(cl_object ht)
{
cl_object output;
assert_type_hash_table(ht);
assert_type_hash_table(@'hash-table-test', 1, ht);
switch(ht->hash.test) {
case htt_eq: output = @'eq'; break;
case htt_eql: output = @'eql'; break;
@ -709,14 +716,14 @@ cl_hash_table_test(cl_object ht)
cl_object
cl_hash_table_size(cl_object ht)
{
assert_type_hash_table(ht);
assert_type_hash_table(@'hash-table-size', 1, ht);
@(return MAKE_FIXNUM(ht->hash.size))
}
cl_object
cl_hash_table_count(cl_object ht)
{
assert_type_hash_table(ht);
assert_type_hash_table(@'hash-table-count', 1, ht);
@(return (MAKE_FIXNUM(ht->hash.entries)))
}
@ -748,7 +755,7 @@ si_hash_table_iterate(cl_narg narg)
cl_object
si_hash_table_iterator(cl_object ht)
{
assert_type_hash_table(ht);
assert_type_hash_table(@'si::hash-table-iterator', 1, ht);
@(return ecl_make_cclosure_va((cl_objectfn)si_hash_table_iterate,
cl_list(2, MAKE_FIXNUM(-1), ht),
@'si::hash-table-iterator'))
@ -757,14 +764,14 @@ si_hash_table_iterator(cl_object ht)
cl_object
cl_hash_table_rehash_size(cl_object ht)
{
assert_type_hash_table(ht);
assert_type_hash_table(@'hash-table-rehash-size', 1, ht);
@(return ht->hash.rehash_size)
}
cl_object
cl_hash_table_rehash_threshold(cl_object ht)
{
assert_type_hash_table(ht);
assert_type_hash_table(@'hash-table-rehash-threshold', 1, ht);
@(return ht->hash.threshold)
}
@ -811,7 +818,7 @@ cl_maphash(cl_object fun, cl_object ht)
{
cl_index i;
assert_type_hash_table(ht);
assert_type_hash_table(@'maphash', 2, ht);
for (i = 0; i < ht->hash.size; i++) {
struct ecl_hashtable_entry e = ht->hash.data[i];
if(e.key != OBJNULL)

View file

@ -231,13 +231,6 @@ assert_type_proper_list(cl_object p)
FEcircular_list(p);
}
void
assert_type_hash_table(cl_object p)
{
if (type_of(p) != t_hashtable)
FEwrong_type_argument(@'hash-table', p);
}
cl_object
cl_type_of(cl_object x)
{

View file

@ -1686,7 +1686,6 @@ extern ECL_API cl_object cl_get_universal_time(void);
extern ECL_API void assert_type_integer(cl_object p);
extern ECL_API void assert_type_non_negative_integer(cl_object p);
extern ECL_API void assert_type_hash_table(cl_object p);
extern ECL_API void assert_type_proper_list(cl_object p);
extern ECL_API cl_object cl_type_of(cl_object x);