Prechádzať zdrojové kódy

fix and improve memory handling by better allocations and proper type use (backport of https://trac.osgeo.org/grass/changeset/61812)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@62279 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 10 rokov pred
rodič
commit
5bd2126d8d

+ 3 - 4
raster/r.li/r.li.daemon/avl.c

@@ -193,7 +193,7 @@ int avl_add(avl_tree * root, const generic_cell k, const long n)
 
 
 
-long avl_to_array(avl_node * root, long i, AVL_table * a)
+long avl_to_array(avl_node * root, long i, AVL_table a)
 {
 
     if (root != NULL) {
@@ -201,9 +201,8 @@ long avl_to_array(avl_node * root, long i, AVL_table * a)
 	if (a == NULL)
 	    G_fatal_error("avl, avl_to_array: null value");
 	else {
-	    a[i] = G_malloc(sizeof(AVL_tableRow));
-	    a[i]->k = root->key;
-	    a[i]->tot = root->counter;
+	    a[i].k = root->key;
+	    a[i].tot = root->counter;
 	    i++;
 	    i = avl_to_array(root->right_child, i, a);
 	}

+ 1 - 1
raster/r.li/r.li.daemon/avl.h

@@ -37,7 +37,7 @@ avl_tree avl_make(const generic_cell k, const long n);
 void avl_destroy(avl_tree root);
 avl_node *avl_find(const avl_tree root, const generic_cell k);
 int avl_add(avl_tree * root, const generic_cell k, const long n);
-long avl_to_array(avl_node * root, long i, AVL_table * a);
+long avl_to_array(avl_node * root, long i, AVL_table a);
 long howManyCell(const avl_tree root, const generic_cell k);
 
 

+ 6 - 6
raster/r.li/r.li.dominance/dominance.c

@@ -123,7 +123,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -310,7 +310,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -456,7 +456,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -497,7 +497,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -643,7 +643,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;

+ 6 - 6
raster/r.li/r.li.pielou/pielou.c

@@ -123,7 +123,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -310,7 +310,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -456,7 +456,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -497,7 +497,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -643,7 +643,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;

+ 6 - 6
raster/r.li/r.li.renyi/renyi.c

@@ -147,7 +147,7 @@ int calculate(int fd, struct area_entry *ad, char **par, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -297,7 +297,7 @@ int calculate(int fd, struct area_entry *ad, char **par, double *result)
 	sum = 0;
 	sum2 = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    pi = t / area;
 	    sum += pow(pi, alpha);
 	    sum2 += pi;
@@ -348,7 +348,7 @@ int calculateD(int fd, struct area_entry *ad, char **par, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -498,7 +498,7 @@ int calculateD(int fd, struct area_entry *ad, char **par, double *result)
 	sum = 0;
 	sum2 = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    pi = t / area;
 	    sum += pow(pi, alpha);
 	    sum += pi;
@@ -549,7 +549,7 @@ int calculateF(int fd, struct area_entry *ad, char **par, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -699,7 +699,7 @@ int calculateF(int fd, struct area_entry *ad, char **par, double *result)
 	sum = 0;
 	sum2 = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    pi = t / area;
 	    sum += pow(pi, alpha);
 	    sum2 += pi;

+ 6 - 6
raster/r.li/r.li.shannon/shannon.c

@@ -123,7 +123,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -310,7 +310,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -456,7 +456,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -497,7 +497,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -643,7 +643,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;

+ 6 - 6
raster/r.li/r.li.simpson/simpson.c

@@ -123,7 +123,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
 	/* calculate simpson */
 	simpson = 0;
 	for (i = 0; i < m; i++) {
-	    t = (double)(array[i]->tot);
+	    t = (double)(array[i].tot);
 	    p = t / area;
 	    simpson += (p * p);
 	}
@@ -309,7 +309,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -455,7 +455,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 	/* calculate simpson */
 	simpson = 0;
 	for (i = 0; i < m; i++) {
-	    t = (double)(array[i]->tot);
+	    t = (double)(array[i].tot);
 	    p = t / area;
 	    simpson += (p * p);
 	}
@@ -495,7 +495,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -641,7 +641,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 	/* calculate simpson */
 	simpson = 0;
 	for (i = 0; i < m; i++) {
-	    t = (double)(array[i]->tot);
+	    t = (double)(array[i].tot);
 	    p = t / area;
 	    simpson += (p * p);
 	}