X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_id.c;h=410218df72d8c442f74fcc21fced90843b6106ff;hb=831d570fe1f68872766700bc969b7377d2f2b123;hp=81ed8a0379b7f07a38408d73952f9ad96255653c;hpb=64e0c9a630d2cec74cc60b23156cf63a3083de43;p=platform%2Fupstream%2Fisl.git diff --git a/isl_id.c b/isl_id.c index 81ed8a0..410218d 100644 --- a/isl_id.c +++ b/isl_id.c @@ -1,7 +1,7 @@ /* * Copyright 2008-2009 Katholieke Universiteit Leuven * - * Use of this software is governed by the GNU LGPLv2.1 license + * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, K.U.Leuven, Departement * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium @@ -11,6 +11,22 @@ #include #include +#undef BASE +#define BASE id + +#include + +/* A special, static isl_id to use as domains (and ranges) + * of sets and parameters domains. + * The user should never get a hold on this isl_id. + */ +isl_id isl_id_none = { + .ref = -1, + .ctx = NULL, + .name = "#none", + .user = NULL +}; + isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id) { return id ? id->ctx : NULL; @@ -33,7 +49,7 @@ static __isl_give isl_id *id_alloc(isl_ctx *ctx, const char *name, void *user) 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; @@ -55,18 +71,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) @@ -74,7 +101,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) @@ -85,11 +112,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 +140,22 @@ uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id) 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. + */ void *isl_id_free(__isl_take isl_id *id) { struct isl_hash_table_entry *entry; @@ -114,6 +163,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; @@ -125,6 +177,9 @@ void *isl_id_free(__isl_take isl_id *id) 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); @@ -150,17 +205,3 @@ error: isl_printer_free(p); return NULL; } - -void isl_id_dump(__isl_keep isl_id *id) -{ - isl_printer *printer; - - if (!id) - return; - - printer = isl_printer_to_file(isl_id_get_ctx(id), stderr); - printer = isl_printer_print_id(printer, id); - printer = isl_printer_end_line(printer); - - isl_printer_free(printer); -}