freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master 76e79ec 4/6: [base, bdf] Don't expose `FT_Hashnode' i


From: Werner LEMBERG
Subject: [freetype2] master 76e79ec 4/6: [base, bdf] Don't expose `FT_Hashnode' in hash functions.
Date: Sun, 20 Dec 2015 18:36:52 +0000

branch: master
commit 76e79ec9a59bce0c5f6adc0684bb9e657843d51a
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    [base, bdf] Don't expose `FT_Hashnode' in hash functions.
    
    * src/base/fthash.c (hash_lookup, ft_hash_str_lookup,
    ft_hash_num_lookup): Return pointer to `size_t' instead of
    `FT_Hashnode'.
    
    * include/freetype/internal/fthash.h: Updated.
    
    * src/bdf/bdflib.c (bdf_get_property, _bdf_add_property,
    bdf_get_font_property): Updated.
---
 ChangeLog                          |   13 +++++++++++
 include/freetype/internal/fthash.h |    4 +-
 src/base/fthash.c                  |    9 ++++---
 src/bdf/bdflib.c                   |   41 ++++++++++++++++-------------------
 4 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 251da08..fc484fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2015-12-20  Werner Lemberg  <address@hidden>
 
+       [base, bdf] Don't expose `FT_Hashnode' in hash functions.
+
+       * src/base/fthash.c (hash_lookup, ft_hash_str_lookup,
+       ft_hash_num_lookup): Return pointer to `size_t' instead of
+       `FT_Hashnode'.
+
+       * include/freetype/internal/fthash.h: Updated.
+
+       * src/bdf/bdflib.c (bdf_get_property, _bdf_add_property,
+       bdf_get_font_property): Updated.
+
+2015-12-20  Werner Lemberg  <address@hidden>
+
        [base, bdf] Add number hashing.
 
        * src/base/fthash.c (hash_num_lookup, hash_num_compare): New
diff --git a/include/freetype/internal/fthash.h 
b/include/freetype/internal/fthash.h
index 84563cb..7867e12 100644
--- a/include/freetype/internal/fthash.h
+++ b/include/freetype/internal/fthash.h
@@ -118,11 +118,11 @@ FT_BEGIN_HEADER
                       FT_Hash    hash,
                       FT_Memory  memory );
 
-  FT_Hashnode
+  size_t*
   ft_hash_str_lookup( const char*  key,
                       FT_Hash      hash );
 
-  FT_Hashnode
+  size_t*
   ft_hash_num_lookup( FT_Int   num,
                       FT_Hash  hash );
 
diff --git a/src/base/fthash.c b/src/base/fthash.c
index 942e650..854741a 100644
--- a/src/base/fthash.c
+++ b/src/base/fthash.c
@@ -291,18 +291,19 @@
   }
 
 
-  static FT_Hashnode
+  static size_t*
   hash_lookup( FT_Hashkey  key,
                FT_Hash     hash )
   {
     FT_Hashnode*  np = hash_bucket( key, hash );
 
 
-    return *np;
+    return (*np) ? &(*np)->data
+                 : NULL;
   }
 
 
-  FT_Hashnode
+  size_t*
   ft_hash_str_lookup( const char*  key,
                       FT_Hash      hash )
   {
@@ -315,7 +316,7 @@
   }
 
 
-  FT_Hashnode
+  size_t*
   ft_hash_num_lookup( FT_Int   num,
                       FT_Hash  hash )
   {
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index 6944467..cef52c4 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -848,25 +848,23 @@
   }
 
 
-  FT_LOCAL_DEF( bdf_property_t * )
+  FT_LOCAL_DEF( bdf_property_t* )
   bdf_get_property( char*        name,
                     bdf_font_t*  font )
   {
-    FT_Hashnode  hn;
-    size_t       propid;
+    size_t*  propid;
 
 
     if ( name == 0 || *name == 0 )
       return 0;
 
-    if ( ( hn = ft_hash_str_lookup( name, &(font->proptbl) ) ) == 0 )
+    if ( ( propid = ft_hash_str_lookup( name, &(font->proptbl) ) ) == NULL )
       return 0;
 
-    propid = hn->data;
-    if ( propid >= _num_bdf_properties )
-      return font->user_props + ( propid - _num_bdf_properties );
+    if ( *propid >= _num_bdf_properties )
+      return font->user_props + ( *propid - _num_bdf_properties );
 
-    return (bdf_property_t*)_bdf_properties + propid;
+    return (bdf_property_t*)_bdf_properties + *propid;
   }
 
 
@@ -1074,8 +1072,7 @@
                      char*          value,
                      unsigned long  lineno )
   {
-    size_t          propid;
-    FT_Hashnode     hn;
+    size_t*         propid;
     bdf_property_t  *prop, *fp;
     FT_Memory       memory = font->memory;
     FT_Error        error  = FT_Err_Ok;
@@ -1084,11 +1081,12 @@
 
 
     /* First, check whether the property already exists in the font. */
-    if ( ( hn = ft_hash_str_lookup( name, (FT_Hash)font->internal ) ) != 0 )
+    if ( ( propid = ft_hash_str_lookup( name,
+                                        (FT_Hash)font->internal ) ) != NULL )
     {
       /* The property already exists in the font, so simply replace */
       /* the value of the property with the current value.          */
-      fp = font->props + hn->data;
+      fp = font->props + *propid;
 
       switch ( fp->format )
       {
@@ -1120,13 +1118,13 @@
 
     /* See whether this property type exists yet or not. */
     /* If not, create it.                                */
-    hn = ft_hash_str_lookup( name, &(font->proptbl) );
-    if ( hn == 0 )
+    propid = ft_hash_str_lookup( name, &(font->proptbl) );
+    if ( propid == NULL )
     {
       error = bdf_create_property( name, BDF_ATOM, font );
       if ( error )
         goto Exit;
-      hn = ft_hash_str_lookup( name, &(font->proptbl) );
+      propid = ft_hash_str_lookup( name, &(font->proptbl) );
     }
 
     /* Allocate another property if this is overflow. */
@@ -1150,11 +1148,10 @@
       font->props_size++;
     }
 
-    propid = hn->data;
-    if ( propid >= _num_bdf_properties )
-      prop = font->user_props + ( propid - _num_bdf_properties );
+    if ( *propid >= _num_bdf_properties )
+      prop = font->user_props + ( *propid - _num_bdf_properties );
     else
-      prop = (bdf_property_t*)_bdf_properties + propid;
+      prop = (bdf_property_t*)_bdf_properties + *propid;
 
     fp = font->props + font->props_used;
 
@@ -2408,15 +2405,15 @@
   bdf_get_font_property( bdf_font_t*  font,
                          const char*  name )
   {
-    FT_Hashnode  hn;
+    size_t*  propid;
 
 
     if ( font == 0 || font->props_size == 0 || name == 0 || *name == 0 )
       return 0;
 
-    hn = ft_hash_str_lookup( name, (FT_Hash)font->internal );
+    propid = ft_hash_str_lookup( name, (FT_Hash)font->internal );
 
-    return hn ? ( font->props + hn->data ) : 0;
+    return propid ? ( font->props + *propid ) : 0;
   }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]