*_list_free: return NULL
[platform/upstream/isl.git] / isl_list_templ.c
index baae501..00f993d 100644 (file)
@@ -54,6 +54,22 @@ __isl_give LIST(EL) *FN(LIST(EL),copy)(__isl_keep LIST(EL) *list)
        return list;
 }
 
+__isl_give LIST(EL) *FN(LIST(EL),dup)(__isl_keep LIST(EL) *list)
+{
+       int i;
+       LIST(EL) *dup;
+
+       if (!list)
+               return NULL;
+
+       dup = FN(LIST(EL),alloc)(FN(LIST(EL),get_ctx)(list), list->n);
+       if (!dup)
+               return NULL;
+       for (i = 0; i < list->n; ++i)
+               dup = FN(LIST(EL),add)(dup, FN(EL,copy)(list->p[i]));
+       return dup;
+}
+
 __isl_give LIST(EL) *FN(LIST(EL),add)(__isl_take LIST(EL) *list,
        __isl_take struct EL *el)
 {
@@ -69,20 +85,22 @@ error:
        return NULL;
 }
 
-void FN(LIST(EL),free)(__isl_take LIST(EL) *list)
+void *FN(LIST(EL),free)(__isl_take LIST(EL) *list)
 {
        int i;
 
        if (!list)
-               return;
+               return NULL;
 
        if (--list->ref > 0)
-               return;
+               return NULL;
 
        isl_ctx_deref(list->ctx);
        for (i = 0; i < list->n; ++i)
                FN(EL,free)(list->p[i]);
        free(list);
+
+       return NULL;
 }
 
 int FN(FN(LIST(EL),n),BASE)(__isl_keep LIST(EL) *list)
@@ -118,3 +136,37 @@ int FN(LIST(EL),foreach)(__isl_keep LIST(EL) *list,
 
        return 0;
 }
+
+__isl_give isl_printer *CAT(isl_printer_print_,LIST(BASE))(
+       __isl_take isl_printer *p, __isl_keep LIST(EL) *list)
+{
+       int i;
+
+       if (!p || !list)
+               goto error;
+       p = isl_printer_print_str(p, "(");
+       for (i = 0; i < list->n; ++i) {
+               if (i)
+                       p = isl_printer_print_str(p, ",");
+               p = CAT(isl_printer_print_,BASE)(p, list->p[i]);
+       }
+       p = isl_printer_print_str(p, ")");
+       return p;
+error:
+       isl_printer_free(p);
+       return NULL;
+}
+
+void FN(LIST(EL),dump)(__isl_keep LIST(EL) *list)
+{
+       isl_printer *printer;
+
+       if (!list)
+               return;
+
+       printer = isl_printer_to_file(FN(LIST(EL),get_ctx)(list), stderr);
+       printer = CAT(isl_printer_print_,LIST(BASE))(printer, list);
+       printer = isl_printer_end_line(printer);
+
+       isl_printer_free(printer);
+}