Przeglądaj źródła

vector library: Patch from Radim, enhancement request https://trac.osgeo.org/grass/ticket/2729, to allow Map_info struct allocation and deletion

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@66048 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 9 lat temu
rodzic
commit
f1c7da4b2e
2 zmienionych plików z 38 dodań i 0 usunięć
  1. 3 0
      include/defs/vector.h
  2. 35 0
      lib/vector/Vlib/map.c

+ 3 - 0
include/defs/vector.h

@@ -159,6 +159,9 @@ int Vect_cidx_dump(const struct Map_info *, FILE *);
 int Vect_cidx_save(struct Map_info *);
 int Vect_cidx_open(struct Map_info *, int);
 
+/* Create/destroy Map_info */
+struct Map_info *Vect_new_map_struct(void);
+void Vect_destroy_map_struct(struct Map_info *);
 
 /* Set/get map header info */
 int Vect_read_header(struct Map_info *);

+ 35 - 0
lib/vector/Vlib/map.c

@@ -32,6 +32,41 @@
 #include "local_proto.h"
 
 /*!
+   \brief Creates and initializes Map_info structure
+
+  To free allocated memory call Vect_destroy_map_struct().
+
+   \return pointer to Map_info 
+ */
+struct Map_info *Vect_new_map_struct(void)
+{
+    struct Map_info *p;
+
+    p = (struct Map_info *)malloc(sizeof(struct Map_info)); 
+
+    if (NULL == p)
+      G_fatal_error("Vect_new_map_struct(): %s", _("Out of memory"));
+
+    G_zero(p, sizeof(struct Map_info));
+
+    return p;
+}
+
+/*!
+   \brief Frees all memory associated with a Map_info structure,
+   including the structure itself
+
+   \param p pointer to Map_info structure
+ */
+void Vect_destroy_map_struct(struct Map_info *p)
+{
+   /* We should free all allocated member structures, but they may be already 
+      freed by other functions (e.g. Vect_close()) without resetting member pointers to zero */
+
+   G_free((char *)p);
+}
+
+/*!
    \brief Copy file
 
    \param src source file