bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

strsignal on mingw


From: Eric Blake
Subject: strsignal on mingw
Date: Tue, 17 Jun 2008 22:10:58 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I was experimenting with the strsignal module on mingw, and have several 
questions.

The strsignal module is rather heavy-handed when used for a single-threaded 
app, since thread-local storage is not really necessary in that case.  What is 
the recommended way to git a single-thread-friendly strsignal?  Maybe it is 
worth creating a strsignal-simple module that avoids pulling in lock and tls?  
Or is it as simple as using './gnulib-tool --avoid lock'?


Can we relicense the tls module to be LGPLv2+?  I'm seeing this:
$ CC='gcc -mno-cygwin' CFLAGS='-gdwarf-2 -Wall -Werror' ./gnulib-tool --with-
tests --test strsignal
warning: module strsignal depends on a module with an incompatible license: tls


The mingw headers for <windows.h> currently have a bug, where Interlocked{In,De}
crement are defined as taking LPLONG (long *) rather than the Microsoft 
documentation [1] of LONG volatile *, triggering compiler warnings when passing 
in a pointer to volatile data.  Is it acceptable to add macros to lock.h to 
work around this mingw deficiency when USE_WIN32_THREADS?

[1] http://msdn.microsoft.com/en-us/library/ms683614(VS.85).aspx

../../lib/lock.c: In function `glthread_lock_lock':
../../lib/lock.c:550: warning: passing arg 1 of `InterlockedIncrement' discards 
qualifiers from pointer target type
../../lib/lock.c: In function `glthread_rwlock_rdlock':
../../lib/lock.c:682: warning: passing arg 1 of `InterlockedIncrement' discards 
qualifiers from pointer target type
../../lib/lock.c: In function `glthread_rwlock_wrlock':
../../lib/lock.c:735: warning: passing arg 1 of `InterlockedIncrement' discards 
qualifiers from pointer target type
../../lib/lock.c: In function `glthread_recursive_lock_lock':
../../lib/lock.c:853: warning: passing arg 1 of `InterlockedIncrement' discards 
qualifiers from pointer target type
../../lib/lock.c: In function `glthread_once':
../../lib/lock.c:904: warning: passing arg 1 of `InterlockedIncrement' discards 
qualifiers from pointer target type
../../lib/lock.c:917: warning: passing arg 1 of `InterlockedDecrement' discards 
qualifiers from pointer target type


Even though the destructor is unused in mingw and single-threaded cases, can we 
at least evaluate it to avoid this warning?

../../gllib/strsignal.c:165: warning: 'free_key_mem' defined but not used


Here's my proposed patch for the last two issues; okay to apply?

>From d3355f4de34fb238be1c19881098a3db7b5a8383 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 17 Jun 2008 16:06:23 -0600
Subject: [PATCH] Avoid compiler warnings on mingw.

* lib/tls.h (gl_tls_key_init) [USE_WIN32_THREADS, !threads]:
Evaluate the otherwise unused argument.
* lib/lock.h (InterlockedIncrement, InterlockedDecrement)
[USE_WIN32_THREADS]: Cast away volatile.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog  |    6 ++++++
 lib/lock.h |    5 +++++
 lib/tls.h  |    5 +++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 83af7de..35b5e44 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-06-17  Eric Blake  <address@hidden>
 
+       Avoid compiler warnings on mingw.
+       * lib/tls.h (gl_tls_key_init) [USE_WIN32_THREADS, !threads]:
+       Evaluate the otherwise unused argument.
+       * lib/lock.h (InterlockedIncrement, InterlockedDecrement)
+       [USE_WIN32_THREADS]: Cast away volatile.
+
        Simplify c-stack prerequisites.
        * lib/c-stack.c (includes): Remove unused <sys/resource.h>.
        * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Posix 200x
diff --git a/lib/lock.h b/lib/lock.h
index 32a35bb..c88c2ce 100644
--- a/lib/lock.h
+++ b/lib/lock.h
@@ -905,6 +905,11 @@ extern int glthread_once_singlethreaded (gl_once_t 
*once_control);
 
 # include <windows.h>
 
+/* Work around bug in mingw headers that neglects to use volatile in
+   the prototypes, by casting away volatile.  */
+#define InterlockedIncrement(p) (InterlockedIncrement) ((LPLONG) p)
+#define InterlockedDecrement(p) (InterlockedDecrement) ((LPLONG) p)
+
 # ifdef __cplusplus
 extern "C" {
 # endif
diff --git a/lib/tls.h b/lib/tls.h
index 09faade..97a13bc 100644
--- a/lib/tls.h
+++ b/lib/tls.h
@@ -1,5 +1,5 @@
 /* Thread-local storage in multithreaded situations.
-   Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -285,6 +285,7 @@ typedef DWORD gl_tls_key_t;
       {                                          \
         if (((NAME) = TlsAlloc ()) == (DWORD)-1) \
           abort ();                              \
+        (void) (DESTRUCTOR);                     \
       }                                          \
     while (0)
 # define gl_tls_get(NAME) \
@@ -320,7 +321,7 @@ typedef struct
         }
         gl_tls_key_t;
 # define gl_tls_key_init(NAME, DESTRUCTOR) \
-    (NAME).singlethread_value = NULL
+    ((void) (DESTRUCTOR), (NAME).singlethread_value = NULL)
 # define gl_tls_get(NAME) \
     (NAME).singlethread_value
 # define gl_tls_set(NAME, POINTER) \
-- 
1.5.5.1








reply via email to

[Prev in Thread] Current Thread [Next in Thread]