freetype
[Top][All Lists]
Advanced

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

Re: [ft] freetype2 and Win64


From: mpsuzuki
Subject: Re: [ft] freetype2 and Win64
Date: Sun, 13 Sep 2009 01:31:19 +0900

Hi,

On Thu, 10 Sep 2009 16:32:55 +0900
address@hidden wrote:
>On Mon, 7 Sep 2009 13:02:28 +0900
>address@hidden wrote:
>>There are 3 groups of the problem.
>>
>>A) bdflib.c
>
>>B) t1decode.c & cffgload.c
>
>>C) ftcbasic.c & ftccmap.c
>
>Just I've fixed B) in git. Soon A) will be fixed.

Just I've fixed A) in git, but by completely different way.

The BDF driver has a hash mechanism to access the properties
loaded from BDF to memory. The BDF hash mechanism is designed
to be generic, so it takes the key by char* and the value by
void* pointer. However, when I check how hash_insert() is used
in bdflib.c, the passed value is always unsigned long integer
(a property id, or an index to property array), no pointer
is passed.

Considering the utilization of BDF hash mechanism, I thought
"size_t" is better data type for default. Even if we are
required to write a pointer into BDF hash table, size_t has
sufficient bitwidth to convey the pointer. Also I note that
BDF driver in FT2 had a comment that BDF hash mechanism should
be replaced by FT2's own hash mechanism (to reduce codesize).

By this fix, there is a different support level of BDF
between LP64 and LLP64 systems: LP64 system can load 64-bit
size BDF (I've never tried), but LLP64 system cannot.
I think it's not critical issue, because ILP32 cannot load
such from the beginning.  And, the BDF greater than 2GB is
not so realistic, I guess.

Regards,
mpsuzuki


diff --git a/src/bdf/bdf.h b/src/bdf/bdf.h
index e3088a2..561b415 100644
--- a/src/bdf/bdf.h
+++ b/src/bdf/bdf.h
@@ -160,7 +160,7 @@ FT_BEGIN_HEADER
   typedef struct  _hashnode_
   {
     const char*  key;
-    void*        data;
+    size_t       data;
 
   } _hashnode, *hashnode;
 
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index c8afc01..5fa5868 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -281,7 +281,7 @@
 
   static FT_Error
   hash_insert( char*       key,
-               void*       data,
+               size_t      data,
                hashtable*  ht,
                FT_Memory   memory )
   {
@@ -971,7 +971,7 @@
                        int          format,
                        bdf_font_t*  font )
   {
-    unsigned long    n;
+    size_t           n;
     bdf_property_t*  p;
     FT_Memory        memory = font->memory;
     FT_Error         error = BDF_Err_Ok;
@@ -991,7 +991,9 @@
     p = font->user_props + font->nuser_props;
     FT_ZERO( p );
 
-    n = (unsigned long)( ft_strlen( name ) + 1 );
+    n = ft_strlen( name ) + 1;
+    if ( n > FT_ULONG_MAX )
+      return BDF_Err_Invalid_Argument;
 
     if ( FT_NEW_ARRAY( p->name, n ) )
       goto Exit;
@@ -1003,7 +1005,7 @@
 
     n = _num_bdf_properties + font->nuser_props;
 
-    error = hash_insert( p->name, (void *)n, &(font->proptbl), memory );
+    error = hash_insert( p->name, n, &(font->proptbl), memory );
     if ( error )
       goto Exit;
 
@@ -1018,8 +1020,8 @@
   bdf_get_property( char*        name,
                     bdf_font_t*  font )
   {
-    hashnode       hn;
-    unsigned long  propid;
+    hashnode  hn;
+    size_t    propid;
 
 
     if ( name == 0 || *name == 0 )
@@ -1028,7 +1030,7 @@
     if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 )
       return 0;
 
-    propid = (unsigned long)hn->data;
+    propid = hn->data;
     if ( propid >= _num_bdf_properties )
       return font->user_props + ( propid - _num_bdf_properties );
 
@@ -1131,11 +1133,11 @@
   _bdf_set_default_spacing( bdf_font_t*     font,
                             bdf_options_t*  opts )
   {
-    unsigned long  len;
-    char           name[256];
-    _bdf_list_t    list;
-    FT_Memory      memory;
-    FT_Error       error = BDF_Err_Ok;
+    size_t       len;
+    char         name[256];
+    _bdf_list_t  list;
+    FT_Memory    memory;
+    FT_Error     error = BDF_Err_Ok;
 
 
     if ( font == 0 || font->name == 0 || font->name[0] == 0 )
@@ -1150,7 +1152,7 @@
 
     font->spacing = opts->font_spacing;
 
-    len = (unsigned long)( ft_strlen( font->name ) + 1 );
+    len = ft_strlen( font->name ) + 1;
     /* Limit ourselves to 256 characters in the font name. */
     if ( len >= 256 )
     {
@@ -1261,7 +1263,7 @@
                      char*        name,
                      char*        value )
   {
-    unsigned long   propid;
+    size_t          propid;
     hashnode        hn;
     bdf_property_t  *prop, *fp;
     FT_Memory       memory = font->memory;
@@ -1273,7 +1275,7 @@
     {
       /* The property already exists in the font, so simply replace */
       /* the value of the property with the current value.          */
-      fp = font->props + (unsigned long)hn->data;
+      fp = font->props + hn->data;
 
       switch ( fp->format )
       {
@@ -1335,7 +1337,7 @@
       font->props_size++;
     }
 
-    propid = (unsigned long)hn->data;
+    propid = hn->data;
     if ( propid >= _num_bdf_properties )
       prop = font->user_props + ( propid - _num_bdf_properties );
     else
@@ -1372,7 +1374,7 @@
     if ( ft_memcmp( name, "COMMENT", 7 ) != 0 ) {
       /* Add the property to the font property table. */
       error = hash_insert( fp->name,
-                           (void *)font->props_used,
+                           font->props_used,
                            (hashtable *)font->internal,
                            memory );
       if ( error )
@@ -2044,7 +2046,7 @@
       p->memory    = 0;
 
       { /* setup */
-        unsigned long    i;
+        size_t           i;
         bdf_property_t*  prop;
 
 
@@ -2054,7 +2056,7 @@
         for ( i = 0, prop = (bdf_property_t*)_bdf_properties;
               i < _num_bdf_properties; i++, prop++ )
         {
-          error = hash_insert( prop->name, (void *)i,
+          error = hash_insert( prop->name, i,
                                &(font->proptbl), memory );
           if ( error )
             goto Exit;
@@ -2472,7 +2474,7 @@
 
     hn = hash_lookup( name, (hashtable *)font->internal );
 
-    return hn ? ( font->props + (unsigned long)hn->data ) : 0;
+    return hn ? ( font->props + hn->data ) : 0;
   }
 
 




reply via email to

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