summaryrefslogtreecommitdiff
path: root/glsl_types.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-03-31 16:13:38 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-03-31 16:13:38 -0700
commit299ed08a68d4f603bb72b7635bfa5c6f95776b22 (patch)
tree4ba3525235b39206770bfb25dd975fb6a473d249 /glsl_types.cpp
parent0bf381016524ac58f5961877ea0e8651c4922ca3 (diff)
Fix big dumbness in glsl_type::get_array_instance
hash_table_insert needs to keep the key so that it compare keys on a following hash_table_find call. Since key was allocated on the stack, it disappeared out from under the hash table.
Diffstat (limited to 'glsl_types.cpp')
-rw-r--r--glsl_types.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/glsl_types.cpp b/glsl_types.cpp
index eb9ab820b1..7b8b3e9014 100644
--- a/glsl_types.cpp
+++ b/glsl_types.cpp
@@ -576,29 +576,40 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
int
glsl_type::array_key_compare(const void *a, const void *b)
{
- const array_hash_key *const key1 = (array_hash_key *) a;
- const array_hash_key *const key2 = (array_hash_key *) b;
+ const glsl_type *const key1 = (glsl_type *) a;
+ const glsl_type *const key2 = (glsl_type *) b;
- return ((key1->type == key2->type) && (key1->size == key2->size)) ? 0 : 1;
+ /* Return zero is the types match (there is zero difference) or non-zero
+ * otherwise.
+ */
+ return ((key1->fields.array == key2->fields.array)
+ && (key1->length == key2->length)) ? 0 : 1;
}
unsigned
glsl_type::array_key_hash(const void *a)
{
- char buf[sizeof(array_hash_key) + 1];
-
- memcpy(buf, a, sizeof(array_hash_key));
- buf[sizeof(array_hash_key)] = '\0';
+ const glsl_type *const key = (glsl_type *) a;
+
+ const struct {
+ const glsl_type *t;
+ unsigned l;
+ char nul;
+ } hash_key = {
+ key->fields.array,
+ key->length,
+ '\0'
+ };
- return hash_table_string_hash(buf);
+ return hash_table_string_hash(& hash_key);
}
const glsl_type *
glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
{
- array_hash_key key = { base, array_size };
+ const glsl_type key(base, array_size);
if (array_types == NULL) {
array_types = hash_table_ctor(64, array_key_hash, array_key_compare);
@@ -608,7 +619,7 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
if (t == NULL) {
t = new glsl_type(base, array_size);
- hash_table_insert(array_types, (void *) t, & key);
+ hash_table_insert(array_types, (void *) t, t);
}
assert(t->base_type == GLSL_TYPE_ARRAY);