From eee51fe3a4ed1b822a1c5d79b9a1b653cae59dff Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Jul 2020 11:22:46 +0200 Subject: Work around glibc bug #14898 (GitHub issue #2) --- libbutl/utility.cxx | 14 ++++++++++++-- libbutl/utility.mxx | 27 +++++++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'libbutl') diff --git a/libbutl/utility.cxx b/libbutl/utility.cxx index d6a21c6..c23d3f5 100644 --- a/libbutl/utility.cxx +++ b/libbutl/utility.cxx @@ -51,11 +51,21 @@ namespace butl #else __thread #endif - bool exception_unwinding_dtor_ = false; +#if defined(__GLIBC__) && \ + defined(__GLIBC_MINOR__) && \ + (__GLIBC__ < 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ < 17) + int +#else + bool +#endif + exception_unwinding_dtor_ = false; #ifdef _WIN32 - bool& + bool exception_unwinding_dtor () {return exception_unwinding_dtor_;} + + void + exception_unwinding_dtor (bool v) {exception_unwinding_dtor_ = v;} #endif #endif diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index 251471a..78c9355 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -422,17 +422,32 @@ LIBBUTL_MODEXPORT namespace butl #else __thread #endif - bool exception_unwinding_dtor_; + // Work around glibc bug #14898. + // +#if defined(__GLIBC__) && \ + defined(__GLIBC_MINOR__) && \ + (__GLIBC__ < 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ < 17) + int +#else + bool +#endif + exception_unwinding_dtor_; // On Windows one cannot export a thread-local variable so we have to - // use a wrapper functions. + // use wrapper functions. // #ifdef _WIN32 - LIBBUTL_SYMEXPORT bool& + LIBBUTL_SYMEXPORT bool exception_unwinding_dtor (); + + LIBBUTL_SYMEXPORT void + exception_unwinding_dtor (bool); #else - inline bool& + inline bool exception_unwinding_dtor () {return exception_unwinding_dtor_;} + + inline void + exception_unwinding_dtor (bool v) {exception_unwinding_dtor_ = v;} #endif template @@ -443,9 +458,9 @@ LIBBUTL_MODEXPORT namespace butl { if (std::uncaught_exception ()) { - exception_unwinding_dtor () = true; + exception_unwinding_dtor (true); f_ (); - exception_unwinding_dtor () = false; + exception_unwinding_dtor (false); } } -- cgit v1.1