diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2015-09-02 17:51:40 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2015-09-02 17:51:40 +0300 |
commit | 1b0b9fcb928042bf30fb2e42247912d226f85513 (patch) | |
tree | 10abb98957304dbdbbb310cad62b7d3c654bb167 /libgfortran/runtime/string.c | |
parent | 710465235b06be5b74b7fda1c8e2092b43d83e01 (diff) | |
download | gcc-1b0b9fcb928042bf30fb2e42247912d226f85513.zip gcc-1b0b9fcb928042bf30fb2e42247912d226f85513.tar.gz gcc-1b0b9fcb928042bf30fb2e42247912d226f85513.tar.bz2 |
PR 67414 Better diagnostics on backtrace failure, gf_strerror bugfix
2015-09-02 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/67414
* io/write.c (gfc_itoa): Move to runtime/string.c.
* libgfortran.h (show_backtrace): Make arg bool.
(gfc_itoa): New prototype.
* runtime/backtrace.c (struct mystate): Change type of try_simple
field, add in_signal_handler field.
(error_callback): Print out error number, or if not in a signal
handler, the error message.
(show_backtrace): Change type of arg, change initialization of
struct mystate.
(backtrace): Call show_backtrace with correct arg type.
* runtime/compile_options.c (backtrace_handler): Call with correct
arg type.
* runtime/error.c (sys_abort): Likewise.
(gf_strerror): Handle newlocale() failure.
* runtime/string.c (gfc_itoa): Function moved here from
io/write.c.
From-SVN: r227404
Diffstat (limited to 'libgfortran/runtime/string.c')
-rw-r--r-- | libgfortran/runtime/string.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/libgfortran/runtime/string.c b/libgfortran/runtime/string.c index 3c339da..5bd0f61 100644 --- a/libgfortran/runtime/string.c +++ b/libgfortran/runtime/string.c @@ -1,7 +1,7 @@ /* Copyright (C) 2002-2015 Free Software Foundation, Inc. Contributed by Paul Brook -This file is part of the GNU Fortran 95 runtime library (libgfortran). +This file is part of the GNU Fortran runtime library (libgfortran). Libgfortran is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -167,3 +167,48 @@ find_option (st_parameter_common *cmp, const char *s1, gfc_charlen_type s1_len, return -1; } + + +/* gfc_itoa()-- Integer to decimal conversion. + The itoa function is a widespread non-standard extension to + standard C, often declared in <stdlib.h>. Even though the itoa + defined here is a static function we take care not to conflict with + any prior non-static declaration. Hence the 'gfc_' prefix, which + is normally reserved for functions with external linkage. Notably, + in contrast to the *printf() family of functions, this ought to be + async-signal-safe. */ + +const char * +gfc_itoa (GFC_INTEGER_LARGEST n, char *buffer, size_t len) +{ + int negative; + char *p; + GFC_UINTEGER_LARGEST t; + + if (len < GFC_ITOA_BUF_SIZE) + sys_abort (); + + if (n == 0) + return "0"; + + negative = 0; + t = n; + if (n < 0) + { + negative = 1; + t = -n; /*must use unsigned to protect from overflow*/ + } + + p = buffer + GFC_ITOA_BUF_SIZE - 1; + *p = '\0'; + + while (t != 0) + { + *--p = '0' + (t % 10); + t /= 10; + } + + if (negative) + *--p = '-'; + return p; +} |