isl_mat.c: fix some warnings
[isl.git] / isl_vec.c
blobc27dcc83af5bdeaf27e59a5b243a60ac338482cd
1 #include "isl_vec.h"
3 struct isl_vec *isl_vec_alloc(struct isl_ctx *ctx, unsigned size)
5 struct isl_vec *vec;
7 vec = isl_alloc_type(ctx, struct isl_vec);
8 if (!vec)
9 return NULL;
11 vec->block = isl_blk_alloc(ctx, size);
12 if (isl_blk_is_error(vec->block))
13 goto error;
15 vec->ref = 1;
16 vec->size = size;
18 return vec;
19 error:
20 isl_blk_free(ctx, vec->block);
21 return NULL;
24 struct isl_vec *isl_vec_copy(struct isl_ctx *ctx, struct isl_vec *vec)
26 if (!vec)
27 return NULL;
29 vec->ref++;
30 return vec;
33 void isl_vec_free(struct isl_ctx *ctx, struct isl_vec *vec)
35 if (!vec)
36 return;
38 if (--vec->ref > 0)
39 return;
41 isl_blk_free(ctx, vec->block);
42 free(vec);
45 void isl_vec_dump(struct isl_ctx *ctx, struct isl_vec *vec,
46 FILE *out, int indent)
48 int i;
49 fprintf(out, "%*s[", indent, "");
50 for (i = 0; i < vec->size; ++i) {
51 if (i)
52 fprintf(out, ",");
53 isl_int_print(out, vec->block.data[i]);
55 fprintf(out, "]\n");