[svn:parrot] r41523 - in trunk: include/parrot src src/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sun Sep 27 09:33:58 UTC 2009


Author: bacek
Date: Sun Sep 27 09:33:58 2009
New Revision: 41523
URL: https://trac.parrot.org/parrot/changeset/41523

Log:
[cage] Change signature of PMC_compare and hash_key_PMC to avoid casing void*

Modified:
   trunk/include/parrot/hash.h
   trunk/src/hash.c
   trunk/src/pmc/hash.pmc

Modified: trunk/include/parrot/hash.h
==============================================================================
--- trunk/include/parrot/hash.h	Sun Sep 27 09:28:30 2009	(r41522)
+++ trunk/include/parrot/hash.h	Sun Sep 27 09:33:58 2009	(r41523)
@@ -326,10 +326,9 @@
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
-size_t key_hash_PMC(PARROT_INTERP,
-    ARGIN_NULLOK(const void *value),
-    NULLOK(size_t seed))
-        __attribute__nonnull__(1);
+size_t key_hash_PMC(PARROT_INTERP, ARGIN(PMC *value), NULLOK(size_t seed))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
 
 PARROT_WARN_UNUSED_RESULT
 size_t key_hash_STRING(PARROT_INTERP,
@@ -366,10 +365,9 @@
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
-int PMC_compare(PARROT_INTERP,
-    ARGIN_NULLOK(const void *a),
-    ARGIN_NULLOK(const void *b))
-        __attribute__nonnull__(1);
+int PMC_compare(PARROT_INTERP, ARGIN(PMC *a), ARGIN_NULLOK(PMC *b))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
@@ -487,7 +485,8 @@
 #define ASSERT_ARGS_int_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
 #define ASSERT_ARGS_key_hash_int __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
 #define ASSERT_ARGS_key_hash_PMC __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp)
+       PARROT_ASSERT_ARG(interp) \
+    && PARROT_ASSERT_ARG(value)
 #define ASSERT_ARGS_key_hash_STRING __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     && PARROT_ASSERT_ARG(s)
@@ -503,7 +502,8 @@
     && PARROT_ASSERT_ARG(compare) \
     && PARROT_ASSERT_ARG(keyhash)
 #define ASSERT_ARGS_PMC_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp)
+       PARROT_ASSERT_ARG(interp) \
+    && PARROT_ASSERT_ARG(a)
 #define ASSERT_ARGS_pointer_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
 #define ASSERT_ARGS_STRING_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \

Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c	Sun Sep 27 09:28:30 2009	(r41522)
+++ trunk/src/hash.c	Sun Sep 27 09:33:58 2009	(r41523)
@@ -283,7 +283,7 @@
 
 /*
 
-=item C<size_t key_hash_PMC(PARROT_INTERP, const void *value, size_t seed)>
+=item C<size_t key_hash_PMC(PARROT_INTERP, PMC *value, size_t seed)>
 
 Returns a hashed value for an PMC key (passed as a void pointer, sadly).
 
@@ -294,16 +294,15 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
 size_t
-key_hash_PMC(PARROT_INTERP, ARGIN_NULLOK(const void *value), SHIM(size_t seed))
+key_hash_PMC(PARROT_INTERP, ARGIN(PMC *value), SHIM(size_t seed))
 {
     ASSERT_ARGS(key_hash_PMC)
-    DECL_CONST_CAST;
-    return VTABLE_hashvalue(interp, PARROT_const_cast(PMC *, value));
+    return VTABLE_hashvalue(interp, value);
 }
 
 /*
 
-=item C<int PMC_compare(PARROT_INTERP, const void *a, const void *b)>
+=item C<int PMC_compare(PARROT_INTERP, PMC *a, PMC *b)>
 
 Compares two PMC for equality, returning 0 if the first is equal to second.
 Uses void pointers to store the PMC, sadly.
@@ -315,22 +314,19 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
 int
-PMC_compare(PARROT_INTERP, ARGIN_NULLOK(const void *a), ARGIN_NULLOK(const void *b))
+PMC_compare(PARROT_INTERP, ARGIN(PMC *a), ARGIN_NULLOK(PMC *b))
 {
     ASSERT_ARGS(PMC_compare)
-    DECL_CONST_CAST;
-    PMC * left  = PARROT_const_cast(PMC *, a);
-    PMC * right = PARROT_const_cast(PMC *, b);
 
     /* If pointers are same - PMCs are same */
-    if (left == right)
+    if (a == b)
         return 0;
 
     /* PMCs of different types are differ */
-    if (left->vtable->base_type != right->vtable->base_type)
+    if (a->vtable->base_type != b->vtable->base_type)
         return 1;
 
-    return !VTABLE_is_equal(interp, left, right);
+    return !VTABLE_is_equal(interp, a, b);
 }
 
 /*

Modified: trunk/src/pmc/hash.pmc
==============================================================================
--- trunk/src/pmc/hash.pmc	Sun Sep 27 09:28:30 2009	(r41522)
+++ trunk/src/pmc/hash.pmc	Sun Sep 27 09:33:58 2009	(r41523)
@@ -159,8 +159,8 @@
             new_hash = parrot_create_hash(interp,
                     entry_type,
                     Hash_key_type_PMC,
-                    PMC_compare,
-                    key_hash_PMC);
+                    (hash_comp_fn)PMC_compare,
+                    (hash_hash_key_fn)key_hash_PMC);
         else if (type == Hash_key_type_STRING)
             /* new_int_hash set BOTH keys and values to INTVAL */
             new_hash = parrot_create_hash(interp,


More information about the parrot-commits mailing list