This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: verbose terminate() on by default
On Mon, Dec 23, 2002 at 08:41:36PM +0100, Gabriel Dos Reis wrote:
> Daniel Jacobowitz <drow@mvista.com> writes:
>
> | Step back... Phil, your most recent patch just changed eh_terminate.cc,
> | if I'm looking at the right message. That's in libsupc++. But
> | verbose_terminate is in libstdc++. I see a problem there; libsupc++
> | should not have link dependency on libstdc++, that defeats the point,
> | doesn't it?
>
> Good catch!
>
> But src/cterminate.cc should have been put in libsupc++/ in the first
> place.
I agree. I wonder why nobody noticed this last year.
> It currenlty uses:
>
> * free() // to free the storage allocated by the demangler
> * abort() // which is already used in libsupc++
I'm not worried about either of those. The routine used to deallocate
memory will probably have to be generalized if we start using Carlo's
less-buggy demangler.
> * fprintf() // which might be effcienly replaced by write() or puts().
Replacing it with fputs() still brings in the stdio library. Although I
think that it would still be an improvement, since it doesn't do string
interpretation and wouldn't (in theory) pull in as much stuff as fprtinf(),
assuming a well-divisioned stdio library.
Replacing it with write() would be a bad step, I think. Now we have
multiple system calls, instead of a single one done after formatting.
Unless we want to format the string into a buffer ourselves before calling
write() once... at which point we're back to using fprintf.
Here's what it looks like:
Index: src/vterminate.cc
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/src/vterminate.cc,v
retrieving revision 1.7
diff -u -3 -r1.7 vterminate.cc
--- src/vterminate.cc 18 Dec 2002 16:31:35 -0000 1.7
+++ src/vterminate.cc 24 Dec 2002 00:14:23 -0000
@@ -36,6 +36,8 @@
using namespace std;
using namespace abi;
+#define errwrite(s) write(2,s,strlen(s))
+
namespace __gnu_cxx
{
/* A replacement for the standard terminate_handler which prints
@@ -57,8 +59,12 @@
dem = __cxa_demangle(name, 0, 0, &status);
- fprintf(stderr, "terminate called after throwing a `%s'\n",
- status == 0 ? dem : name);
+ errwrite("terminate called after throwing a `");
+ if (status == 0)
+ errwrite(dem);
+ else
+ errwrite(name);
+ errwrite("'\n");
if (status == 0)
free(dem);
@@ -69,12 +75,17 @@
try { __throw_exception_again; }
#ifdef __EXCEPTIONS
catch (exception &exc)
- { fprintf(stderr, " what(): %s\n", exc.what()); }
+ {
+ char const *w = exc.what();
+ errwrite(" what(): ");
+ errwrite(w);
+ errwrite("\n");
+ }
#endif
catch (...) { }
}
else
- fprintf(stderr, "terminate called without an active exception\n");
+ errwrite("terminate called without an active exception\n");
abort();
}