From: Matthew Fernandez Date: Wed, 21 Sep 2022 02:31:55 +0000 (-0700) Subject: pack ccomps: use cgraph wrappers for allocation X-Git-Tag: 6.0.2~31^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e559a8e0b39057d56799ff086a2ce96ffa50eae6;p=graphviz pack ccomps: use cgraph wrappers for allocation 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. --- diff --git a/lib/pack/ccomps.c b/lib/pack/ccomps.c index 403897024..04ac926a7 100644 --- a/lib/pack/ccomps.c +++ b/lib/pack/ccomps.c @@ -243,7 +243,6 @@ Agraph_t **ccomps(Agraph_t * g, int *ncc, char *pfx) char *name; Agraph_t *out; Agnode_t *n; - Agraph_t **ccs; size_t len; size_t bnd = 10; stk_t stk; @@ -254,7 +253,7 @@ Agraph_t **ccomps(Agraph_t * g, int *ncc, char *pfx) } name = setPrefix (pfx, &len, buffer, SMALLBUF); - ccs = N_GNEW(bnd, Agraph_t *); + Agraph_t **ccs = gv_calloc(bnd, sizeof(Agraph_t*)); initStk(&stk, insertFn, markFn); for (n = agfstnode(g); n; n = agnxtnode(g, n)) UNMARK(&stk,n); @@ -274,14 +273,14 @@ Agraph_t **ccomps(Agraph_t * g, int *ncc, char *pfx) return NULL; } if (c_cnt == bnd) { + ccs = gv_recalloc(ccs, bnd, bnd * 2, sizeof(Agraph_t*)); bnd *= 2; - ccs = RALLOC(bnd, ccs, Agraph_t *); } ccs[c_cnt] = out; c_cnt++; } freeStk (&stk); - ccs = RALLOC(c_cnt, ccs, Agraph_t *); + ccs = gv_recalloc(ccs, bnd, c_cnt, sizeof(Agraph_t*)); if (name != buffer) free(name); *ncc = (int) c_cnt;