Markus Neteler wrote:

> > r.basin map=map@Elevation prefix=o coordinates=-71.10394196,43.9865230801
> > threshold=19005 dir=C:\\Users\\Andrea\\Basins
> >
> > I get:
> > " ....
> > v.to.rast complete.
> > All in RAM calculation...
> > Reading raster map <o_map_drainage_e>...
> > Calculating basins using vector point map...
> > Current region rows: 21612, cols: 21612
> > ERROR: G_calloc: unable to allocate 21612 * 4 bytes of memory at io.c:41
> ...
> 
> Question: is there a way to also communicate in which *command* the
> memory allocation occurred, i.e. improve the error message?

Why should allocation errors be different to any other error?

For the case of scripts, it may suffice to fix run_command() etc so
that they terminate (or raise an exception) if the module returns a
non-zero exit status. If the error message is immedately followed by
"error executing <command>", it should remove most of the ambiguity.

> We have 9 files called "io.c" in GRASS 7.
> Ideal would be something like:
> 
> ERROR: G_calloc: unable to allocate 21612 * 4 bytes of memory at 
> r.thin/io.c:41
> 
> or
> ERROR: r.thin: G_calloc: unable to allocate 21612 * 4 bytes of memory
> at r.thin/io.c:41
> 
> Not sure how to implement that in lib/gis/alloc.c

alloc.c is the wrong place. If you want errors to be traceable, the
module name should be included for *all* errors by G_fatal_error (and
possibly others).

Also, I wouldn't suggest using module/file.c, because that will be
inaccurate (and thus misleading) if the caller is part of a library.

If we just want the complete filename in allocation errors, we can
modify the compiler switches to include $(RELDIR) as per the attached
patch. Similarly for use of __FILE__ in the iostream headers.

-- 
Glynn Clements <[email protected]>

Index: include/Make/Compile.make
===================================================================
--- include/Make/Compile.make   (revision 62377)
+++ include/Make/Compile.make   (working copy)
@@ -20,7 +20,7 @@
 linker_cxx = $(call linker_x,$(CXX))
 linker = $(call linker_x,$(LINK))
 
-ALL_CFLAGS = $(LFS_CFLAGS) $(EXTRA_CFLAGS) $(NLS_CFLAGS) $(DEFS) $(EXTRA_INC) 
$(INC)
+ALL_CFLAGS = $(LFS_CFLAGS) $(EXTRA_CFLAGS) $(NLS_CFLAGS) $(DEFS) $(EXTRA_INC) 
$(INC) -DRELDIR=\"$(RELDIR)\"
 
 compiler_x = $(1) $(2) $(ALL_CFLAGS) -o $@ -c $<
 compiler_c = $(call compiler_x,$(CC),$(COMPILE_FLAGS_C) $($*_c_FLAGS))
Index: include/defs/gis.h
===================================================================
--- include/defs/gis.h  (revision 62377)
+++ include/defs/gis.h  (working copy)
@@ -81,9 +81,9 @@
 #endif
 
 #ifndef CTYPESGEN
-#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))
+#define G_malloc(n)     G__malloc(RELDIR "/" __FILE__, __LINE__, (n))
+#define G_calloc(m, n)  G__calloc(RELDIR "/" __FILE__, __LINE__, (m), (n))
+#define G_realloc(p, n) G__realloc(RELDIR "/" __FILE__, __LINE__, (p), (n))
 #else
 #define G_malloc(n)     G__malloc("<ctypesgen>", 0, (n))
 #define G_calloc(m, n)  G__calloc("<ctypesgen>", 0, (m), (n))
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to