[GRASS-SVN] r36851 - grass/trunk/lib/vector/diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Apr 21 14:35:07 EDT 2009


Author: mmetz
Date: 2009-04-21 14:35:07 -0400 (Tue, 21 Apr 2009)
New Revision: 36851

Modified:
   grass/trunk/lib/vector/diglib/allocation.c
   grass/trunk/lib/vector/diglib/cindex.c
   grass/trunk/lib/vector/diglib/list.c
   grass/trunk/lib/vector/diglib/plus.c
   grass/trunk/lib/vector/diglib/rbtree.c
   grass/trunk/lib/vector/diglib/struct_alloc.c
Log:
G_* versions for memory management

Modified: grass/trunk/lib/vector/diglib/allocation.c
===================================================================
--- grass/trunk/lib/vector/diglib/allocation.c	2009-04-21 16:34:51 UTC (rev 36850)
+++ grass/trunk/lib/vector/diglib/allocation.c	2009-04-21 18:35:07 UTC (rev 36851)
@@ -78,7 +78,7 @@
 
     /*  first time called allocate initial storage  */
     if (*n_elements == 0)
-	ptr = calloc((unsigned)to_alloc, (unsigned)element_size);
+	ptr = G_calloc((unsigned)to_alloc, (unsigned)element_size);
     else
 	ptr = dig__frealloc((char *)ptr, to_alloc, element_size, *n_elements);
 
@@ -126,7 +126,7 @@
 	nelem = 1;
     }
 
-    ptr = calloc((unsigned)nelem, (unsigned)elsize);
+    ptr = G_calloc((unsigned)nelem, (unsigned)elsize);
     return (ptr);
 }
 
@@ -141,7 +141,7 @@
 	nelem = 1;
     }
 
-    ptr = calloc((unsigned)nelem, (unsigned)elsize);
+    ptr = G_calloc((unsigned)nelem, (unsigned)elsize);
 
     /*  out of memory  */
     if (!ptr)
@@ -159,6 +159,6 @@
 	    *a++ = *b++;
     }
 
-    free(oldptr);
+    G_free(oldptr);
     return (ptr);
 }

Modified: grass/trunk/lib/vector/diglib/cindex.c
===================================================================
--- grass/trunk/lib/vector/diglib/cindex.c	2009-04-21 16:34:51 UTC (rev 36850)
+++ grass/trunk/lib/vector/diglib/cindex.c	2009-04-21 18:35:07 UTC (rev 36851)
@@ -49,7 +49,7 @@
     G_debug(2, "dig_cidx_free()");
     for (i = 0; i < Plus->n_cidx; i++) {
 	ci = &(Plus->cidx[0]);
-	free(ci->cat);
+	G_free(ci->cat);
 	ci->cat = NULL;
 	ci->field = ci->n_cats = ci->a_cats = ci->n_types = 0;
     }

Modified: grass/trunk/lib/vector/diglib/list.c
===================================================================
--- grass/trunk/lib/vector/diglib/list.c	2009-04-21 16:34:51 UTC (rev 36850)
+++ grass/trunk/lib/vector/diglib/list.c	2009-04-21 18:35:07 UTC (rev 36851)
@@ -37,7 +37,7 @@
 
     if (list->n_values == list->alloc_values) {
 	size = (list->n_values + 1000) * sizeof(int);
-	p = realloc((void *)list->value, size);
+	p = G_realloc((void *)list->value, size);
 	if (p == NULL)
 	    return 0;
 	list->value = (int *)p;

Modified: grass/trunk/lib/vector/diglib/plus.c
===================================================================
--- grass/trunk/lib/vector/diglib/plus.c	2009-04-21 16:34:51 UTC (rev 36850)
+++ grass/trunk/lib/vector/diglib/plus.c	2009-04-21 18:35:07 UTC (rev 36851)
@@ -122,7 +122,7 @@
 
 	    dig_free_node(Node);
 	}
-	free(Plus->Node);
+	G_free(Plus->Node);
     }
     Plus->Node = NULL;
     Plus->n_nodes = 0;
@@ -150,7 +150,7 @@
 
 	    dig_free_line(Line);
 	}
-	free(Plus->Line);
+	G_free(Plus->Line);
     }
 
     Plus->Line = NULL;
@@ -186,7 +186,7 @@
 
 	    dig_free_area(Area);
 	}
-	free(Plus->Area);
+	G_free(Plus->Area);
     }
     Plus->Area = NULL;
     Plus->n_areas = 0;
@@ -214,7 +214,7 @@
 
 	    dig_free_isle(Isle);
 	}
-	free(Plus->Isle);
+	G_free(Plus->Isle);
     }
 
     Plus->Isle = NULL;

Modified: grass/trunk/lib/vector/diglib/rbtree.c
===================================================================
--- grass/trunk/lib/vector/diglib/rbtree.c	2009-04-21 16:34:51 UTC (rev 36850)
+++ grass/trunk/lib/vector/diglib/rbtree.c	2009-04-21 18:35:07 UTC (rev 36851)
@@ -49,7 +49,7 @@
  */
 struct RB_TREE *rbtree_create(rb_compare_fn *compare, size_t rb_datasize)
 {
-    struct RB_TREE *tree = malloc(sizeof(*tree));
+    struct RB_TREE *tree = G_malloc(sizeof(*tree));
 
     if (tree == NULL) {
 	G_warning("RB tree: Out of memory!");
@@ -220,10 +220,10 @@
 
     /* Replace and remove if found */
     if (f != NULL) {
-	free(f->data);
+	G_free(f->data);
 	f->data = q->data;
 	p->link[p->link[1] == q] = q->link[q->link[0] == NULL];
-	free(q);
+	G_free(q);
 	tree->count--;
 	removed = 1;
     }
@@ -413,7 +413,7 @@
 /* destroy the tree */
 void rbtree_destroy(struct RB_TREE *tree) {
     rbtree_destroy2(tree->root);
-    free(tree);
+    G_free(tree);
 }
 
 void rbtree_destroy2(struct RB_NODE *root)
@@ -421,8 +421,8 @@
     if (root != NULL) {
 	rbtree_destroy2(root->link[0]);
 	rbtree_destroy2(root->link[1]);
-	free(root->data);
-	free(root);
+	G_free(root->data);
+	G_free(root);
     }
 }
 
@@ -488,12 +488,12 @@
 /* add a new node to the tree */
 struct RB_NODE *rbtree_make_node(size_t datasize, void *data)
 {
-    struct RB_NODE *new_node = malloc(sizeof(*new_node));
+    struct RB_NODE *new_node = G_malloc(sizeof(*new_node));
 
     if (new_node == NULL)
 	G_fatal_error("RB Search Tree: Out of memory!");
 
-    new_node->data = malloc(datasize);
+    new_node->data = G_malloc(datasize);
     if (new_node->data == NULL)
 	G_fatal_error("RB Search Tree: Out of memory!");
 	

Modified: grass/trunk/lib/vector/diglib/struct_alloc.c
===================================================================
--- grass/trunk/lib/vector/diglib/struct_alloc.c	2009-04-21 16:34:51 UTC (rev 36850)
+++ grass/trunk/lib/vector/diglib/struct_alloc.c	2009-04-21 18:35:07 UTC (rev 36851)
@@ -35,14 +35,12 @@
  ** Allocate array space to add 'add' elements
  */
 
-/* TODO: use G_malloc and friends instead of malloc et al.? */
-
 /* allocate new node structure */
 P_NODE *dig_alloc_node()
 {
     P_NODE *Node;
 
-    Node = (P_NODE *) malloc(sizeof(P_NODE));
+    Node = (P_NODE *) G_malloc(sizeof(P_NODE));
     if (Node == NULL)
         return NULL;
 
@@ -58,11 +56,11 @@
 void dig_free_node(P_NODE *Node)
 {
     if (Node->alloc_lines > 0) {
-        free(Node->lines);
-        free(Node->angles);
+        G_free(Node->lines);
+        G_free(Node->angles);
     }
 
-    free(Node);
+    G_free(Node);
 }
 
 /* dig_node_alloc_line (node, add)
@@ -81,12 +79,12 @@
 
     num = node->n_lines + add;
 
-    p = realloc(node->lines, num * sizeof(plus_t));
+    p = G_realloc(node->lines, num * sizeof(plus_t));
     if (p == NULL)
         return -1;
     node->lines = (plus_t *) p;
 
-    p = realloc(node->angles, num * sizeof(float));
+    p = G_realloc(node->angles, num * sizeof(float));
     if (p == NULL)
         return -1;
     node->angles = (float *)p;
@@ -108,7 +106,7 @@
     char *p;
 
     size = Plus->alloc_nodes + 1 + add;
-    p = realloc(Plus->Node, size * sizeof(P_NODE *));
+    p = G_realloc(Plus->Node, size * sizeof(P_NODE *));
     if (p == NULL)
         return -1;
 
@@ -123,7 +121,7 @@
 {
     P_LINE *Line;
 
-    Line = (P_LINE *) malloc(sizeof(P_LINE));
+    Line = (P_LINE *) G_malloc(sizeof(P_LINE));
     if (Line == NULL)
         return NULL;
 
@@ -133,7 +131,7 @@
 /* free line structure */
 void dig_free_line(P_LINE *Line)
 {
-    free(Line);
+    G_free(Line);
 }
 
 /* Reallocate array of pointers to lines.
@@ -148,7 +146,7 @@
     char *p;
 
     size = Plus->alloc_lines + 1 + add;
-    p = realloc(Plus->Line, size * sizeof(P_LINE *));
+    p = G_realloc(Plus->Line, size * sizeof(P_LINE *));
     if (p == NULL)
         return -1;
 
@@ -170,7 +168,7 @@
     char *p;
 
     size = Plus->alloc_areas + 1 + add;
-    p = realloc(Plus->Area, size * sizeof(P_AREA *));
+    p = G_realloc(Plus->Area, size * sizeof(P_AREA *));
     if (p == NULL)
         return -1;
 
@@ -193,7 +191,7 @@
 
     G_debug(3, "dig_alloc_isle():");
     size = Plus->alloc_isles + 1 + add;
-    p = realloc(Plus->Isle, size * sizeof(P_ISLE *));
+    p = G_realloc(Plus->Isle, size * sizeof(P_ISLE *));
     if (p == NULL)
         return -1;
 
@@ -208,7 +206,7 @@
 {
     P_AREA *Area;
 
-    Area = (P_AREA *) malloc(sizeof(P_AREA));
+    Area = (P_AREA *) G_malloc(sizeof(P_AREA));
     if (Area == NULL)
         return NULL;
 
@@ -234,7 +232,7 @@
     if (Area->alloc_isles > 0)
         free(Area->isles);
 
-    free(Area);
+    G_free(Area);
 }
 
 /* alloc new isle structure */
@@ -242,7 +240,7 @@
 {
     P_ISLE *Isle;
 
-    Isle = (P_ISLE *) malloc(sizeof(P_ISLE));
+    Isle = (P_ISLE *) G_malloc(sizeof(P_ISLE));
     if (Isle == NULL)
         return NULL;
 
@@ -259,9 +257,9 @@
 void dig_free_isle(P_ISLE *Isle)
 {
     if (Isle->alloc_lines > 0)
-        free(Isle->lines);
+        G_free(Isle->lines);
 
-    free(Isle);
+    G_free(Isle);
 }
 
 /* allocate room for  'num'   X and Y  arrays in struct line_pnts 
@@ -345,7 +343,7 @@
 
     num = area->alloc_lines + add;
 
-    p = realloc(area->lines, num * sizeof(plus_t));
+    p = G_realloc(area->lines, num * sizeof(plus_t));
     if (p == NULL)
         return -1;
     area->lines = (plus_t *) p;
@@ -368,7 +366,7 @@
     G_debug(5, "dig_area_alloc_isle(): add = %d", add);
     num = area->alloc_isles + add;
 
-    p = realloc(area->isles, num * sizeof(plus_t));
+    p = G_realloc(area->isles, num * sizeof(plus_t));
     if (p == NULL)
         return -1;
     area->isles = (plus_t *) p;
@@ -391,7 +389,7 @@
     G_debug(3, "dig_isle_alloc_line():");
     num = isle->alloc_lines + add;
 
-    p = realloc(isle->lines, num * sizeof(plus_t));
+    p = G_realloc(isle->lines, num * sizeof(plus_t));
     if (p == NULL)
         return -1;
     isle->lines = (plus_t *) p;



More information about the grass-commit mailing list