Harmonize generic stdio-lock support with nptl
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 22 Dec 2015 13:39:19 +0000 (14:39 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 22 Dec 2015 13:39:19 +0000 (14:39 +0100)
This fixes build when _IO_funlockfile is a macro, fixes build where
_IO_acquire_lock_clear_flags2 is used, and fixes unlocking on unexpected
stack unwind.

* sysdeps/generic/stdio-lock.h [__EXCEPTIONS] (_IO_acquire_lock,
_IO_release_lock ): Use cleanup attribute on new
_IO_acquire_lock_file variable instead of assuming that
_IO_release_lock will be called.
[!__EXCEPTIONS] (_IO_acquire_lock): Define to non-existing
_IO_acquire_lock_needs_exceptions_enabled.
(_IO_acquire_lock_clear_flags2): New macro.

ChangeLog
sysdeps/generic/stdio-lock.h

index 3c15a055d44aaa1e1111eda339f5939e418da189..a57db54b469622ed89c167d849ef1217bca938f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2015-12-22  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+       Harmonize generic stdio-lock support with nptl
+
+       This fixes build when _IO_funlockfile is a macro, fixes build where
+       _IO_acquire_lock_clear_flags2 is used, and fixes unlocking on unexpected
+       stack unwind.
+
+       * sysdeps/generic/stdio-lock.h [__EXCEPTIONS] (_IO_acquire_lock,
+       _IO_release_lock ): Use cleanup attribute on new
+       _IO_acquire_lock_file variable instead of assuming that
+       _IO_release_lock will be called.
+       [!__EXCEPTIONS] (_IO_acquire_lock): Define to non-existing
+       _IO_acquire_lock_needs_exceptions_enabled.
+       (_IO_acquire_lock_clear_flags2): New macro.
+
 2015-12-22  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        * sysdeps/powerpc/fpu/libm-test-ulps: Regenerated.
index 38f93efce9cd2f41d18c1aec00b3e203793b591d..5f232f99a9cc59487477ec4f5f6027c98f5e05e2 100644 (file)
@@ -45,13 +45,26 @@ __libc_lock_define_recursive (typedef, _IO_lock_t)
   __libc_cleanup_region_end (_doit)
 
 #if defined _LIBC && IS_IN (libc)
+
+# ifdef __EXCEPTIONS
 # define _IO_acquire_lock(_fp) \
-  _IO_cleanup_region_start ((void (*) (void *)) _IO_funlockfile, (_fp));      \
-  _IO_flockfile (_fp)
+  do {                                                                       \
+    _IO_FILE *_IO_acquire_lock_file                                          \
+       __attribute__((cleanup (_IO_acquire_lock_fct)))                       \
+       = (_fp);                                                              \
+    _IO_flockfile (_IO_acquire_lock_file);
+#  define _IO_acquire_lock_clear_flags2(_fp) \
+  do {                                                                       \
+    _IO_FILE *_IO_acquire_lock_file                                          \
+       __attribute__((cleanup (_IO_acquire_lock_clear_flags2_fct)))          \
+       = (_fp);                                                              \
+    _IO_flockfile (_IO_acquire_lock_file);
+# else
+#  define _IO_acquire_lock(_fp) _IO_acquire_lock_needs_exceptions_enabled
+#  define _IO_acquire_lock_clear_flags2(_fp) _IO_acquire_lock (_fp)
+# endif
+# define _IO_release_lock(_fp) ; } while (0)
 
-# define _IO_release_lock(_fp) \
-  _IO_funlockfile (_fp);                                                     \
-  _IO_cleanup_region_end (0)
 #endif
 
 #endif /* stdio-lock.h */