[Qgis-developer] [GRASS-dev] GRASS & QGIS: the future
Martin Landa
landa.martin at gmail.com
Sat Apr 19 04:03:31 PDT 2014
2014-04-19 0:59 GMT+02:00 Glynn Clements <glynn at gclements.plus.com>:
[...]
> You're misunderstanding a key point.
"Misunderstanding" is usually a question of the point of view or level
of "doggedness". Especially when someone is speaking about "a key
point" ;-)
> Returning from G_fatal_error() won't leave GRASS libraries in an
> unpredictable state. It's "escaping" from G_fatal_error() via e.g.
> Returning from G_fatal_error() will typically result in a
> (more-or-less immediate) segfault when the caller tries to use data
> structures which contain garbage (because the callee never initialised
> them, but raised a fatal error instead).
Well, and what do you think that I meant by "unpredictable state"?
> The simplest example is G__malloc():
>
> buf = malloc(n);
> if (!buf) {
>
> ...
>
> G_fatal_error(_("G_malloc: unable to allocate %lu bytes of memory at %s:%d"),
> (unsigned long) n, file, line);
> }
>
> return buf;
>
> If malloc() returns NULL and the subsequent G_fatal_error() call
> returns, G__malloc() will return NULL to its caller. Which will
> segfault as soon as it tries to store something in the "allocated"
> memory.
You chose very specific case of course. There is probably something
you don't want to understand. In the core libraries (gis, vector,
raster, imagery) there are 553(!) places where G_fatal_error() is
called. Some time ago you introduced G_fatal_error() even to the
function which tries to open raster map [1]. So if the raster map
doesn't exists the function is calling exit()! This is something which
makes life harder for anyone who want to use GRASS libraries (as you
already mentioned) with one exception - modules - standalone programs,
where you don't need to specify `if` statement. You can hardly explain
to someone that our libraries call fatal exit even when raster map is
not found. Yes, you can if don't want to change your opinion
regardless any input from outside world. For such cases, like opening
raster map would G_set_fatal_error() simply make sense.
> It achieves this by calling exit() (or optionally raising SIGSEGV; why
> it didn't use SIGABRT, I have no idea). Calling longjmp() would work.
> If it was C++, raising an exception would work. Returning will *not*
> work.
[...]
Martin
[1] http://trac.osgeo.org/grass/changeset/40209/grass/trunk/lib/raster/opencell.c
--
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa
More information about the Qgis-developer
mailing list