allow isl_ids with negative reference counts
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 25 Aug 2011 19:18:34 +0000 (21:18 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 3 Sep 2011 19:43:08 +0000 (21:43 +0200)
This will be useful for static isl_ids that are not supposed to change.

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

index 0bb3677..8149e69 100644 (file)
--- a/isl_id.c
+++ b/isl_id.c
@@ -85,11 +85,17 @@ __isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
        return entry->data;
 }
 
+/* If the id has a negative refcount, then it is a static isl_id
+ * which should not be changed.
+ */
 __isl_give isl_id *isl_id_copy(isl_id *id)
 {
        if (!id)
                return NULL;
 
+       if (id->ref < 0)
+               return id;
+
        id->ref++;
        return id;
 }
@@ -107,6 +113,9 @@ uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id)
        return hash;
 }
 
+/* If the id has a negative refcount, then it is a static isl_id
+ * and should not be freed.
+ */
 void *isl_id_free(__isl_take isl_id *id)
 {
        struct isl_hash_table_entry *entry;
@@ -114,6 +123,9 @@ void *isl_id_free(__isl_take isl_id *id)
        if (!id)
                return NULL;
 
+       if (id->ref < 0)
+               return NULL;
+
        if (--id->ref > 0)
                return NULL;