[BDF] Modify hash API to take size_t value instead of void *.

This commit is contained in:
suzuki toshiya 2009-09-13 00:50:14 +09:00
parent 519a5eafd7
commit 704f4d75cd
3 changed files with 54 additions and 21 deletions

View File

@ -1,3 +1,34 @@
2009-09-11 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
[BDF] Modify hash API to take size_t value instead of void *.
The hash API in BDF driver is designed to be generic, it takes
void * typed data. But BDF driver always gives an unsigned long
integer (the index to a property). To reduce non-essential
casts from unsigned long to void* and from void* to unsigned
long, the hash API is changed to take size_t integer.
The issue of incompatible cast between unsigned long and void*
on LLP64 platform is reported by NightStrike from MinGW-Win64
project. See
http://lists.gnu.org/archive/html/freetype/2009-09/msg00000.html
* src/bdf/bdf.h: The type of hashnode->data is changed from
void* to size_t.
* src/bdf/bdflib.c (hash_insert): Get size_t data, instead of
void* data.
(bdf_create_property): Get the name length of new property by
size_t variable, with a cut-off at FT_ULONG_MAX.
(_bdf_set_default_spacing): Get the name length of the face by
size_t variable, with a cut-off at 256.
(bdf_get_property): Get the property id by size_t variable to
reduce the casts between 32-bit prop ID & hashnode->data during
simple copying.
(_bdf_add_property): Ditto.
(_bdf_parse_start): Calculate the index to the property array
by size_t variable.
(bdf_get_font_property): Drop a cast to unsigned long.
2009-09-10 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp> 2009-09-10 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
[Win64] Improve the computation of random seed from stack address. [Win64] Improve the computation of random seed from stack address.

View File

@ -160,7 +160,7 @@ FT_BEGIN_HEADER
typedef struct _hashnode_ typedef struct _hashnode_
{ {
const char* key; const char* key;
void* data; size_t data;
} _hashnode, *hashnode; } _hashnode, *hashnode;

View File

@ -281,7 +281,7 @@
static FT_Error static FT_Error
hash_insert( char* key, hash_insert( char* key,
void* data, size_t data,
hashtable* ht, hashtable* ht,
FT_Memory memory ) FT_Memory memory )
{ {
@ -971,7 +971,7 @@
int format, int format,
bdf_font_t* font ) bdf_font_t* font )
{ {
unsigned long n; size_t n;
bdf_property_t* p; bdf_property_t* p;
FT_Memory memory = font->memory; FT_Memory memory = font->memory;
FT_Error error = BDF_Err_Ok; FT_Error error = BDF_Err_Ok;
@ -991,7 +991,9 @@
p = font->user_props + font->nuser_props; p = font->user_props + font->nuser_props;
FT_ZERO( p ); 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 ) ) if ( FT_NEW_ARRAY( p->name, n ) )
goto Exit; goto Exit;
@ -1003,7 +1005,7 @@
n = _num_bdf_properties + font->nuser_props; 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 ) if ( error )
goto Exit; goto Exit;
@ -1019,7 +1021,7 @@
bdf_font_t* font ) bdf_font_t* font )
{ {
hashnode hn; hashnode hn;
unsigned long propid; size_t propid;
if ( name == 0 || *name == 0 ) if ( name == 0 || *name == 0 )
@ -1028,7 +1030,7 @@
if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 ) if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 )
return 0; return 0;
propid = (unsigned long)hn->data; propid = hn->data;
if ( propid >= _num_bdf_properties ) if ( propid >= _num_bdf_properties )
return font->user_props + ( propid - _num_bdf_properties ); return font->user_props + ( propid - _num_bdf_properties );
@ -1131,7 +1133,7 @@
_bdf_set_default_spacing( bdf_font_t* font, _bdf_set_default_spacing( bdf_font_t* font,
bdf_options_t* opts ) bdf_options_t* opts )
{ {
unsigned long len; size_t len;
char name[256]; char name[256];
_bdf_list_t list; _bdf_list_t list;
FT_Memory memory; FT_Memory memory;
@ -1150,7 +1152,7 @@
font->spacing = opts->font_spacing; 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. */ /* Limit ourselves to 256 characters in the font name. */
if ( len >= 256 ) if ( len >= 256 )
{ {
@ -1261,7 +1263,7 @@
char* name, char* name,
char* value ) char* value )
{ {
unsigned long propid; size_t propid;
hashnode hn; hashnode hn;
bdf_property_t *prop, *fp; bdf_property_t *prop, *fp;
FT_Memory memory = font->memory; FT_Memory memory = font->memory;
@ -1273,7 +1275,7 @@
{ {
/* The property already exists in the font, so simply replace */ /* The property already exists in the font, so simply replace */
/* the value of the property with the current value. */ /* the value of the property with the current value. */
fp = font->props + (unsigned long)hn->data; fp = font->props + hn->data;
switch ( fp->format ) switch ( fp->format )
{ {
@ -1335,7 +1337,7 @@
font->props_size++; font->props_size++;
} }
propid = (unsigned long)hn->data; propid = hn->data;
if ( propid >= _num_bdf_properties ) if ( propid >= _num_bdf_properties )
prop = font->user_props + ( propid - _num_bdf_properties ); prop = font->user_props + ( propid - _num_bdf_properties );
else else
@ -1372,7 +1374,7 @@
if ( ft_memcmp( name, "COMMENT", 7 ) != 0 ) { if ( ft_memcmp( name, "COMMENT", 7 ) != 0 ) {
/* Add the property to the font property table. */ /* Add the property to the font property table. */
error = hash_insert( fp->name, error = hash_insert( fp->name,
(void *)font->props_used, font->props_used,
(hashtable *)font->internal, (hashtable *)font->internal,
memory ); memory );
if ( error ) if ( error )
@ -2044,7 +2046,7 @@
p->memory = 0; p->memory = 0;
{ /* setup */ { /* setup */
unsigned long i; size_t i;
bdf_property_t* prop; bdf_property_t* prop;
@ -2054,7 +2056,7 @@
for ( i = 0, prop = (bdf_property_t*)_bdf_properties; for ( i = 0, prop = (bdf_property_t*)_bdf_properties;
i < _num_bdf_properties; i++, prop++ ) i < _num_bdf_properties; i++, prop++ )
{ {
error = hash_insert( prop->name, (void *)i, error = hash_insert( prop->name, i,
&(font->proptbl), memory ); &(font->proptbl), memory );
if ( error ) if ( error )
goto Exit; goto Exit;
@ -2472,7 +2474,7 @@
hn = hash_lookup( name, (hashtable *)font->internal ); hn = hash_lookup( name, (hashtable *)font->internal );
return hn ? ( font->props + (unsigned long)hn->data ) : 0; return hn ? ( font->props + hn->data ) : 0;
} }