Hi all,
the vector library still uses in GRASS7 GV_FATAL_EXIT/PRINT/RETURN
defines, see Vect_set_fatal_error() for details. It was introduced in
r10426.
I know that this topic "G_fatal_error() and exit() call" has been
discussed several times in the past. The GRASS libraries has been
designed for Unix-like modules, which just starts, do processing and
terminates. This absolutely acceptable reason why G_fatal_error()
should call exit() when fatal_error appears. On the other hand I still
think that the programmer should have some possibility to avoid
calling exit() on G_fatal_error() of course on his/her own risk.
Anyway this option should be there with BIG warning at least but it
should be there...
Please review the attach patch which moves Vect_*_fatal_error() to the gislib.
Martin
[1]
http://trac.osgeo.org/grass/changeset/10426/grass/trunk/lib/vector/Vlib/error.c
--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa
Index: lib/gis/error.c
===================================================================
--- lib/gis/error.c (revision 49164)
+++ lib/gis/error.c (working copy)
@@ -45,6 +45,7 @@
static int (*ext_error) (const char *, int); /* Roger Bivand 17 June 2000 */
static int no_warn = 0;
static int no_sleep = 1;
+static int fatal_err = FATAL_EXIT;
static int grass_info_format;
static char *logfile;
@@ -149,10 +150,10 @@
static int busy;
va_list ap;
- if (busy)
+ if (busy && fatal_err == FATAL_EXIT)
exit(EXIT_FAILURE);
busy = 1;
-
+
va_start(ap, msg);
vfprint_error(ERR, msg, ap);
va_end(ap);
@@ -166,7 +167,8 @@
if (getenv("GRASS_SIGSEGV_ON_ERROR"))
raise(SIGSEGV);
- exit(EXIT_FAILURE);
+ if (fatal_err == FATAL_EXIT)
+ exit(EXIT_FAILURE);
}
/*!
@@ -515,3 +517,34 @@
return grass_info_format;
}
+
+/*!
+ \brief Set behaviour if fatal error occurs in some functions
+
+ FATAL_EXIT causes that G_fatal_error() calls exit(). This is DEFAULT
+ behaviour and highly recommended approach when using GRASS
+ libraries. The GRASS libraries have been designed to support the
+ creation of such GRASS Unix-style modules, which read command-line
+ arguments, do processing, terminated.
+
+ FATAL_RETURN avoids calling exit() on G_fatal_error(). WARNING: This
+ causes that GRASS libraries will remain in undefined state. Use this
+ option when you really know what you are doing.
+
+ \param fatal FATAL_EXIT or FATAL_RETURN
+*/
+void G_set_fatal_error(int fatal)
+{
+ fatal_err = fatal == FATAL_RETURN ? FATAL_RETURN : FATAL_EXIT;
+}
+
+/*!
+ \brief Get behaviour for fatal error
+
+ \return FATAL_EXIT call exit() on G_fatal_error()
+ \return FATAL_RETURN don't call exit() just return
+ */
+int G_get_fatal_error()
+{
+ return fatal_err;
+}
Index: include/gis.h
===================================================================
--- include/gis.h (revision 49164)
+++ include/gis.h (working copy)
@@ -61,6 +61,9 @@
#define NEWLINE '\n'
+#define FATAL_EXIT 0
+#define FATAL_RETURN 1
+
/*!
\brief List of units
*/
Index: include/gisdefs.h
===================================================================
--- include/gisdefs.h (revision 49164)
+++ include/gisdefs.h (working copy)
@@ -215,6 +215,8 @@
void G_set_error_routine(int (*)(const char *, int));
void G_unset_error_routine(void);
void G_init_logging(void);
+void G_set_fatal_error(int);
+int G_get_fatal_error();
/* file_name.c */
char *G_file_name(char *, const char *, const char *, const char *);
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev