isl_tab_add_eq: return int instead of isl_tab *
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 25 Jun 2010 16:56:12 +0000 (18:56 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 26 Jun 2010 15:37:39 +0000 (17:37 +0200)
basis_reduction_tab.c
isl_affine_hull.c
isl_coalesce.c
isl_tab.c
isl_tab.h
isl_tab_pip.c
isl_vertices.c

index 4ac27e2..11c43ad 100644 (file)
@@ -179,11 +179,13 @@ static int cut_lp_to_hyperplane(struct tab_lp *lp, isl_int *row)
                return -1;
 
        isl_int_neg(lp->row->el[0], lp->tmp);
-       lp->tab = isl_tab_add_eq(lp->tab, lp->row->el);
+       if (isl_tab_add_eq(lp->tab, lp->row->el) < 0)
+               return -1;
 
        isl_seq_cpy(lp->row->el + 1 + lp->dim, row, lp->dim);
        isl_seq_clr(lp->row->el + 1, lp->dim);
-       lp->tab = isl_tab_add_eq(lp->tab, lp->row->el);
+       if (isl_tab_add_eq(lp->tab, lp->row->el) < 0)
+               return -1;
 
        lp->con_offset += 2;
 
index c92b952..13c818a 100644 (file)
@@ -388,8 +388,7 @@ static struct isl_basic_set *extend_affine_hull(struct isl_tab *tab,
                                break;
                        isl_vec_free(sample);
 
-                       tab = isl_tab_add_eq(tab, hull->eq[j]);
-                       if (!tab)
+                       if (isl_tab_add_eq(tab, hull->eq[j]) < 0)
                                goto error;
                }
                if (j == hull->n_eq)
@@ -630,7 +629,8 @@ struct isl_tab *isl_tab_detect_equalities(struct isl_tab *tab,
        if (hull->n_eq > tab->n_zero) {
                for (j = 0; j < hull->n_eq; ++j) {
                        isl_seq_normalize(tab->mat->ctx, hull->eq[j], 1 + tab->n_var);
-                       tab = isl_tab_add_eq(tab, hull->eq[j]);
+                       if (isl_tab_add_eq(tab, hull->eq[j]) < 0)
+                               goto error;
                }
        }
 
index 8f953df..84a5a4b 100644 (file)
@@ -722,7 +722,8 @@ static int wrap_in_facets(struct isl_map *map, int i, int j,
 
                isl_seq_cpy(bound->el, map->p[i]->ineq[cuts[k]], 1 + total);
                isl_int_add_ui(bound->el[0], bound->el[0], 1);
-               tabs[j] = isl_tab_add_eq(tabs[j], bound->el);
+               if (isl_tab_add_eq(tabs[j], bound->el) < 0)
+                       goto error;
                if (isl_tab_detect_redundant(tabs[j]) < 0)
                        goto error;
 
index 4affdaf..5ea612c 100644 (file)
--- a/isl_tab.c
+++ b/isl_tab.c
@@ -1882,7 +1882,7 @@ static int add_zero_row(struct isl_tab *tab)
 /* Add equality "eq" and check if it conflicts with the
  * previously added constraints or if it is obviously redundant.
  */
-struct isl_tab *isl_tab_add_eq(struct isl_tab *tab, isl_int *eq)
+int isl_tab_add_eq(struct isl_tab *tab, isl_int *eq)
 {
        struct isl_tab_undo *snap = NULL;
        struct isl_tab_var *var;
@@ -1892,8 +1892,8 @@ struct isl_tab *isl_tab_add_eq(struct isl_tab *tab, isl_int *eq)
        isl_int cst;
 
        if (!tab)
-               return NULL;
-       isl_assert(tab->mat->ctx, !tab->M, goto error);
+               return -1;
+       isl_assert(tab->mat->ctx, !tab->M, return -1);
 
        if (tab->need_undo)
                snap = isl_tab_snap(tab);
@@ -1908,32 +1908,32 @@ struct isl_tab *isl_tab_add_eq(struct isl_tab *tab, isl_int *eq)
                isl_int_clear(cst);
        }
        if (r < 0)
-               goto error;
+               return -1;
 
        var = &tab->con[r];
        row = var->index;
        if (row_is_manifestly_zero(tab, row)) {
                if (snap) {
                        if (isl_tab_rollback(tab, snap) < 0)
-                               goto error;
+                               return -1;
                } else
                        drop_row(tab, row);
-               return tab;
+               return 0;
        }
 
        if (tab->bmap) {
                tab->bmap = isl_basic_map_add_ineq(tab->bmap, eq);
                if (isl_tab_push(tab, isl_tab_undo_bmap_ineq) < 0)
-                       goto error;
+                       return -1;
                isl_seq_neg(eq, eq, 1 + tab->n_var);
                tab->bmap = isl_basic_map_add_ineq(tab->bmap, eq);
                isl_seq_neg(eq, eq, 1 + tab->n_var);
                if (isl_tab_push(tab, isl_tab_undo_bmap_ineq) < 0)
-                       goto error;
+                       return -1;
                if (!tab->bmap)
-                       goto error;
+                       return -1;
                if (add_zero_row(tab) < 0)
-                       goto error;
+                       return -1;
        }
 
        sgn = isl_int_sgn(tab->mat->row[row][1]);
@@ -1948,25 +1948,22 @@ struct isl_tab *isl_tab_add_eq(struct isl_tab *tab, isl_int *eq)
        if (sgn < 0) {
                sgn = sign_of_max(tab, var);
                if (sgn < -1)
-                       goto error;
+                       return -1;
                if (sgn < 0) {
                        if (isl_tab_mark_empty(tab) < 0)
-                               goto error;
-                       return tab;
+                               return -1;
+                       return 0;
                }
        }
 
        var->is_nonneg = 1;
        if (to_col(tab, var) < 0)
-               goto error;
+               return -1;
        var->is_nonneg = 0;
        if (isl_tab_kill_col(tab, var->index) < 0)
-               goto error;
+               return -1;
 
-       return tab;
-error:
-       isl_tab_free(tab);
-       return NULL;
+       return 0;
 }
 
 /* Construct and return an inequality that expresses an upper bound
@@ -2177,9 +2174,10 @@ struct isl_tab *isl_tab_from_recession_cone(__isl_keep isl_basic_set *bset,
        isl_int_init(cst);
        for (i = 0; i < bset->n_eq; ++i) {
                isl_int_swap(bset->eq[i][offset], cst);
-               if (offset > 0)
-                       tab = isl_tab_add_eq(tab, bset->eq[i] + offset);
-               else
+               if (offset > 0) {
+                       if (isl_tab_add_eq(tab, bset->eq[i] + offset) < 0)
+                               goto error;
+               } else
                        tab = add_eq(tab, bset->eq[i]);
                isl_int_swap(bset->eq[i][offset], cst);
                if (!tab)
index cccfb9b..da7089c 100644 (file)
--- a/isl_tab.h
+++ b/isl_tab.h
@@ -192,7 +192,7 @@ enum isl_lp_result isl_tab_min(struct isl_tab *tab,
 
 struct isl_tab *isl_tab_extend(struct isl_tab *tab, unsigned n_new) WARN_UNUSED;
 int isl_tab_add_ineq(struct isl_tab *tab, isl_int *ineq) WARN_UNUSED;
-struct isl_tab *isl_tab_add_eq(struct isl_tab *tab, isl_int *eq) WARN_UNUSED;
+int isl_tab_add_eq(struct isl_tab *tab, isl_int *eq) WARN_UNUSED;
 struct isl_tab *isl_tab_add_valid_eq(struct isl_tab *tab, isl_int *eq) WARN_UNUSED;
 
 int isl_tab_freeze_constraint(struct isl_tab *tab, int con) WARN_UNUSED;
index 809342b..b616a33 100644 (file)
@@ -2690,7 +2690,8 @@ static struct isl_tab *add_gbr_eq(struct isl_tab *tab, isl_int *eq)
        if (isl_tab_extend_cons(tab, 2) < 0)
                goto error;
 
-       tab = isl_tab_add_eq(tab, eq);
+       if (isl_tab_add_eq(tab, eq) < 0)
+               goto error;
 
        return tab;
 error:
@@ -2708,7 +2709,8 @@ static void context_gbr_add_eq(struct isl_context *context, isl_int *eq,
        if (cgbr->cone && cgbr->cone->n_col != cgbr->cone->n_dead) {
                if (isl_tab_extend_cons(cgbr->cone, 2) < 0)
                        goto error;
-               cgbr->cone = isl_tab_add_eq(cgbr->cone, eq);
+               if (isl_tab_add_eq(cgbr->cone, eq) < 0)
+                       goto error;
        }
 
        if (check) {
index 722fea5..5d2b718 100644 (file)
@@ -1138,11 +1138,8 @@ static struct isl_tab *tab_for_shifted_cone(__isl_keep isl_basic_set *bset)
        isl_int_set_si(c->el[0], 0);
        for (i = 0; i < bset->n_eq; ++i) {
                isl_seq_cpy(c->el + 1, bset->eq[i], c->size - 1);
-               tab = isl_tab_add_eq(tab, c->el);
-               if (!tab) {
-                       isl_vec_free(c);
-                       return tab;
-               }
+               if (isl_tab_add_eq(tab, c->el) < 0)
+                       goto error;
        }
 
        isl_int_set_si(c->el[0], -1);