Boost logo

Boost-Commit :

From: jurko.gospodnetic_at_[hidden]
Date: 2008-04-16 20:20:33


Author: jurko
Date: 2008-04-16 20:20:33 EDT (Wed, 16 Apr 2008)
New Revision: 44480
URL: http://svn.boost.org/trac/boost/changeset/44480

Log:
Added a workaround for a compilation failure when including some Boost Serialization headers before some Boost Pool headers using MSVC 7.1 or 8.0. Source of the problem is a compiler bug fixed in MSVC 9.0 and workaround consists of referencing some Windows API identifiers using their fully qualified names. Added a related regression test for the Boost Pool library. See the test code comments for more detailed information on the bug.
Added:
   trunk/libs/pool/test/pool_msvc_compiler_bug_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/pool/detail/mutex.hpp | 20 ++++++++++----------
   trunk/libs/pool/test/Jamfile.v2 | 1 +
   2 files changed, 11 insertions(+), 10 deletions(-)

Modified: trunk/boost/pool/detail/mutex.hpp
==============================================================================
--- trunk/boost/pool/detail/mutex.hpp (original)
+++ trunk/boost/pool/detail/mutex.hpp 2008-04-16 20:20:33 EDT (Wed, 16 Apr 2008)
@@ -64,23 +64,23 @@
 class win32_mutex
 {
   private:
- CRITICAL_SECTION mtx;
+ ::CRITICAL_SECTION mtx;
 
     win32_mutex(const win32_mutex &);
     void operator=(const win32_mutex &);
 
   public:
     win32_mutex()
- { InitializeCriticalSection(&mtx); }
+ { ::InitializeCriticalSection(&mtx); }
 
     ~win32_mutex()
- { DeleteCriticalSection(&mtx); }
+ { ::DeleteCriticalSection(&mtx); }
 
     void lock()
- { EnterCriticalSection(&mtx); }
+ { ::EnterCriticalSection(&mtx); }
 
     void unlock()
- { LeaveCriticalSection(&mtx); }
+ { ::LeaveCriticalSection(&mtx); }
 };
 
 #endif // defined(BOOST_WINDOWS)
@@ -90,23 +90,23 @@
 class pthread_mutex
 {
   private:
- pthread_mutex_t mtx;
+ ::pthread_mutex_t mtx;
 
     pthread_mutex(const pthread_mutex &);
     void operator=(const pthread_mutex &);
 
   public:
     pthread_mutex()
- { pthread_mutex_init(&mtx, 0); }
+ { ::pthread_mutex_init(&mtx, 0); }
 
     ~pthread_mutex()
- { pthread_mutex_destroy(&mtx); }
+ { ::pthread_mutex_destroy(&mtx); }
 
     void lock()
- { pthread_mutex_lock(&mtx); }
+ { ::pthread_mutex_lock(&mtx); }
 
     void unlock()
- { pthread_mutex_unlock(&mtx); }
+ { ::pthread_mutex_unlock(&mtx); }
 };
 
 #endif // defined(_POSIX_THREADS) || defined(BOOST_HAS_PTHREADS)

Modified: trunk/libs/pool/test/Jamfile.v2
==============================================================================
--- trunk/libs/pool/test/Jamfile.v2 (original)
+++ trunk/libs/pool/test/Jamfile.v2 2008-04-16 20:20:33 EDT (Wed, 16 Apr 2008)
@@ -11,4 +11,5 @@
 
 test-suite pool :
     [ run test_pool_alloc.cpp ]
+ [ run pool_msvc_compiler_bug_test.cpp ]
     ;

Added: trunk/libs/pool/test/pool_msvc_compiler_bug_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/pool/test/pool_msvc_compiler_bug_test.cpp 2008-04-16 20:20:33 EDT (Wed, 16 Apr 2008)
@@ -0,0 +1,40 @@
+// Copyright (C) 2008 Jurko Gospodnetic
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+// This tests whether the Boost Pool library managed to get a regression and
+// hit the MSVC 'variables exported to global namespace' bug again. This bug
+// affects at least MSVC 7.1 & 8.0 releases and has been fixed in the MSVC 9.0
+// release.
+//
+// If the bug exists this test should fail to compile, complaining about an
+// ambiguous CRITICAL_SECTION symbol. The bug got fixed by making the boost/
+// /pool/detail/mutex.hpp header reference all Windows API constants using their
+// fully qualified names.
+//
+// To see the bug in action without using any Boost libraries run the
+// following program:
+//
+// namespace One { class Brick; }
+// namespace Two
+// {
+// using namespace One;
+// template <class TinyTemplateParam> class TinyClass {};
+// }
+// class Brick {};
+// Brick brick;
+// int main() {}
+// (17.04.2008.) (Jurko)
+
+
+#include "boost/archive/text_iarchive.hpp"
+#include "boost/pool/detail/mutex.hpp"
+// Including "boost/pool/pool_alloc.hpp" instead of mutex.hpp should work as
+// well.
+
+int main()
+{
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk