]> Savannah Git Hosting - gnulib.git/commitdiff
fstrcmp: Add API to clean up resources.
authorBruno Haible <bruno@clisp.org>
Sun, 16 Feb 2020 12:49:49 +0000 (13:49 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 16 Feb 2020 12:49:49 +0000 (13:49 +0100)
Reported by Akim Demaille <akim@lrde.epita.fr> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-01/msg00080.html>.

* lib/fstrcmp.h (fstrcmp_free_resources): New declaration.
* lib/fstrcmp.c (fstrcmp_free_resources): New function.

ChangeLog
lib/fstrcmp.c
lib/fstrcmp.h

index dfaf6cc9235fae5b7c1ce4cfa4d69b44cd050b48..288bae705f32a68bcbaf897aea003876ee13b1f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-02-16  Bruno Haible  <bruno@clisp.org>
+
+       fstrcmp: Add API to clean up resources.
+       Reported by Akim Demaille <akim@lrde.epita.fr> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-01/msg00080.html>.
+       * lib/fstrcmp.h (fstrcmp_free_resources): New declaration.
+       * lib/fstrcmp.c (fstrcmp_free_resources): New function.
+
 2020-02-14  Bruno Haible  <bruno@clisp.org>
 
        wctype-h: Fix compilation errors in C++ (regression from 2020-01-25).
index c6a66389e33641e0ddfa722d99df12b5eb1deb74..1a4fbfdf8de625323aeb7734e224be0496567993 100644 (file)
@@ -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
index 92b67e34a3b5b0546220b75684fbd0697bee2e0e..37df588a3edc3925787d27fca591ebb8df71f441 100644 (file)
@@ -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