]> granicus.if.org Git - graphviz/commitdiff
patchwork tree_map: use cgraph wrapper for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 18 Nov 2022 01:14:41 +0000 (17:14 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 4 Dec 2022 18:02:35 +0000 (10:02 -0800)
The lib/cgraph/alloc.h wrappers are similar to the older lib/common/memory.h
wrappers except (1) they are header-only and (2) they live in a directory
(cgraph) that is at the root of the dependency tree. The long term plan is to
replace all use of lib/common/memory.h with lib/cgraph/alloc.h.

lib/patchwork/tree_map.c

index 78c5f484f673f89d521f9bf4f74ba6f7c8634488..2dfd4ec9979a5f40ce2f8ac6018899f2c7dc3150 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
+#include <cgraph/alloc.h>
 #include <common/render.h>
 #include <math.h>
 #include <patchwork/tree_map.h>
@@ -98,7 +99,6 @@ static void squarify(int n, double *area, rectangle *recs, int nadded, double ma
  */
 rectangle* tree_map(int n, double *area, rectangle fillrec){
   /* fill a rectangle rec with n items, each item i has area[i] area. */
-  rectangle *recs;
   int i;
   double total = 0, minarea = 1., maxarea = 0., asp = 1, totalarea = 0;
   int nadded = 0;
@@ -108,7 +108,7 @@ rectangle* tree_map(int n, double *area, rectangle fillrec){
   if (total > fillrec.size[0] * fillrec.size[1] + 0.001)
     return NULL;
   
-  recs = N_NEW(n,rectangle);
+  rectangle *recs = gv_calloc(n, sizeof(rectangle));
   squarify(n, area, recs, nadded, maxarea, minarea, totalarea, asp, fillrec);
   return recs;
 }