#include <isl/id.h>
__isl_give isl_id *isl_id_alloc(isl_ctx *ctx,
__isl_keep const char *name, void *user);
+ __isl_give isl_id *isl_id_set_free_user(
+ __isl_take isl_id *id,
+ __isl_give void (*free_user)(void *user));
__isl_give isl_id *isl_id_copy(isl_id *id);
void *isl_id_free(__isl_take isl_id *id);
__isl_give isl_printer *isl_printer_print_id(
__isl_take isl_printer *p, __isl_keep isl_id *id);
+The callback set by C<isl_id_set_free_user> is called on the user
+pointer when the last reference to the C<isl_id> is freed.
Note that C<isl_id_get_name> returns a pointer to some internal
data structure, so the result can only be used while the
corresponding C<isl_id> is alive.
void *isl_id_get_user(__isl_keep isl_id *id);
__isl_keep const char *isl_id_get_name(__isl_keep isl_id *id);
+__isl_give isl_id *isl_id_set_free_user(__isl_take isl_id *id,
+ __isl_give void (*free_user)(void *user));
+
__isl_give isl_printer *isl_printer_print_id(__isl_take isl_printer *p,
__isl_keep isl_id *id);
void isl_id_dump(__isl_keep isl_id *id);
if (name && !copy)
return NULL;
- id = isl_alloc_type(ctx, struct isl_id);
+ id = isl_calloc_type(ctx, struct isl_id);
if (!id)
goto error;
return hash;
}
+/* Replace the free_user callback by "free_user".
+ */
+__isl_give isl_id *isl_id_set_free_user(__isl_take isl_id *id,
+ __isl_give void (*free_user)(void *user))
+{
+ if (!id)
+ return NULL;
+
+ id->free_user = free_user;
+
+ return id;
+}
+
/* If the id has a negative refcount, then it is a static isl_id
* and should not be freed.
*/
else
isl_hash_table_remove(id->ctx, &id->ctx->id_table, entry);
+ if (id->free_user)
+ id->free_user(id->user);
+
free((char *)id->name);
isl_ctx_deref(id->ctx);
free(id);
#include <isl/id.h>
+/* Represent a name and/or user pointer.
+ *
+ * If "free_user" is set, then it will be called on "user" when
+ * the last instance of the isl_id is freed.
+ */
struct isl_id {
int ref;
isl_ctx *ctx;
const char *name;
void *user;
uint32_t hash;
+
+ __isl_give void (*free_user)(void *user);
};
uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id);