From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
To: libc-alpha@sourceware.org
Subject: [PATCH 07/13] string: Use tls-internal on strerror_l
Date: Tue, 19 May 2020 15:05:12 -0300 [thread overview]
Message-ID: <20200519180518.318733-8-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20200519180518.318733-1-adhemerval.zanella@linaro.org>
The buffer allocation uses the same strategy of strsignal.
Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
and s390x-linux-gnu.
---
string/strerror_l.c | 16 +++++++--------
sysdeps/generic/tls-internal-struct.h | 1 +
sysdeps/mach/strerror_l.c | 28 +++++++++++++--------------
3 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/string/strerror_l.c b/string/strerror_l.c
index cb656b5d54..dcbf605560 100644
--- a/string/strerror_l.c
+++ b/string/strerror_l.c
@@ -18,11 +18,8 @@
#include <libintl.h>
#include <locale.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-
-static __thread char *last_value;
+#include <tls-internal.h>
static const char *
@@ -45,12 +42,13 @@ __strerror_l (int errnum, locale_t loc)
if (__glibc_unlikely (errnum < 0 || errnum >= _sys_nerr_internal
|| _sys_errlist_internal[errnum] == NULL))
{
- free (last_value);
- if (__asprintf (&last_value, "%s%d",
+ struct tls_internal_t *tls_internal = __glibc_tls_internal ();
+ free (tls_internal->strerror_l_buf);
+ if (__asprintf (&tls_internal->strerror_l_buf, "%s%d",
translate ("Unknown error ", loc), errnum) == -1)
- last_value = NULL;
+ tls_internal->strerror_l_buf = NULL;
- r = last_value;
+ r = tls_internal->strerror_l_buf;
}
else
r = (char *) translate (_sys_errlist_internal[errnum], loc);
@@ -64,6 +62,6 @@ libc_hidden_def (__strerror_l)
void
__strerror_thread_freeres (void)
{
- free (last_value);
+ free (__glibc_tls_internal ()->strerror_l_buf);
}
text_set_element (__libc_subfreeres, __strerror_thread_freeres);
diff --git a/sysdeps/generic/tls-internal-struct.h b/sysdeps/generic/tls-internal-struct.h
index 33a9079ee9..156e722bd8 100644
--- a/sysdeps/generic/tls-internal-struct.h
+++ b/sysdeps/generic/tls-internal-struct.h
@@ -22,6 +22,7 @@
struct tls_internal_t
{
char *strsignal_buf;
+ char *strerror_l_buf;
};
#endif
diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c
index b6c9fdbe80..1e97496e77 100644
--- a/sysdeps/mach/strerror_l.c
+++ b/sysdeps/mach/strerror_l.c
@@ -23,11 +23,7 @@
#include <string.h>
#include <mach/error.h>
#include <errorlib.h>
-#include <sys/param.h>
-#include <libc-symbols.h>
-
-
-static __thread char *last_value;
+#include <tls-internal.h>
static const char *
@@ -58,13 +54,14 @@ __strerror_l (int errnum, locale_t loc)
if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
{
- free (last_value);
- if (__asprintf (&last_value, "%s%X",
+ struct tls_internal_t *tls_internal = __glibc_tls_internal ();
+ free (tls_internal->strerror_l_buf);
+ if (__asprintf (&tls_internal->strerror_l_buf, "%s%X",
translate ("Error in unknown error system: ", loc),
errnum) == -1)
- last_value = NULL;
+ tls_internal->strerror_l_buf = NULL;
- return last_value;
+ return tls_internal->strerror_l_buf;
}
es = &__mach_error_systems[system];
@@ -74,14 +71,15 @@ __strerror_l (int errnum, locale_t loc)
if (code >= es->subsystem[sub].max_code)
{
- free (last_value);
- if (__asprintf (&last_value, "%s%s %d",
+ struct tls_internal_t *tls_internal = __glibc_tls_internal ();
+ free (tls_internal->strerror_l_buf);
+ if (__asprintf (&tls_internal->strerror_l_buf, "%s%s %d",
translate ("Unknown error ", loc),
translate (es->subsystem[sub].subsys_name, loc),
errnum) == -1)
- last_value = NULL;
+ tls_internal->strerror_l_buf = NULL;
- return last_value;
+ return tls_internal->strerror_l_buf;
}
return (char *) translate (es->subsystem[sub].codes[code], loc);
@@ -89,10 +87,10 @@ __strerror_l (int errnum, locale_t loc)
weak_alias (__strerror_l, strerror_l)
libc_hidden_def (__strerror_l)
-/* This is called when a thread is exiting to free the last_value string. */
+/* This is called when a thread is exiting to free the allocated string. */
void
__strerror_thread_freeres (void)
{
- free (last_value);
+ free (__glibc_tls_internal ()->strerror_l_buf);
}
text_set_element (__libc_subfreeres, __strerror_thread_freeres);
--
2.25.1
next prev parent reply other threads:[~2020-05-19 18:06 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 18:05 [PATCH 00/13] Signal and error list refactoring Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH v2 01/13] signal: Add signum-{generic,arch}.h Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH v3 02/13] signal: Move sys_siglist to a compat symbol Adhemerval Zanella via Libc-alpha
2020-05-28 14:50 ` Florian Weimer via Libc-alpha
2020-05-19 18:05 ` [PATCH v3 03/13] signal: Move sys_errlist " Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH 04/13] linux: Fix __NSIG_WORDS and add __NSIG_BYTES Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH 05/13] string: Remove old TLS usage on strsignal Adhemerval Zanella via Libc-alpha
2020-05-28 11:38 ` Florian Weimer via Libc-alpha
2020-06-01 18:08 ` Adhemerval Zanella via Libc-alpha
2020-06-01 18:13 ` Florian Weimer
2020-06-01 18:39 ` Adhemerval Zanella via Libc-alpha
2020-06-01 18:43 ` Florian Weimer
2020-05-19 18:05 ` [PATCH 06/13] string: Implement strerror in terms of strerror_l Adhemerval Zanella via Libc-alpha
2020-05-28 11:41 ` Florian Weimer via Libc-alpha
2020-06-01 18:28 ` Adhemerval Zanella via Libc-alpha
2020-06-03 8:24 ` Florian Weimer via Libc-alpha
2020-06-03 15:13 ` Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` Adhemerval Zanella via Libc-alpha [this message]
2020-05-19 18:05 ` [PATCH 08/13] string: Simplify strerror_r Adhemerval Zanella via Libc-alpha
2020-05-28 11:56 ` Florian Weimer via Libc-alpha
2020-06-01 18:31 ` Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH 09/13] string: Add strsignal test Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH 10/13] string: Add strerror, strerror_r, and strerror_l test Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH 11/13] string: Add strerror_l on test-strerror-errno Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH 12/13] string: Add sigabbrev_np and sigdescr_np Adhemerval Zanella via Libc-alpha
2020-05-19 18:47 ` Joseph Myers
2020-05-28 12:31 ` Florian Weimer via Libc-alpha
2020-06-03 16:39 ` Adhemerval Zanella via Libc-alpha
2020-05-19 18:05 ` [PATCH 13/13] string: Add errname_np and errdesc_np Adhemerval Zanella via Libc-alpha
2020-05-28 12:28 ` Florian Weimer via Libc-alpha
2020-06-01 20:52 ` Adhemerval Zanella via Libc-alpha
2020-06-02 17:13 ` Adhemerval Zanella via Libc-alpha
2020-06-02 17:19 ` Florian Weimer via Libc-alpha
2020-06-02 17:20 ` Adhemerval Zanella via Libc-alpha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200519180518.318733-8-adhemerval.zanella@linaro.org \
--to=libc-alpha@sourceware.org \
--cc=adhemerval.zanella@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).