isl_id_alloc: allow isl_ids with the same name but different user value
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 31 Oct 2011 16:53:12 +0000 (17:53 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 31 Oct 2011 19:31:09 +0000 (20:31 +0100)
Although isl_ids were documented as being identified by the pair
of name and pointer value, this was not implemented as such.
Instead, only the name was taken into account.

This commit fixes isl_id_alloc to also take into account the user value.
We also avoid dereferencing possible NULL names.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_id.c

index ef03330..a3a2ea9 100644 (file)
--- a/isl_id.c
+++ b/isl_id.c
@@ -66,18 +66,29 @@ error:
        return NULL;
 }
 
-static int isl_id_has_name(const void *entry, const void *val)
+struct isl_name_and_user {
+       const char *name;
+       void *user;
+};
+
+static int isl_id_has_name_and_user(const void *entry, const void *val)
 {
        isl_id *id = (isl_id *)entry;
-       const char *s = (const char *)val;
+       struct isl_name_and_user *nu = (struct isl_name_and_user *) val;
+
+       if (id->user != nu->user)
+               return 0;
+       if (!id->name && !nu->name)
+               return 1;
 
-       return !strcmp(id->name, s);
+       return !strcmp(id->name, nu->name);
 }
 
 __isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
 {
        struct isl_hash_table_entry *entry;
        uint32_t id_hash;
+       struct isl_name_and_user nu = { name, user };
 
        id_hash = isl_hash_init();
        if (name)
@@ -85,7 +96,7 @@ __isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
        else
                id_hash = isl_hash_builtin(id_hash, user);
        entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash,
-                                       isl_id_has_name, name, 1);
+                                       isl_id_has_name_and_user, &nu, 1);
        if (!entry)
                return NULL;
        if (entry->data)