]> granicus.if.org Git - graphviz/commitdiff
remove MEMCPY wrapper and expand it everywhere
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 31 May 2020 21:04:49 +0000 (14:04 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 6 Jun 2020 00:34:31 +0000 (17:34 -0700)
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
lib/edgepaint/furtherest_point.c
lib/edgepaint/node_distinct_coloring.c
lib/mingle/agglomerative_bundling.c
lib/mingle/edge_bundling.c
lib/sfdpgen/post_process.c
lib/sfdpgen/sparse_solve.c
lib/sfdpgen/spring_electrical.c
lib/sparse/SparseMatrix.c
lib/sparse/general.h
lib/sparse/mq.c

index 7dfa4b74c9ebaa384e14f4e1124988f89d938705..3950c722687c61ae50a93a434d543137488e7b5a 100644 (file)
@@ -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);
index f604d3b18a3674259a262d3586fc2c4ae2dc4cdd..c2fbf5f00452cea4787a77dece2b4c45f23a9884 100644 (file)
@@ -10,6 +10,7 @@
 #include "general.h"
 #include "QuadTree.h"
 #include "furtherest_point.h"
+#include <string.h>
 
 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;
        }
index 9c5bb0325e65cffd8ea1eb6a674bb9ffdffc9a25..5b27fa339141e7fed3664609400e6b18692d6054 100644 (file)
@@ -14,6 +14,7 @@
 #include "lab.h"
 #include "furtherest_point.h"
 #include "color_palette.h"
+#include <string.h>
 
 #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);
   }
index 27aa9f20f3dfa7b7d1317aaa27b40cc363c91e7f..c3cdd3a7713bae33da72dd9f50f6e9bdc94c50fd 100644 (file)
@@ -18,6 +18,7 @@
 #include "ink.h"
 #include "agglomerative_bundling.h"
 #include "nearest_neighbor_graph.h"
+#include <string.h>
 
 #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; 
          }
index e0e2af625dfa572af333bb9a6080472943847f54..4cfb157c2b8054308a695296041b4284ef516313 100644 (file)
@@ -19,6 +19,7 @@
 #include "clustering.h"
 #include "ink.h"
 #include "agglomerative_bundling.h"
+#include <string.h>
 
 #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;
index 57cc9870edc8ca6e2e6ac28d98b802a854ef250d..33519e715bdcebc6b1ae5b518c0a337d2d2415dc 100644 (file)
@@ -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
index 14b4f23cb4d09d06075c6bdfabf2dcf2f29c8d91..b8fab847193b26b458fc204efa969c18d808067b 100644 (file)
@@ -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++) {
index 45cf47a5fb630ebb2e7ba3c8631feaf7828a8405..cf9d30503a8c5028d6a40f875a4df977051a0df4 100644 (file)
@@ -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;
index 96427eb7a4f93bf538ebbcba0537f21216d3b8b8..b87f1fb0f93470c296aebaa4ed48f86a9b574946 100644 (file)
@@ -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);
index 9645272508f6f35f73743bf33f3f66c486b4f58a..5d788051f02c4da29eb8919e99015bf657d467d5 100644 (file)
@@ -71,7 +71,6 @@ extern unsigned char Verbose;
 #endif    /* STANDALONE */
 
 #define FREE free
-#define MEMCPY memcpy
 
 #ifndef DEBUG
 #ifndef NDEBUG
index e5e21407c5794a7d853c99d68531dad7911b59c9..eddee3310501ea9b02902b4bf4f1dcc88b1640eb 100644 (file)
@@ -63,6 +63,7 @@
 #include "SparseMatrix.h"
 #include "mq.h"
 #include "LinkedList.h"
+#include <string.h>
 
 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 {