add isl_mat_set_element_si
[platform/upstream/isl.git] / isl_mat.c
index 271c649..6dc9d19 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -248,6 +248,25 @@ error:
        return NULL;
 }
 
+__isl_give isl_mat *isl_mat_set_element_si(__isl_take isl_mat *mat,
+       int row, int col, int v)
+{
+       mat = isl_mat_cow(mat);
+       if (!mat)
+               return NULL;
+       if (row < 0 || row >= mat->n_row)
+               isl_die(mat->ctx, isl_error_invalid, "row out of range",
+                       goto error);
+       if (col < 0 || col >= mat->n_col)
+               isl_die(mat->ctx, isl_error_invalid, "column out of range",
+                       goto error);
+       isl_int_set_si(mat->row[row][col], v);
+       return mat;
+error:
+       isl_mat_free(mat);
+       return NULL;
+}
+
 struct isl_mat *isl_mat_identity(struct isl_ctx *ctx, unsigned n_row)
 {
        int i;
@@ -528,6 +547,7 @@ error:
                isl_mat_free(*U);
                *U = NULL;
        }
+       isl_mat_free(M);
        return NULL;
 }
 
@@ -937,6 +957,8 @@ struct isl_mat *isl_mat_product(struct isl_mat *left, struct isl_mat *right)
        if (left->n_col == 0) {
                for (i = 0; i < prod->n_row; ++i)
                        isl_seq_clr(prod->row[i], prod->n_col);
+               isl_mat_free(left);
+               isl_mat_free(right);
                return prod;
        }
        for (i = 0; i < prod->n_row; ++i) {