Sfoglia il codice sorgente

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.
tags/mesa-7.9-rc1
Ian Romanick 15 anni fa
parent
commit
299ed08a68
2 ha cambiato i file con 21 aggiunte e 16 eliminazioni
  1. 21
    10
      glsl_types.cpp
  2. 0
    6
      glsl_types.h

+ 21
- 10
glsl_types.cpp Vedi File

@@ -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);

+ 0
- 6
glsl_types.h Vedi File

@@ -330,12 +330,6 @@ private:
/** Hash table containing the known array types. */
static struct hash_table *array_types;

/** Structure defining the key type used for array_types hash table. */
struct array_hash_key {
const glsl_type *type;
unsigned size;
};

static int array_key_compare(const void *a, const void *b);
static unsigned array_key_hash(const void *key);
};

Loading…
Annulla
Salva