gallium: Switch u_debug_stack/symbol.c to util/hash_table.h
[mesa.git] / src / gallium / auxiliary / util / u_debug_symbol.c
index 4ea6c8d07b02a732c3510e7e01550d68e9c9a7c6..73225e9e49544ed443c7696f1c5da2099f633207 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "util/u_debug.h"
 #include "u_debug_symbol.h"
-#include "u_hash_table.h"
+#include "util/hash_table.h"
 
 
 #if defined(PIPE_OS_WINDOWS)
@@ -234,7 +234,7 @@ debug_symbol_name_glibc(const void *addr, char* buf, unsigned size)
    if (!syms) {
       return FALSE;
    }
-   strncpy(buf, syms[0], size);
+   strncpy(buf, syms[0], size - 1);
    buf[size - 1] = 0;
    free(syms);
    return TRUE;
@@ -270,23 +270,12 @@ debug_symbol_print(const void *addr)
    debug_printf("\t%s\n", buf);
 }
 
-struct util_hash_table* symbols_hash;
+static struct hash_table* symbols_hash;
+#ifdef PIPE_OS_WINDOWS
+static mtx_t symbols_mutex;
+#else
 static mtx_t symbols_mutex = _MTX_INITIALIZER_NP;
-
-static unsigned hash_ptr(void* p)
-{
-   return (unsigned)(uintptr_t)p;
-}
-
-static int compare_ptr(void* a, void* b)
-{
-   if(a == b)
-      return 0;
-   else if(a < b)
-      return -1;
-   else
-      return 1;
-}
+#endif
 
 const char*
 debug_symbol_name_cached(const void *addr)
@@ -303,16 +292,15 @@ debug_symbol_name_cached(const void *addr)
 
    mtx_lock(&symbols_mutex);
    if(!symbols_hash)
-      symbols_hash = util_hash_table_create(hash_ptr, compare_ptr);
-   name = util_hash_table_get(symbols_hash, (void*)addr);
-   if(!name)
-   {
+      symbols_hash = _mesa_pointer_hash_table_create(NULL);
+   struct hash_entry *entry = _mesa_hash_table_search(symbols_hash, addr);
+   if (!entry) {
       char buf[1024];
       debug_symbol_name(addr, buf, sizeof(buf));
       name = strdup(buf);
 
-      util_hash_table_set(symbols_hash, (void*)addr, (void*)name);
+      entry = _mesa_hash_table_insert(symbols_hash, addr, (void*)name);
    }
    mtx_unlock(&symbols_mutex);
-   return name;
+   return entry->data;
 }