summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-05-17 16:52:15 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-05-17 16:52:15 +0000
commit5afd6d4225c4773e6506b9fc3c8ca61abeea89a5 (patch)
treeb4ae3bf910381858eed9b9c567b1cd88571362f0 /hv.h
parentb194b55204233387f5607cc8e73f91aec4b9abc2 (diff)
downloadperl-5afd6d4225c4773e6506b9fc3c8ca61abeea89a5.tar.gz
PERL_HASH() casting games so that our hashed data is "unsigned
char" but old code using just a "char" doesn't need changes. (The change is using a temporary pointer instead of a direct cast to unsigned char* which would blindly cast anything, not just char pointers.) (The problem arose in MacOS Classic, as seen by Pudge, the cure by Nicholas Clark.) p4raw-id: //depot/perl@16656
Diffstat (limited to 'hv.h')
-rw-r--r--hv.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/hv.h b/hv.h
index 4979fdd8b6..16b14828e2 100644
--- a/hv.h
+++ b/hv.h
@@ -47,12 +47,19 @@ struct xpvhv {
};
/* hash a key */
-/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */
-/* from requirements by Colin Plumb. */
-/* (http://burtleburtle.net/bob/hash/doobs.html) */
+/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins
+ * from requirements by Colin Plumb.
+ * (http://burtleburtle.net/bob/hash/doobs.html) */
+/* The use of a temporary pointer and the casting games
+ * is needed to serve the dual purposes of
+ * (a) the hashed data being interpreted as "unsigned char" (new since 5.8,
+ * a "char" can be either signed or signed, depending on the compiler)
+ * (b) catering for old code that uses a "char"
+ */
#define PERL_HASH(hash,str,len) \
STMT_START { \
- register const unsigned char *s_PeRlHaSh = str; \
+ register const char *s_PeRlHaSh_tmp = str; \
+ register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \
register I32 i_PeRlHaSh = len; \
register U32 hash_PeRlHaSh = 0; \
while (i_PeRlHaSh--) { \