[pango] pangowin32: fix script cache hash key for 64bit builds
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] pangowin32: fix script cache hash key for 64bit builds
- Date: Mon, 9 Apr 2018 13:47:59 +0000 (UTC)
commit 5d46e21df66a11233186ddf27ca8c70149307871
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Apr 7 06:44:53 2018 +0200
pangowin32: fix script cache hash key for 64bit builds
It joins the HFONT and script key to a gint64 and uses this as a
hash key, but HFONT is a pointer type and on 64bit Windows it
doesn't fit in 32bit and the value gets truncated.
This breaks the build with meson where -Werror=pointer-to-int-cast
is enabled by default.
Instead of using the gint64 hash functions add our own key type and implement
matching hash and equality functions for it.
https://bugzilla.gnome.org/show_bug.cgi?id=795045
pango/pangowin32-shape.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
---
diff --git a/pango/pangowin32-shape.c b/pango/pangowin32-shape.c
index 001fc43..aad0243 100644
--- a/pango/pangowin32-shape.c
+++ b/pango/pangowin32-shape.c
@@ -370,6 +370,24 @@ convert_log_clusters_to_byte_offsets (const char *text,
g_free (byte_offset);
}
+typedef struct {
+ HFONT hfont;
+ gint32 script;
+} script_cache_key;
+
+static guint
+script_cache_key_hash_func (script_cache_key *key)
+{
+ return g_direct_hash (key->hfont) ^ g_int_hash (&(key->script));
+}
+
+static gboolean
+script_cache_key_equal_func (script_cache_key *a,
+ script_cache_key *b)
+{
+ return (a->hfont == b->hfont) && (a->script == b->script);
+}
+
static gboolean
itemize_shape_and_place (PangoFont *font,
HDC hdc,
@@ -389,7 +407,8 @@ itemize_shape_and_place (PangoFont *font,
static GHashTable *script_cache_hash = NULL;
if (!script_cache_hash)
- script_cache_hash = g_hash_table_new (g_int64_hash, g_int64_equal);
+ script_cache_hash = g_hash_table_new ((GHashFunc)script_cache_key_hash_func,
+ (GEqualFunc)script_cache_key_equal_func);
memset (&control, 0, sizeof (control));
memset (&state, 0, sizeof (state));
@@ -440,7 +459,7 @@ itemize_shape_and_place (PangoFont *font,
int ng;
int char_offset;
SCRIPT_CACHE *script_cache;
- gint64 font_and_script_key;
+ script_cache_key font_and_script_key;
memset (advances, 0, sizeof (advances));
memset (offsets, 0, sizeof (offsets));
@@ -472,16 +491,17 @@ itemize_shape_and_place (PangoFont *font,
items[item].iCharPos, items[item+1].iCharPos-1, itemlen);
#endif
/* Create a hash key based on hfont and script engine */
- font_and_script_key = (((gint64) ((gint32) hfont)) << 32) | script;
+ font_and_script_key.hfont = hfont;
+ font_and_script_key.script = script;
/* Get the script cache for this hfont and script */
script_cache = g_hash_table_lookup (script_cache_hash, &font_and_script_key);
if (!script_cache)
{
- gint64 *key_n;
+ script_cache_key *key_n;
SCRIPT_CACHE *new_script_cache;
- key_n = g_new (gint64, 1);
+ key_n = g_new (script_cache_key, 1);
*key_n = font_and_script_key;
new_script_cache = g_new0 (SCRIPT_CACHE, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]