[GRASS-SVN] r66048 - in grass/trunk: include/defs lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 27 06:22:32 PDT 2015
Author: huhabla
Date: 2015-08-27 06:22:31 -0700 (Thu, 27 Aug 2015)
New Revision: 66048
Modified:
grass/trunk/include/defs/vector.h
grass/trunk/lib/vector/Vlib/map.c
Log:
vector library: Patch from Radim, enhancement request #2729, to allow Map_info struct allocation and deletion
Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h 2015-08-27 13:11:15 UTC (rev 66047)
+++ grass/trunk/include/defs/vector.h 2015-08-27 13:22:31 UTC (rev 66048)
@@ -159,6 +159,9 @@
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 *);
Modified: grass/trunk/lib/vector/Vlib/map.c
===================================================================
--- grass/trunk/lib/vector/Vlib/map.c 2015-08-27 13:11:15 UTC (rev 66047)
+++ grass/trunk/lib/vector/Vlib/map.c 2015-08-27 13:22:31 UTC (rev 66048)
@@ -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
More information about the grass-commit
mailing list