From: Sven Verdoolaege Date: Fri, 8 Jul 2011 13:41:38 +0000 (+0200) Subject: isl_reordering_extend_dim: don't mess with copies of input X-Git-Tag: isl-0.07~29^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d3c83bac004f2f199c07bd46f268a498e1ec9879;p=platform%2Fupstream%2Fisl.git isl_reordering_extend_dim: don't mess with copies of input In particular, perform an isl_reordering_cow before changing anythin. Signed-off-by: Sven Verdoolaege --- diff --git a/isl_reordering.c b/isl_reordering.c index 6a5b014..f19bcd6 100644 --- a/isl_reordering.c +++ b/isl_reordering.c @@ -37,16 +37,49 @@ __isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp) return exp; } -void isl_reordering_free(__isl_take isl_reordering *exp) +__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r) +{ + int i; + isl_reordering *dup; + + if (!r) + return NULL; + + dup = isl_reordering_alloc(r->dim->ctx, r->len); + if (!dup) + return NULL; + + dup->dim = isl_dim_copy(r->dim); + if (!dup->dim) + return isl_reordering_free(dup); + for (i = 0; i < dup->len; ++i) + dup->pos[i] = r->pos[i]; + + return dup; +} + +__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r) +{ + if (!r) + return NULL; + + if (r->ref == 1) + return r; + r->ref--; + return isl_reordering_dup(r); +} + +void *isl_reordering_free(__isl_take isl_reordering *exp) { if (!exp) - return; + return NULL; if (--exp->ref > 0) - return; + return NULL; isl_dim_free(exp->dim); free(exp); + return NULL; } /* Construct a reordering that maps the parameters of "alignee" @@ -141,6 +174,7 @@ __isl_give isl_reordering *isl_reordering_extend_dim( res = isl_reordering_extend(isl_reordering_copy(exp), isl_dim_total(dim) - exp->len); + res = isl_reordering_cow(res); if (!res) goto error; isl_dim_free(res->dim); diff --git a/isl_reordering.h b/isl_reordering.h index cfec95a..7560d3a 100644 --- a/isl_reordering.h +++ b/isl_reordering.h @@ -22,7 +22,7 @@ typedef struct isl_reordering isl_reordering; __isl_give isl_reordering *isl_parameter_alignment_reordering( __isl_keep isl_dim *alignee, __isl_keep isl_dim *aligner); __isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp); -void isl_reordering_free(__isl_take isl_reordering *exp); +void *isl_reordering_free(__isl_take isl_reordering *exp); __isl_give isl_reordering *isl_reordering_extend_dim( __isl_take isl_reordering *exp, __isl_take isl_dim *dim); __isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,