From 776febf69ddce5363c723316fcf79a574ab81595 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 31 May 2020 14:04:49 -0700 Subject: [PATCH] remove MEMCPY wrapper and expand it everywhere This removes one of two MEMCPY macros and replaces invocations of it with its trivial expansion. This makes it more obvious that the remaining MEMCPY calls are seeing the one remaining MEMCPY definition. Related to #1723. --- cmd/gvmap/make_map.c | 4 ++-- lib/edgepaint/furtherest_point.c | 9 +++++---- lib/edgepaint/node_distinct_coloring.c | 5 +++-- lib/mingle/agglomerative_bundling.c | 13 +++++++------ lib/mingle/edge_bundling.c | 11 ++++++----- lib/sfdpgen/post_process.c | 4 ++-- lib/sfdpgen/sparse_solve.c | 4 ++-- lib/sfdpgen/spring_electrical.c | 10 +++++----- lib/sparse/SparseMatrix.c | 26 +++++++++++++------------- lib/sparse/general.h | 1 - lib/sparse/mq.c | 3 ++- 11 files changed, 47 insertions(+), 43 deletions(-) diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index 7dfa4b74c..3950c7226 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -1895,7 +1895,7 @@ int make_map_internal(int exclude_random, int include_OK_points, int *grouping2; nzok0 = nzok = *nrandom - 1;/* points that are within tolerance of real or artificial points */ grouping2 = MALLOC(sizeof(int)*(n + *nrandom)); - MEMCPY(grouping2, grouping, sizeof(int)*n); + memcpy(grouping2, grouping, sizeof(int)*n); grouping = grouping2; } nn = n; @@ -1996,7 +1996,7 @@ int make_map_internal(int exclude_random, int include_OK_points, for (i = nh; i < n; i++){ grouping[i] = 2; } - MEMCPY(*xcombined, xtemp, n*dim*sizeof(real)); + memcpy(*xcombined, xtemp, n*dim*sizeof(real)); *nrandom = *nrandom + n - nh;/* count everything except cluster HIGHLIGHT_SET as random */ n = nh; if (Verbose) fprintf(stderr,"nh = %d\n",nh); diff --git a/lib/edgepaint/furtherest_point.c b/lib/edgepaint/furtherest_point.c index f604d3b18..c2fbf5f00 100644 --- a/lib/edgepaint/furtherest_point.c +++ b/lib/edgepaint/furtherest_point.c @@ -10,6 +10,7 @@ #include "general.h" #include "QuadTree.h" #include "furtherest_point.h" +#include static real dist(int dim, real *x, real *y){ int k; @@ -87,7 +88,7 @@ void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real w qt->total_weight = *dist_max = distance_to_group(k, dim, wgt, pts, center, usr_dist);/* store distance in total_weight */ if (!(*argmax)) *argmax = MALLOC(sizeof(real)*dim); - MEMCPY(*argmax, center, sizeof(real)*dim); + memcpy(*argmax, center, sizeof(real)*dim); candidates = MALLOC(sizeof(qt)*ncandidates_max); candidates2 = MALLOC(sizeof(qt)*ncandidates2_max); @@ -128,7 +129,7 @@ void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real w for (j = 0; j < dim; j++) fprintf(stderr,"%f, ", qt->qts[ii]->center[j]); fprintf(stderr,"}\n"); } - MEMCPY(*argmax, qt->qts[ii]->center, sizeof(real)*dim); + memcpy(*argmax, qt->qts[ii]->center, sizeof(real)*dim); } else if (distance + wmax*sqrt(((real) dim))*(qt->width)/2 < *dist_max){ pruned = TRUE; } @@ -219,7 +220,7 @@ void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, average = qt->average; qt->total_weight = *dist_max = distance_to_group(k, dim, wgt, pts, average, usr_dist);/* store distance in total_weight */ if (!(*argmax)) *argmax = MALLOC(sizeof(real)*dim); - MEMCPY(*argmax, average, sizeof(real)*dim); + memcpy(*argmax, average, sizeof(real)*dim); candidates = MALLOC(sizeof(qt)*ncandidates_max); candidates2 = MALLOC(sizeof(qt)*ncandidates2_max); @@ -260,7 +261,7 @@ void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, for (j = 0; j < dim; j++) fprintf(stderr,"%f, ", qt->qts[ii]->average[j]); fprintf(stderr,"}\n"); } - MEMCPY(*argmax, qt->qts[ii]->average, sizeof(real)*dim); + memcpy(*argmax, qt->qts[ii]->average, sizeof(real)*dim); } else if (distance + wmax*sqrt(((real) dim))*(qt->width) < *dist_max){/* average feasible point in this square is too close to the point set */ pruned = TRUE; } diff --git a/lib/edgepaint/node_distinct_coloring.c b/lib/edgepaint/node_distinct_coloring.c index 9c5bb0325..5b27fa339 100644 --- a/lib/edgepaint/node_distinct_coloring.c +++ b/lib/edgepaint/node_distinct_coloring.c @@ -14,6 +14,7 @@ #include "lab.h" #include "furtherest_point.h" #include "color_palette.h" +#include #ifndef _WIN32 inline @@ -140,7 +141,7 @@ static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weight k = 0; for (j = ia[i]; j < ia[i+1]; j++){ if (ja[j] == i) continue; - MEMCPY(&(x[k*cdim]), &(colors[ja[j]*cdim]), sizeof(real)*cdim); + memcpy(&(x[k*cdim]), &(colors[ja[j]*cdim]), sizeof(real)*cdim); if (wgt && a) wgt[k] = a[j]; k++; } @@ -307,7 +308,7 @@ void node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, for (j = comps_ptr[i]; j < comps_ptr[i+1]; j++){ jj = j - comps_ptr[i]; - MEMCPY(&((*colors)[comps[j]*cdim]), &(ctmp[jj*cdim]), cdim*sizeof(real)); + memcpy(&((*colors)[comps[j]*cdim]), &(ctmp[jj*cdim]), cdim*sizeof(real)); } SparseMatrix_delete(B); } diff --git a/lib/mingle/agglomerative_bundling.c b/lib/mingle/agglomerative_bundling.c index 27aa9f20f..c3cdd3a77 100644 --- a/lib/mingle/agglomerative_bundling.c +++ b/lib/mingle/agglomerative_bundling.c @@ -18,6 +18,7 @@ #include "ink.h" #include "agglomerative_bundling.h" #include "nearest_neighbor_graph.h" +#include #if OPENGL #include "gl.h" @@ -132,8 +133,8 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera if (ip && jp){/* not the first level */ ni = (ip[i+1] - ip[i]);/* number of edges represented by i */ nj = (ip[jj+1] - ip[jj]);/* number of edges represented by jj */ - MEMCPY(pick, &(jp[ip[i]]), sizeof(int)*ni); - MEMCPY(pick+ni, &(jp[ip[jj]]), sizeof(int)*nj); + memcpy(pick, &(jp[ip[i]]), sizeof(int)*ni); + memcpy(pick+ni, &(jp[ip[jj]]), sizeof(int)*nj); } else {/* first level */ pick[0] = i; pick[1] = jj; ni = nj = 1; @@ -145,7 +146,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera if (Verbose && DEBUG) fprintf(stderr, "ink(%d)=%f, ink(%d->%d)=%f", i, inki, jj, jc, inkj); if (ip) { ni = (ip[i+1] - ip[i]);/* number of edges represented by i */ - MEMCPY(pick, &(jp[ip[i]]), sizeof(int)*ni); + memcpy(pick, &(jp[ip[i]]), sizeof(int)*ni); } else { ni = 1; pick[0] = i; } @@ -359,8 +360,8 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_aggressive_establis if (ip && jp){/* not the first level */ ni = (ip[i+1] - ip[i]);/* number of edges represented by i */ nj = (ip[jj+1] - ip[jj]);/* number of edges represented by jj */ - MEMCPY(pick, &(jp[ip[i]]), sizeof(int)*ni); - MEMCPY(pick+ni, &(jp[ip[jj]]), sizeof(int)*nj); + memcpy(pick, &(jp[ip[i]]), sizeof(int)*ni); + memcpy(pick+ni, &(jp[ip[jj]]), sizeof(int)*nj); } else {/* first level */ pick[0] = i; pick[1] = jj; ni = nj = 1; @@ -372,7 +373,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_aggressive_establis if (Verbose && DEBUG) fprintf(stderr, "ink(%d)=%f, ink(%d->%d)=%f", i, inki, jj, jc, inkj); if (ip) { ni = (ip[i+1] - ip[i]);/* number of edges represented by i */ - MEMCPY(pick, &(jp[ip[i]]), sizeof(int)*ni); + memcpy(pick, &(jp[ip[i]]), sizeof(int)*ni); } else { ni = 1; pick[0] = i; } diff --git a/lib/mingle/edge_bundling.c b/lib/mingle/edge_bundling.c index e0e2af625..4cfb157c2 100644 --- a/lib/mingle/edge_bundling.c +++ b/lib/mingle/edge_bundling.c @@ -19,6 +19,7 @@ #include "clustering.h" #include "ink.h" #include "agglomerative_bundling.h" +#include #define SMALL 1.e-10 @@ -54,7 +55,7 @@ pedge pedge_new(int np, int dim, real *x){ e->dim = dim; e->len = np; e->x = MALLOC(dim*(e->len)*sizeof(real)); - MEMCPY(e->x, x, dim*(e->len)*sizeof(real)); + memcpy(e->x, x, dim*(e->len)*sizeof(real)); e->edge_length = dist(dim, &(x[0*dim]), &(x[(np-1)*dim])); e->wgt = 1.; e->wgts = NULL; @@ -70,7 +71,7 @@ pedge pedge_wgt_new(int np, int dim, real *x, real wgt){ e->dim = dim; e->len = np; e->x = MALLOC(dim*(e->len)*sizeof(real)); - MEMCPY(e->x, x, dim*(e->len)*sizeof(real)); + memcpy(e->x, x, dim*(e->len)*sizeof(real)); e->edge_length = dist(dim, &(x[0*dim]), &(x[(np-1)*dim])); e->wgt = wgt; e->wgts = MALLOC(sizeof(real)*(np - 1)); @@ -92,9 +93,9 @@ pedge pedge_flip(pedge e){ y = MALLOC(sizeof(real)*e->dim); for (i = 0; i < (e->npoints)/2; i++){ - MEMCPY(y, &(x[i*dim]), sizeof(real)*dim); - MEMCPY(&(x[(n-1-i)*dim]), &(x[i*dim]), sizeof(real)*dim); - MEMCPY(&(x[i*dim]), y, sizeof(real)*dim); + memcpy(y, &(x[i*dim]), sizeof(real)*dim); + memcpy(&(x[(n-1-i)*dim]), &(x[i*dim]), sizeof(real)*dim); + memcpy(&(x[i*dim]), y, sizeof(real)*dim); } FREE(y); return e; diff --git a/lib/sfdpgen/post_process.c b/lib/sfdpgen/post_process.c index 57cc9870e..33519e715 100644 --- a/lib/sfdpgen/post_process.c +++ b/lib/sfdpgen/post_process.c @@ -822,7 +822,7 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r x0 = N_GNEW(dim*m,real); if (!x0) goto RETURN; - x0 = MEMCPY(x0, x, sizeof(real)*dim*m); + memcpy(x0, x, sizeof(real)*dim*m); y = N_GNEW(dim*m,real); if (!y) goto RETURN; @@ -989,7 +989,7 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r #endif - MEMCPY(x, y, sizeof(real)*m*dim); + memcpy(x, y, sizeof(real)*m*dim); } #ifdef DEBUG diff --git a/lib/sfdpgen/sparse_solve.c b/lib/sfdpgen/sparse_solve.c index 14b4f23cb..b8fab8471 100644 --- a/lib/sfdpgen/sparse_solve.c +++ b/lib/sfdpgen/sparse_solve.c @@ -189,7 +189,7 @@ static real conjugate_gradient(Operator A, Operator precon, int n, real *x, real beta = rho/rho_old; p = vector_saxpy(n, z, p, beta); } else { - MEMCPY(p, z, sizeof(real)*n); + memcpy(p, z, sizeof(real)*n); } q = Ax(A, p, q); @@ -277,7 +277,7 @@ real* jacobi(SparseMatrix A, int dim, real *x0, real *rhs, int maxit, int *flag) y[i] = (b[i] - sum)/diag; } - MEMCPY(x, y, sizeof(real)*n); + memcpy(x, y, sizeof(real)*n); } for (i = 0; i < n; i++) { diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index 45cf47a5f..cf9d30503 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -559,7 +559,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica #endif iter++; - xold = MEMCPY(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(real)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; @@ -764,7 +764,7 @@ void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_electrica for (i = 0; i < dim*n; i++) force[i] = 0; iter++; - xold = MEMCPY(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(real)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; @@ -1046,7 +1046,7 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con #endif iter++; - xold = MEMCPY(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(real)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; @@ -1364,7 +1364,7 @@ void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_el xold = MALLOC(sizeof(real)*dim*n); do { iter++; - xold = MEMCPY(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(real)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; @@ -1604,7 +1604,7 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D xold = MALLOC(sizeof(real)*dim*n); do { iter++; - xold = MEMCPY(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(real)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; diff --git a/lib/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index 96427eb7a..b87f1fb0f 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -933,7 +933,7 @@ static SparseMatrix SparseMatrix_from_coordinate_arrays_internal(int nz, int m, ia[irn[i]+1]++; } for (i = 0; i < m; i++) ia[i+1] += ia[i]; - MEMCPY(A->a, val0, A->size*((size_t)nz)); + memcpy(A->a, val0, A->size*((size_t)nz)); for (i = 0; i < nz; i++){ ja[ia[irn[i]]++] = jcn[i]; } @@ -1102,7 +1102,7 @@ static void dense_transpose(real *v, int m, int n){ int i, j; real *u; u = MALLOC(sizeof(real)*((size_t) m)*((size_t) n)); - MEMCPY(u,v, sizeof(real)*((size_t) m)*((size_t) n)); + memcpy(u,v, sizeof(real)*((size_t) m)*((size_t) n)); for (i = 0; i < m; i++){ for (j = 0; j < n; j++){ @@ -1978,9 +1978,9 @@ SparseMatrix SparseMatrix_coordinate_form_add_entries(SparseMatrix A, int nentri nzmax = MAX(10, (int) 0.2*nzmax) + nzmax; A = SparseMatrix_realloc(A, nzmax); } - MEMCPY((char*) A->ia + ((size_t)nz)*sizeof(int)/sizeof(char), irn, sizeof(int)*((size_t)nentries)); - MEMCPY((char*) A->ja + ((size_t)nz)*sizeof(int)/sizeof(char), jcn, sizeof(int)*((size_t)nentries)); - if (A->size) MEMCPY((char*) A->a + ((size_t)nz)*A->size/sizeof(char), val, A->size*((size_t)nentries)); + memcpy((char*) A->ia + ((size_t)nz)*sizeof(int)/sizeof(char), irn, sizeof(int)*((size_t)nentries)); + memcpy((char*) A->ja + ((size_t)nz)*sizeof(int)/sizeof(char), jcn, sizeof(int)*((size_t)nentries)); + if (A->size) memcpy((char*) A->a + ((size_t)nz)*A->size/sizeof(char), val, A->size*((size_t)nentries)); for (i = 0; i < nentries; i++) { if (irn[i] >= A->m) A->m = irn[i]+1; if (jcn[i] >= A->n) A->n = jcn[i]+1; @@ -2223,8 +2223,8 @@ SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A){ B = SparseMatrix_new(m, n, nz, MATRIX_TYPE_PATTERN, FORMAT_CSR); - MEMCPY(B->ia, ia, sizeof(int)*((size_t)(m+1))); - MEMCPY(B->ja, ja, sizeof(int)*((size_t)nz)); + memcpy(B->ia, ia, sizeof(int)*((size_t)(m+1))); + memcpy(B->ja, ja, sizeof(int)*((size_t)nz)); B->nz = A->nz; A = SparseMatrix_symmetrize(B, TRUE); @@ -2472,9 +2472,9 @@ SparseMatrix SparseMatrix_copy(SparseMatrix A){ SparseMatrix B; if (!A) return A; B = SparseMatrix_general_new(A->m, A->n, A->nz, A->type, A->size, A->format); - MEMCPY(B->ia, A->ia, sizeof(int)*((size_t)(A->m+1))); - MEMCPY(B->ja, A->ja, sizeof(int)*((size_t)(A->ia[A->m]))); - if (A->a) MEMCPY(B->a, A->a, A->size*((size_t)A->nz)); + memcpy(B->ia, A->ia, sizeof(int)*((size_t)(A->m+1))); + memcpy(B->ja, A->ja, sizeof(int)*((size_t)(A->ia[A->m]))); + if (A->a) memcpy(B->a, A->a, A->size*((size_t)A->nz)); B->property = A->property; B->nz = A->nz; return B; @@ -2987,8 +2987,8 @@ SparseMatrix SparseMatrix_get_augmented(SparseMatrix A){ if (A->a){ assert(A->size != 0 && nz > 0); val = MALLOC(A->size*2*((size_t)nz)); - MEMCPY(val, A->a, A->size*((size_t)nz)); - MEMCPY((void*)(((char*) val) + ((size_t)nz)*A->size), A->a, A->size*((size_t)nz)); + memcpy(val, A->a, A->size*((size_t)nz)); + memcpy((void*)(((char*) val) + ((size_t)nz)*A->size), A->a, A->size*((size_t)nz)); } nz = 0; @@ -4178,7 +4178,7 @@ void SparseMatrix_page_rank(SparseMatrix A, real teleport_probablity, int weight res = 0; for (i = 0; i < n; i++) res += ABS(x[i] - y[i]); if (Verbose) fprintf(stderr,"page rank iter -- %d, res = %f\n",iter, res); - MEMCPY(x, y, sizeof(real)*n); + memcpy(x, y, sizeof(real)*n); } while (res > epsilon); FREE(y); diff --git a/lib/sparse/general.h b/lib/sparse/general.h index 964527250..5d788051f 100644 --- a/lib/sparse/general.h +++ b/lib/sparse/general.h @@ -71,7 +71,6 @@ extern unsigned char Verbose; #endif /* STANDALONE */ #define FREE free -#define MEMCPY memcpy #ifndef DEBUG #ifndef NDEBUG diff --git a/lib/sparse/mq.c b/lib/sparse/mq.c index e5e21407c..eddee3310 100644 --- a/lib/sparse/mq.c +++ b/lib/sparse/mq.c @@ -63,6 +63,7 @@ #include "SparseMatrix.h" #include "mq.h" #include "LinkedList.h" +#include static real get_mq(SparseMatrix A, int *assignment, int *ncluster0, real *mq_in0, real *mq_out0, real **dout0){ /* given a symmetric matrix representation of a graph and an assignment of nodes into clusters, calculate the modularity quality. @@ -340,7 +341,7 @@ Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ_Cluste double mq2, mq_in2, mq_out2, *dout2; int *matching2, nc2 = nc; matching2 = MALLOC(sizeof(int)*A->m); - matching2 = MEMCPY(matching2, matching, sizeof(real)*A->m); + memcpy(matching2, matching, sizeof(real)*A->m); if (jc != UNMATCHED) { matching2[i] = jc; } else { -- 2.40.0