From: Matthew Fernandez Date: Thu, 15 Sep 2022 01:10:43 +0000 (-0700) Subject: sparse SparseMatrix_get_submatrix: use cgraph wrappers for allocation X-Git-Tag: 6.0.2~35^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3f85acc863d5bb2f38cc3865d7c827fedcf3c51;p=graphviz sparse SparseMatrix_get_submatrix: 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/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index 321958796..b67a9cfce 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -2185,8 +2185,8 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int - rmask = MALLOC(sizeof(int)*((size_t)m)); - cmask = MALLOC(sizeof(int)*((size_t)n)); + rmask = gv_calloc((size_t)m, sizeof(int)); + cmask = gv_calloc((size_t)n, sizeof(int)); for (i = 0; i < m; i++) rmask[i] = -1; for (i = 0; i < n; i++) cmask[i] = -1; @@ -2227,9 +2227,9 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int case MATRIX_TYPE_REAL:{ double *a = (double*) A->a; double *val; - irn = MALLOC(sizeof(int)*((size_t)nz)); - jcn = MALLOC(sizeof(int)*((size_t)nz)); - val = MALLOC(sizeof(double)*((size_t)nz)); + irn = gv_calloc((size_t)nz, sizeof(int)); + jcn = gv_calloc((size_t)nz, sizeof(int)); + val = gv_calloc((size_t)nz, sizeof(double)); nz = 0; for (i = 0; i < m; i++){ @@ -2248,9 +2248,9 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int double *a = (double*) A->a; double *val; - irn = MALLOC(sizeof(int)*((size_t)nz)); - jcn = MALLOC(sizeof(int)*((size_t)nz)); - val = MALLOC(sizeof(double)*2*((size_t)nz)); + irn = gv_calloc((size_t)nz, sizeof(int)); + jcn = gv_calloc((size_t)nz, sizeof(int)); + val = gv_calloc(2 * (size_t)nz, sizeof(double)); nz = 0; for (i = 0; i < m; i++){ @@ -2271,9 +2271,9 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int int *a = (int*) A->a; int *val; - irn = MALLOC(sizeof(int)*((size_t)nz)); - jcn = MALLOC(sizeof(int)*((size_t)nz)); - val = MALLOC(sizeof(int)*((size_t)nz)); + irn = gv_calloc((size_t)nz, sizeof(int)); + jcn = gv_calloc((size_t)nz, sizeof(int)); + val = gv_calloc((size_t)nz, sizeof(int)); nz = 0; for (i = 0; i < m; i++){ @@ -2290,8 +2290,8 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int break; } case MATRIX_TYPE_PATTERN: - irn = MALLOC(sizeof(int)*((size_t)nz)); - jcn = MALLOC(sizeof(int)*((size_t)nz)); + irn = gv_calloc((size_t)nz, sizeof(int)); + jcn = gv_calloc((size_t)nz, sizeof(int)); nz = 0; for (i = 0; i < m; i++){ if (rmask[i] < 0) continue;