From: Bruno Haible Date: Sun, 16 Feb 2020 12:49:49 +0000 (+0100) Subject: fstrcmp: Add API to clean up resources. X-Git-Tag: v1.0~4248 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=b5ba60c50b5c0e510e06d5f8137a922ba4895b17;p=gnulib.git fstrcmp: Add API to clean up resources. Reported by Akim Demaille in . * lib/fstrcmp.h (fstrcmp_free_resources): New declaration. * lib/fstrcmp.c (fstrcmp_free_resources): New function. --- diff --git a/ChangeLog b/ChangeLog index dfaf6cc923..288bae705f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2020-02-16 Bruno Haible + + fstrcmp: Add API to clean up resources. + Reported by Akim Demaille in + . + * lib/fstrcmp.h (fstrcmp_free_resources): New declaration. + * lib/fstrcmp.c (fstrcmp_free_resources): New function. + 2020-02-14 Bruno Haible wctype-h: Fix compilation errors in C++ (regression from 2020-01-25). diff --git a/lib/fstrcmp.c b/lib/fstrcmp.c index c6a66389e3..1a4fbfdf8d 100644 --- a/lib/fstrcmp.c +++ b/lib/fstrcmp.c @@ -73,6 +73,21 @@ keys_init (void) /* Ensure that keys_init is called once only. */ gl_once_define(static, keys_init_once) +void +fstrcmp_free_resources (void) +{ + ptrdiff_t *buffer; + + gl_once (keys_init_once, keys_init); + buffer = gl_tls_get (buffer_key); + if (buffer != NULL) + { + gl_tls_set (buffer_key, NULL); + gl_tls_set (bufmax_key, (void *) (uintptr_t) 0); + free (buffer); + } +} + /* In the code below, branch probabilities were measured by Ralf Wildenhues, by running "msgmerge LL.po coreutils.pot" with msgmerge 0.18 for many diff --git a/lib/fstrcmp.h b/lib/fstrcmp.h index 92b67e34a3..37df588a3e 100644 --- a/lib/fstrcmp.h +++ b/lib/fstrcmp.h @@ -38,6 +38,15 @@ extern double fstrcmp_bounded (const char *s1, const char *s2, /* A shortcut for fstrcmp. Avoids a function call. */ #define fstrcmp(s1,s2) fstrcmp_bounded (s1, s2, 0.0) +/* Frees the per-thread resources allocated by this module for the current + thread. + You don't need to call this function in threads other than the main thread, + because per-thread resources are reclaimed automatically when the thread + exits. However, per-thread resources allocated by the main thread are + comparable to static allocations; calling this function can be useful to + avoid an error report from valgrind. */ +extern void fstrcmp_free_resources (void); + #ifdef __cplusplus } #endif