[GRASS-SVN] r34196 - in grass/branches/develbranch_6: include
lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Nov 8 11:42:32 EST 2008
Author: neteler
Date: 2008-11-08 11:42:32 -0500 (Sat, 08 Nov 2008)
New Revision: 34196
Modified:
grass/branches/develbranch_6/include/gisdefs.h
grass/branches/develbranch_6/lib/gis/alloc.c
Log:
glynn: Macro-ise G_*alloc() functions (to allow calling function to be identified in case of error) (merge from trunk, r34193)
Modified: grass/branches/develbranch_6/include/gisdefs.h
===================================================================
--- grass/branches/develbranch_6/include/gisdefs.h 2008-11-08 15:26:35 UTC (rev 34195)
+++ grass/branches/develbranch_6/include/gisdefs.h 2008-11-08 16:42:32 UTC (rev 34196)
@@ -39,11 +39,15 @@
char *G_align_window(struct Cell_head *, const struct Cell_head *);
/* alloc.c */
-void *G_malloc(size_t);
-void *G_calloc(size_t, size_t);
-void *G_realloc(void *, size_t);
+void *G__malloc(const char *, int, size_t);
+void *G__calloc(const char *, int, size_t, size_t);
+void *G__realloc(const char *, int, void *, size_t);
void G_free(void *);
+#define G_malloc(n) G__malloc(__FILE__, __LINE__, (n))
+#define G_calloc(m, n) G__calloc(__FILE__, __LINE__, (m), (n))
+#define G_realloc(p, n) G__realloc(__FILE__, __LINE__, (p), (n))
+
/* alloc_cell.c */
size_t G_raster_size(RASTER_MAP_TYPE);
CELL *G_allocate_cell_buf(void);
Modified: grass/branches/develbranch_6/lib/gis/alloc.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/alloc.c 2008-11-08 15:26:35 UTC (rev 34195)
+++ grass/branches/develbranch_6/lib/gis/alloc.c 2008-11-08 16:42:32 UTC (rev 34196)
@@ -31,22 +31,21 @@
* \return void *
*/
-void *G_malloc(size_t n)
+void *G__malloc(const char *file, int line, size_t n)
{
void *buf;
-
+
if (n <= 0)
n = 1; /* make sure we get a valid request */
-
+
buf = malloc(n);
- if (buf)
- return buf;
+ if (!buf)
+ G_fatal_error(_("G_malloc: unable to allocate %lu bytes at %s:%d"),
+ (unsigned long) n, file, line);
- G_fatal_error(_("G_malloc: out of memory"));
- return NULL;
+ return buf;
}
-
/**
* \brief Memory allocation.
*
@@ -63,7 +62,7 @@
* \return void *
*/
-void *G_calloc(size_t m, size_t n)
+void *G__calloc(const char *file, int line, size_t m, size_t n)
{
void *buf;
@@ -73,11 +72,11 @@
n = 1;
buf = calloc(m, n);
- if (buf)
- return buf;
+ if (!buf)
+ G_fatal_error(_("G_calloc: unable to allocate %lu * %lu bytes at %s:%d"),
+ (unsigned long) m, (unsigned long) n, file, line);
- G_fatal_error(_("G_calloc: out of memory"));
- return NULL;
+ return buf;
}
@@ -101,7 +100,7 @@
* \return void *
*/
-void *G_realloc(void *buf, size_t n)
+void *G__realloc(const char *file, int line, void *buf, size_t n)
{
if (n <= 0)
n = 1; /* make sure we get a valid request */
@@ -111,11 +110,11 @@
else
buf = realloc(buf, n);
- if (buf)
- return buf;
+ if (!buf)
+ G_fatal_error(_("G_realloc: unable to allocate %lu bytes at %s:%d"),
+ (unsigned long) n, file, line);
- G_fatal_error(_("G_realloc: out of memory"));
- return NULL;
+ return buf;
}
More information about the grass-commit
mailing list