Author: petdance
Date: Fri Feb 22 11:50:00 2008
New Revision: 25993

Modified:
   trunk/compilers/imcc/imcc.l
   trunk/compilers/imcc/imclexer.c
   trunk/include/parrot/exceptions.h
   trunk/include/parrot/hash.h
   trunk/src/hash.c

Log:
Heavy consting of hash-key building.  This is the first true consting I have 
been able to do lately.

Modified: trunk/compilers/imcc/imcc.l
==============================================================================
--- trunk/compilers/imcc/imcc.l (original)
+++ trunk/compilers/imcc/imcc.l Fri Feb 22 11:50:00 2008
@@ -1076,13 +1076,10 @@
 static macro_t *
 find_macro(Interp *interp, const char *name)
 {
-    DECL_CONST_CAST_OF(char);
-
     if (!IMCC_INFO(interp)->macros)
         return NULL;
 
-    return (macro_t *)parrot_hash_get(interp,
-        IMCC_INFO(interp)->macros, const_cast(name));
+    return (macro_t *)parrot_hash_get(interp, IMCC_INFO(interp)->macros, name);
 }
 
 static int

Modified: trunk/compilers/imcc/imclexer.c
==============================================================================
--- trunk/compilers/imcc/imclexer.c     (original)
+++ trunk/compilers/imcc/imclexer.c     Fri Feb 22 11:50:00 2008
@@ -5752,13 +5752,10 @@
 static macro_t *
 find_macro(Interp *interp, const char *name)
 {
-    DECL_CONST_CAST_OF(char);
-
     if (!IMCC_INFO(interp)->macros)
         return NULL;
 
-    return (macro_t *)parrot_hash_get(interp,
-        IMCC_INFO(interp)->macros, const_cast(name));
+    return (macro_t *)parrot_hash_get(interp, IMCC_INFO(interp)->macros, name);
 }
 
 static int

Modified: trunk/include/parrot/exceptions.h
==============================================================================
--- trunk/include/parrot/exceptions.h   (original)
+++ trunk/include/parrot/exceptions.h   Fri Feb 22 11:50:00 2008
@@ -193,7 +193,7 @@
 PARROT_API
 PARROT_DOES_NOT_RETURN_WHEN_FALSE
 void Parrot_assert(
-    long condition,
+    INTVAL condition,
     ARGIN(const char *condition_string),
     ARGIN(const char *file),
     unsigned int line)

Modified: trunk/include/parrot/hash.h
==============================================================================
--- trunk/include/parrot/hash.h (original)
+++ trunk/include/parrot/hash.h Fri Feb 22 11:50:00 2008
@@ -40,7 +40,7 @@
 
 typedef int (*hash_comp_fn)(PARROT_INTERP, const void*const, const void*const);
 typedef void (*hash_mark_key_fn)(PARROT_INTERP, PObj *);
-typedef size_t (*hash_hash_key_fn)(PARROT_INTERP, NOTNULL(void*), size_t seed);
+typedef size_t (*hash_hash_key_fn)(PARROT_INTERP, ARGIN(const void *), size_t 
seed);
 
 typedef enum {
     Hash_key_type_int,
@@ -110,7 +110,9 @@
 PARROT_API
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
-void * parrot_hash_get(PARROT_INTERP, ARGIN(Hash *hash), ARGIN(void *key))
+void * parrot_hash_get(PARROT_INTERP,
+    ARGIN(Hash *hash),
+    ARGIN(const void *key))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         __attribute__nonnull__(3);
@@ -120,7 +122,7 @@
 PARROT_CAN_RETURN_NULL
 HashBucket * parrot_hash_get_bucket(PARROT_INTERP,
     ARGIN(const Hash *hash),
-    ARGIN(void *key))
+    ARGIN(const void *key))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         __attribute__nonnull__(3);
@@ -203,7 +205,7 @@
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
-size_t key_hash_int(SHIM_INTERP, ARGIN(void *value), size_t seed)
+size_t key_hash_int(SHIM_INTERP, ARGIN(const void *value), size_t seed)
         __attribute__nonnull__(2);
 
 void parrot_chash_destroy(PARROT_INTERP, ARGMOD(Hash *hash))

Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c    (original)
+++ trunk/src/hash.c    Fri Feb 22 11:50:00 2008
@@ -89,7 +89,9 @@
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
-static size_t key_hash_pointer(SHIM_INTERP, ARGIN(void *value), size_t seed)
+static size_t key_hash_pointer(SHIM_INTERP,
+    ARGIN(const void *value),
+    size_t seed)
         __attribute__nonnull__(2);
 
 PARROT_WARN_UNUSED_RESULT
@@ -186,7 +188,7 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
 static size_t
-key_hash_pointer(SHIM_INTERP, ARGIN(void *value), size_t seed)
+key_hash_pointer(SHIM_INTERP, ARGIN(const void *value), size_t seed)
 {
     return ((size_t) value) ^ seed;
 }
@@ -247,7 +249,7 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
 size_t
-key_hash_int(SHIM_INTERP, ARGIN(void *value), size_t seed)
+key_hash_int(SHIM_INTERP, ARGIN(const void *value), size_t seed)
 {
     return (size_t)value ^ seed;
 }
@@ -846,8 +848,7 @@
 void
 parrot_new_pointer_hash(SHIM_INTERP, ARGOUT(Hash **hptr))
 {
-    parrot_new_hash_x(hptr, enum_type_ptr, Hash_key_type_ptr,
-                        pointer_compare, key_hash_pointer);
+    parrot_new_hash_x(hptr, enum_type_ptr, Hash_key_type_ptr, pointer_compare, 
key_hash_pointer);
 }
 
 /*
@@ -966,13 +967,9 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 HashBucket *
-parrot_hash_get_bucket(PARROT_INTERP, ARGIN(const Hash *hash), ARGIN(void 
*key))
+parrot_hash_get_bucket(PARROT_INTERP, ARGIN(const Hash *hash), ARGIN(const 
void *key))
 {
-    if (hash->entries == 0)
-        return NULL;
-
-    /* this block here should be C89-safe; const is very nice on hashval */
-    {
+    if (hash->entries > 0) {
         const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
         HashBucket   *bucket  = hash->bi[hashval & hash->mask];
 
@@ -1001,7 +998,7 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 void *
-parrot_hash_get(PARROT_INTERP, ARGIN(Hash *hash), ARGIN(void *key))
+parrot_hash_get(PARROT_INTERP, ARGIN(Hash *hash), ARGIN(const void *key))
 {
     const HashBucket * const bucket = parrot_hash_get_bucket(interp, hash, 
key);
     return bucket ? bucket->value : NULL;

Reply via email to