shithub: freetype+ttf2subf

Download patch

ref: 3512a71269d8916bf93c324d6058ab3a535dbb08
parent: 61590b73d176ee5bb5adf02fe87886ee8286ffdc
author: suzuki toshiya <[email protected]>
date: Sun Oct 24 22:07:52 EDT 2010

[cache] Change the hash types to FT_PtrDist.

On LLP64 platforms (e.g. Win64), FT_ULong (32-bit)
variables are inappropriate to calculate hash values
from the memory address (64-bit).  The hash variables
are extended from FT_ULong to FT_PtrDist and new
hashing macro functions are introduced.  The hash
values on 16-bit memory platforms are changed, but
ILP32 and LP64 are not changed.  The hash value in
the cache subsystem is not reverted to the memory
address, so using signed type FT_PtrDist is safe.

* src/cache/ftccache.h (_FTC_FACE_ID_HASH): New hash
function to replace FTC_FACE_ID_HASH() for portability.
* src/cache/ftcmanag.h (FTC_SCALER_HASH): Replace
FTC_FACE_ID_HASH() by _FTC_FACE_ID_HASH().
* src/cache/ftccmap.c (FTC_CMAP_HASH): Ditto.

* src/cache/ftccache.h (FTC_NodeRec): The type of the
member `hash' is changed from FT_UInt32 to FT_PtrDist.

* src/cache/ftccache.h (FTC_Cache_Lookup): The type of the
argument `hash' is changed from FT_UInt32 to FT_PtrDist.
(FTC_Cache_NewNode): Ditto.
* src/cache/ftccache.c (ftc_cache_add): Ditto.
(FTC_Cache_Lookup): Ditto.  (FTC_Cache_NewNode): Ditto.
* src/cache/ftcglyph.h (FTC_GCache_Lookup): Ditto.
* src/cache/ftcglyph.c (FTC_GCache_Lookup): Ditto.

* src/cache/ftcbasic.c (FTC_ImageCache_Lookup): The type
of the internal variable `hash' is changed to FT_PtrDist
from FT_UInt32.  (FTC_ImageCache_LookupScaler): Ditto.
(FTC_SBitCache_Lookup): Ditto.
(FTC_SBitCache_LookupScaler): Ditto.
* src/cache/ftccmap.c (FTC_CMapCache_Lookup): Ditto.
* src/cache/ftccache.h (FTC_CACHE_LOOKUP_CMP): Ditto.
Also the type of the internal variable `_idx' is changed to
FT_PtrDist from FT_UInt32 for better pointer calculation.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,46 @@
 2010-10-24  suzuki toshiya  <[email protected]>
 
+	[cache] Change the hash types to FT_PtrDist.
+
+	On LLP64 platforms (e.g. Win64), FT_ULong (32-bit)
+	variables are inappropriate to calculate hash values
+	from the memory address (64-bit).  The hash variables  
+	are extended from FT_ULong to FT_PtrDist and new
+	hashing macro functions are introduced.  The hash
+	values on 16-bit memory platforms are changed, but
+	ILP32 and LP64 are not changed.  The hash value in
+	the cache subsystem is not reverted to the memory
+	address, so using signed type FT_PtrDist is safe.
+
+	* src/cache/ftccache.h (_FTC_FACE_ID_HASH): New hash
+	function to replace FTC_FACE_ID_HASH() for portability.
+	* src/cache/ftcmanag.h (FTC_SCALER_HASH): Replace 
+	FTC_FACE_ID_HASH() by _FTC_FACE_ID_HASH().
+	* src/cache/ftccmap.c (FTC_CMAP_HASH): Ditto.
+
+	* src/cache/ftccache.h (FTC_NodeRec): The type of the
+	member `hash' is changed from FT_UInt32 to FT_PtrDist.
+
+	* src/cache/ftccache.h (FTC_Cache_Lookup): The type of the
+	argument `hash' is changed from FT_UInt32 to FT_PtrDist.
+	(FTC_Cache_NewNode): Ditto.
+	* src/cache/ftccache.c (ftc_cache_add): Ditto.
+	(FTC_Cache_Lookup): Ditto.  (FTC_Cache_NewNode): Ditto.
+	* src/cache/ftcglyph.h (FTC_GCache_Lookup): Ditto.
+	* src/cache/ftcglyph.c (FTC_GCache_Lookup): Ditto.
+
+	* src/cache/ftcbasic.c (FTC_ImageCache_Lookup): The type
+	of the internal variable `hash' is changed to FT_PtrDist
+	from FT_UInt32.  (FTC_ImageCache_LookupScaler): Ditto.
+	(FTC_SBitCache_Lookup): Ditto.
+	(FTC_SBitCache_LookupScaler): Ditto.
+	* src/cache/ftccmap.c (FTC_CMapCache_Lookup): Ditto.
+	* src/cache/ftccache.h (FTC_CACHE_LOOKUP_CMP): Ditto.
+	Also the type of the internal variable `_idx' is changed to
+	FT_PtrDist from FT_UInt32 for better pointer calculation.
+	
+2010-10-24  suzuki toshiya  <[email protected]>
+
 	[cache] Hide internal macros incompatible with LLP64.
 
 	FT_POINTER_TO_ULONG(), FTC_FACE_ID_HASH() and
--- a/src/cache/ftcbasic.c
+++ b/src/cache/ftcbasic.c
@@ -318,7 +318,7 @@
     FTC_BasicQueryRec  query;
     FTC_Node           node = 0; /* make compiler happy */
     FT_Error           error;
-    FT_UInt32          hash;
+    FT_PtrDist         hash;
 
 
     /* some argument checks are delayed to FTC_Cache_Lookup */
@@ -414,7 +414,7 @@
     FTC_BasicQueryRec  query;
     FTC_Node           node = 0; /* make compiler happy */
     FT_Error           error;
-    FT_UInt32          hash;
+    FT_PtrDist         hash;
 
 
     /* some argument checks are delayed to FTC_Cache_Lookup */
@@ -656,7 +656,7 @@
     FT_Error           error;
     FTC_BasicQueryRec  query;
     FTC_Node           node = 0; /* make compiler happy */
-    FT_UInt32          hash;
+    FT_PtrDist         hash;
 
 
     if ( anode )
@@ -753,7 +753,7 @@
     FT_Error           error;
     FTC_BasicQueryRec  query;
     FTC_Node           node = 0; /* make compiler happy */
-    FT_UInt32          hash;
+    FT_PtrDist         hash;
 
 
     if ( anode )
--- a/src/cache/ftccache.c
+++ b/src/cache/ftccache.c
@@ -410,7 +410,7 @@
 
   static void
   ftc_cache_add( FTC_Cache  cache,
-                 FT_UInt32  hash,
+                 FT_PtrDist hash,
                  FTC_Node   node )
   {
     node->hash = hash;
@@ -438,7 +438,7 @@
 
   FT_LOCAL_DEF( FT_Error )
   FTC_Cache_NewNode( FTC_Cache   cache,
-                     FT_UInt32   hash,
+                     FT_PtrDist  hash,
                      FT_Pointer  query,
                      FTC_Node   *anode )
   {
@@ -477,7 +477,7 @@
 
   FT_LOCAL_DEF( FT_Error )
   FTC_Cache_Lookup( FTC_Cache   cache,
-                    FT_UInt32   hash,
+                    FT_PtrDist  hash,
                     FT_Pointer  query,
                     FTC_Node   *anode )
   {
--- a/src/cache/ftccache.h
+++ b/src/cache/ftccache.h
@@ -24,6 +24,9 @@
 
 FT_BEGIN_HEADER
 
+#define _FTC_FACE_ID_HASH( i )                              \
+          ((FT_PtrDist)(( (FT_PtrDist)(i) >> 3 ) ^ ( (FT_PtrDist)(i) << 7 )))
+
   /* handle to cache object */
   typedef struct FTC_CacheRec_*  FTC_Cache;
 
@@ -56,7 +59,7 @@
   {
     FTC_MruNodeRec  mru;          /* circular mru list pointer           */
     FTC_Node        link;         /* used for hashing                    */
-    FT_UInt32       hash;         /* used for hashing too                */
+    FT_PtrDist      hash;         /* used for hashing too                */
     FT_UShort       cache_index;  /* index of cache the node belongs to  */
     FT_Short        ref_count;    /* reference count for this node       */
 
@@ -168,7 +171,7 @@
 #ifndef FTC_INLINE
   FT_LOCAL( FT_Error )
   FTC_Cache_Lookup( FTC_Cache   cache,
-                    FT_UInt32   hash,
+                    FT_PtrDist  hash,
                     FT_Pointer  query,
                     FTC_Node   *anode );
 #endif
@@ -175,7 +178,7 @@
 
   FT_LOCAL( FT_Error )
   FTC_Cache_NewNode( FTC_Cache   cache,
-                     FT_UInt32   hash,
+                     FT_PtrDist  hash,
                      FT_Pointer  query,
                      FTC_Node   *anode );
 
@@ -200,9 +203,9 @@
   FT_BEGIN_STMNT                                                         \
     FTC_Node             *_bucket, *_pnode, _node;                       \
     FTC_Cache             _cache   = FTC_CACHE(cache);                   \
-    FT_UInt32             _hash    = (FT_UInt32)(hash);                  \
+    FT_PtrDist            _hash    = (FT_PtrDist)(hash);                 \
     FTC_Node_CompareFunc  _nodcomp = (FTC_Node_CompareFunc)(nodecmp);    \
-    FT_UFast              _idx;                                          \
+    FT_PtrDist            _idx;                                          \
                                                                          \
                                                                          \
     error = FTC_Err_Ok;                                                  \
--- a/src/cache/ftccmap.c
+++ b/src/cache/ftccmap.c
@@ -87,7 +87,7 @@
 
   /* compute a query/node hash */
 #define FTC_CMAP_HASH( faceid, index, charcode )         \
-          ( FTC_FACE_ID_HASH( faceid ) + 211 * (index) + \
+          ( _FTC_FACE_ID_HASH( faceid ) + 211 * (index) + \
             ( (charcode) / FTC_CMAP_INDICES_MAX )      )
 
   /* the charmap query */
@@ -287,7 +287,7 @@
     FTC_Node          node;
     FT_Error          error;
     FT_UInt           gindex = 0;
-    FT_UInt32         hash;
+    FT_PtrDist        hash;
     FT_Int            no_cmap_change = 0;
 
 
--- a/src/cache/ftcglyph.c
+++ b/src/cache/ftcglyph.c
@@ -175,7 +175,7 @@
 
   FT_LOCAL_DEF( FT_Error )
   FTC_GCache_Lookup( FTC_GCache   cache,
-                     FT_UInt32    hash,
+                     FT_PtrDist   hash,
                      FT_UInt      gindex,
                      FTC_GQuery   query,
                      FTC_Node    *anode )
--- a/src/cache/ftcglyph.h
+++ b/src/cache/ftcglyph.h
@@ -254,7 +254,7 @@
 #ifndef FTC_INLINE
   FT_LOCAL( FT_Error )
   FTC_GCache_Lookup( FTC_GCache   cache,
-                     FT_UInt32    hash,
+                     FT_PtrDist   hash,
                      FT_UInt      gindex,
                      FTC_GQuery   query,
                      FTC_Node    *anode );
--- a/src/cache/ftcmanag.h
+++ b/src/cache/ftcmanag.h
@@ -161,7 +161,7 @@
           (a)->y_res == (b)->y_res ) ) )
 
 #define FTC_SCALER_HASH( q )                                 \
-    ( FTC_FACE_ID_HASH( (q)->face_id ) +                     \
+    ( _FTC_FACE_ID_HASH( (q)->face_id ) +                     \
       (q)->width + (q)->height*7 +                           \
       ( (q)->pixel ? 0 : ( (q)->x_res*33 ^ (q)->y_res*61 ) ) )