]> granicus.if.org Git - graphviz/commitdiff
sparse SparseMatrix_realloc: use cgraph wrappers for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 15 Sep 2022 00:53:49 +0000 (17:53 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 20 Sep 2022 14:36:59 +0000 (07:36 -0700)
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/sparse/SparseMatrix.c

index c924bd5402fb833d485c35fb20f6d3a395da5a57..77d371000fdbf5d50ea7f469ae40d1437960f811 100644 (file)
@@ -348,25 +348,25 @@ static SparseMatrix SparseMatrix_realloc(SparseMatrix A, int nz){
 
   switch (format){
   case FORMAT_COORD:
-    A->ia = REALLOC(A->ia, sizeof(int)*nz_t);
-    A->ja = REALLOC(A->ja, sizeof(int)*nz_t);
+    A->ia = gv_recalloc(A->ia, A->nzmax, nz_t, sizeof(int));
+    A->ja = gv_recalloc(A->ja, A->nzmax, nz_t, sizeof(int));
     if (A->size > 0) {
       if (A->a){
-       A->a = REALLOC(A->a, A->size*nz_t);
+       A->a = gv_recalloc(A->a, A->nzmax, nz_t, A->size);
       } else {
-       A->a = MALLOC(A->size*nz_t);
+       A->a = gv_calloc(nz_t, A->size);
       }
     } 
     break;
   case FORMAT_CSR:
   case FORMAT_CSC:
   default:
-    A->ja = REALLOC(A->ja, sizeof(int)*nz_t);
+    A->ja = gv_recalloc(A->ja, A->nzmax, nz_t, sizeof(int));
     if (A->size > 0) {
       if (A->a){
-       A->a = REALLOC(A->a, A->size*nz_t);
+       A->a = gv_recalloc(A->a, A->nzmax, nz_t, A->size);
       } else {
-       A->a = MALLOC(A->size*nz_t);
+       A->a = gv_calloc(nz_t, A->size);
       }
     }
     break;