Bug in 1.35: header inclusion order dependency introduced between recursive_mutex.hpp and asio.hpp on Windows

recursive_mutex.hpp include windows.h, which includes winsock.h. asio.hpp barfs if winsock.h has been included. Clearly it's not boost's fault that windows.h and winsock2.h have inclusion order problems, but this change will break code that currently uses them both. Jim P Consider the environment. Please don't print this email. ________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________

"James Talbut" <James.Talbut@omg3d.com> writes:
recursive_mutex.hpp include windows.h, which includes winsock.h. asio.hpp barfs if winsock.h has been included.
Clearly it's not boost's fault that windows.h and winsock2.h have inclusion order problems, but this change will break code that currently uses them both.
The boost thread code only includes windows.h if BOOST_USE_WINDOWS_H is defined. This is what is used in shared_ptr and interprocess to protect <windows.h>, so shouldn't cause a problem. Doing a grep for windows.h shows that it *is* included by the Boost date-time library, which boost.thread now depends on. I've CCed this to Jeff, to see if he can suggest a fix. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

On Mon, Mar 31, 2008 at 11:00 AM, James Talbut <James.Talbut@omg3d.com> wrote:
recursive_mutex.hpp include windows.h, which includes winsock.h. asio.hpp barfs if winsock.h has been included.
Just define WIN32_LEAN_AND_MEAN globally. Then winsock.h will not be included. [snip]
Jim
-- Felipe Magno de Almeida

That's a useful idea, but doesn't alter the fact that date_time 1.35 has broken previously working code and should be altered to work harmoniously with other boost libraries. The windows include order dependencies are a nightmare and I think it's the responsibility of libs that force their inclusion to avoid making the situation worse than it is. In other words, if there are include order dependencies in boost it's a bug, IMO. Jim
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Felipe Magno de Almeida Sent: 31 March 2008 20:22 To: boost@lists.boost.org Subject: Re: [boost] Bug in 1.35: header inclusion order dependencyintroduced between recursive_mutex.hpp and asio.hpp on Windows
On Mon, Mar 31, 2008 at 11:00 AM, James Talbut <James.Talbut@omg3d.com> wrote:
recursive_mutex.hpp include windows.h, which includes winsock.h. asio.hpp barfs if winsock.h has been included.
Just define WIN32_LEAN_AND_MEAN globally. Then winsock.h will not be included.
[snip]
Jim
-- Felipe Magno de Almeida _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________

James Talbut schrieb:
That's a useful idea, but doesn't alter the fact that date_time 1.35 has broken previously working code and should be altered to work harmoniously with other boost libraries. The windows include order dependencies are a nightmare and I think it's the responsibility of libs that force their inclusion to avoid making the situation worse than it is. In other words, if there are include order dependencies in boost it's a bug, IMO.
IMO, too, and I've openend a ticket for it: http://svn.boost.org/trac/boost/ticket/1740 Not only because it breaks winsock.h, but I have an enum member ERROR and it's useless after including date_time :/ Cheers, Anteru

Anteru wrote:
James Talbut schrieb:
That's a useful idea, but doesn't alter the fact that date_time 1.35 has broken previously working code and should be altered to work harmoniously with other boost libraries. The windows include order dependencies are a nightmare and I think it's the responsibility of libs that force their inclusion to avoid making the situation worse than it is. In other words, if there are include order dependencies in boost it's a bug, IMO.
IMO, too, and I've openend a ticket for it: http://svn.boost.org/trac/boost/ticket/1740
Not only because it breaks winsock.h, but I have an enum member ERROR and it's useless after including date_time :/
A global enumerated value called ERROR is not a good idea.

On Tue, 01 Apr 2008 13:48:03 -0400, Edward Diener wrote:
A global enumerated value called ERROR is not a good idea.
In C++, a global anything is not a good idea especially if you use other libraries. At the least, you should be doing C-style namespacing, i.e., product_ERROR, if you are into that sort of thing. -- Sohail Somani http://uint32t.blogspot.com

Sohail Somani wrote:
On Tue, 01 Apr 2008 13:48:03 -0400, Edward Diener wrote:
A global enumerated value called ERROR is not a good idea.
In C++, a global anything is not a good idea especially if you use other libraries. At the least, you should be doing C-style namespacing, i.e., product_ERROR, if you are into that sort of thing.
You mean like this: #include <boost/date_time.hpp> // or <windows.h> namespace X { class Y { typedef enum {OK=1, ERROR} myEnumT; }; } // namespace X int main(int argc, char* argv[]) { return 0; } The issue is not that the ERROR was globally enumerated. The issue is that ERROR is #defined in one of the headers that is included by windows.h. This is, of course, the fault of the windows headers for not respecting the set of symbols that it is allowed to define, but it is surprising to have otherwise valid code break by the inclusion of a boost header. Here is another example that is even harder to track down: ---8<--- Z.h ---8<--- #ifndef Z_incl #define Z_incl class Z { public: int GetMessage() const { return val; } private: int val; }; #endif ---8<--- main.cpp ---8<--- #include "Z.h" #include <boost/date_time.hpp> // or <windows.h> void foo() { Z z; z.GetMessage(); // error: GetMessageA is not a member of Z } ---8<--- ---8<--- David

On Tue, 01 Apr 2008 11:41:49 -0700, David Walthall wrote:
The issue is not that the ERROR was globally enumerated. The issue is that ERROR is #defined in one of the headers that is included by windows.h. This is, of course, the fault of the windows headers for not respecting the set of symbols that it is allowed to define, but it is surprising to have otherwise valid code break by the inclusion of a boost header.
Oh yuck. I'm sorry about that. windows.h is not fun. Another reason for not having header-only libraries to "make it easier" :-) -- Sohail Somani http://uint32t.blogspot.com
participants (7)
-
Anteru
-
Anthony Williams
-
David Walthall
-
Edward Diener
-
Felipe Magno de Almeida
-
James Talbut
-
Sohail Somani