[SERVER-1273] Can't include bson/bson.h and client/connpool.h in same file due to msgasserted conflict Created: 21/Jun/10  Updated: 12/Jul/16  Resolved: 20/Dec/11

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Bug Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Eric Milkie
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Operating System: ALL
Participants:

 Description   

Given the current git head, the following file will not compile:

#include <cmath>
#include <cstring>
#include <mongo/bson/bson.h>
#include <mongo/client/connpool.h>

It fails as follows:

In file included from /afs/acr/users/acm/mongo.temp.install/include/mongo/client/../util/../util/../db/../util/optime.h:20,
from /afs/acr/users/acm/mongo.temp.install/include/mongo/client/../util/../util/../db/jsobj.h:33,
from /afs/acr/users/acm/mongo.temp.install/include/mongo/client/../util/../util/sock.h:25,
from /afs/acr/users/acm/mongo.temp.install/include/mongo/client/../util/message.h:20,
from /afs/acr/users/acm/mongo.temp.install/include/mongo/client/dbclient.h:21,
from /afs/acr/users/acm/mongo.temp.install/include/mongo/client/connpool.h:21,
from ./header_check.cc:4:
/afs/acr/users/acm/mongo.temp.install/include/mongo/client/../util/../util/../db/../util/../db/concurrency.h: In member function 'bool mongo::MongoMutex::_checkWriteLockAlready()':
/afs/acr/users/acm/mongo.temp.install/include/mongo/client/../util/../util/../db/../util/../db/concurrency.h:115: error: call of overloaded 'msgasserted(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' is ambiguous
/afs/acr/users/acm/mongo.temp.install/include/mongo/bson/bson.h:66: note: candidates are: void mongo::msgasserted(int, const std::string&)
/afs/acr/users/acm/mongo.temp.install/include/mongo/client/../util/assert_util.h:173: note: void mongo::msgasserted(int, std::string)



 Comments   
Comment by Eric Milkie [ 12/Jan/12 ]

Hi Michael,
We haven't released the next version yet. When we release the next version, the C++ driver tarball will be updated with my commit seen above.
You have the option of using the latest yet-unreleased nightly build of the server for C++ driver use, to take advantage of the new headers without waiting for the next release.

Comment by Michael Wieher [ 12/Jan/12 ]

The github link shows changes that are not reflected on the driver download.

Notably, the msgasserted function does not exist, that is, the updates to uasserted are on the package downloaded via

http://www.mongodb.org/pages/viewpage.action?pageId=21269361 #C++ language center

however, the changes to msgasserted were not pushed to the package linked on the website, and I believe a function which relied/relies upon the current (ambiguous) msgasserted signature needs to be re-worked once the change is actually pushed.

Comment by Eric Milkie [ 20/Dec/11 ]

Fixed headers will be in the next release!

Comment by auto [ 20/Dec/11 ]

Author:

{u'login': u'milkie', u'name': u'Eric Milkie', u'email': u'milkie@10gen.com'}

Message: SERVER-1273 fix name collisions between bson.h and assert_util.h

Both header files define certain assert functions inline. If you are using the C++ driver,
these function definitions conflict, depending on what order you include the files.
To fix this, I changed the function definitions in assert_util.h to declarations, and also
tweaked the function signatures so that they would match between bson.h and assert_util.h.
I couldn't make the bson.h functions declarations because there is no associated bson.cpp
translation unit, so I had to change the assert_utils.h functions instead.
Removing the inlinedness from the functions is okay because they end up calling functions
that are explicitly marked NOINLINE anyway. Assertions are exceptional and the cost of
one added function call is not significant.
Branch: master
https://github.com/mongodb/mongo/commit/b4c100b0083db46f7915dceaf6ce4dd86d8497c6

Comment by Andrew Morrow (Inactive) [ 23/Feb/11 ]

I believe you, but it sort of misses the point. Client facing include files should never have this sort of order dependency. Every header in the set of client facing headers should be

  • complete: includes all headers needed to compile the header in isolation
  • idempotent: compiles correctly even if already included
  • context independent: compiles correctly no matter which other client headers have been previously included
  • hygenic: minimal injections to the global namespace, doesn't leak macros lacking a package prefix, etc.

Basically, the first three criteria can be validated by the following tests:

  • For any client facing header X.h, I should be able to make a file X.c which includes '#include X.h' twice, with no other content, and have that compile cleanly.
  • For the complete set of client facing headers, I should be able to take any subset and include them in any order to one .C file, and have that compile cleanly.

The mongo C++ driver headers currently don't pass these sorts of tests.

Comment by Scott Hernandez (Inactive) [ 20/Feb/11 ]

You can work around this issue by including more stuff via db/jsobj.h, instead of just bson.h.

Comment by Andrew Morrow (Inactive) [ 08/Feb/11 ]

Recently, this has become an issue for me as well, using mongo 1.6.3

Comment by Lance Diduck [ 02/Sep/10 ]

It did break things for me

Comment by Andrew Morrow (Inactive) [ 29/Jul/10 ]

This issue isn't personally blocking anything for me, since I don't happen to have a need to include both of these files in the same translation unit right now. However, it is almost certainly going to break things for some user of the C++ driver.

I'd looked at fixing this myself but the assertion macros are somewhat subtle and I don't want to break anything. It feels like a refactoring best left to the experts. But I'd still hope to see this fixed in 1.5 if possible.

FWIW, the error message has changed somewhat:

#include <mongo/bson/bson.h>
#include <mongo/client/connpool.h>

gets you:

In file included from /home/acm/tmp/mongo-tmp-install/include/mongo/client/../util/../util/../db/../util/optime.h:20,
from /home/acm/tmp/mongo-tmp-install/include/mongo/client/../util/../util/../db/jsobj.h:33,
from /home/acm/tmp/mongo-tmp-install/include/mongo/client/../util/../util/sock.h:25,
from /home/acm/tmp/mongo-tmp-install/include/mongo/client/../util/message.h:20,
from /home/acm/tmp/mongo-tmp-install/include/mongo/client/dbclient.h:21,
from /home/acm/tmp/mongo-tmp-install/include/mongo/client/connpool.h:21,
from xxx.cc:
/home/acm/tmp/mongo-tmp-install/include/mongo/client/../util/../util/../db/../util/../db/concurrency.h: In member function 'bool mongo::MongoMutex::_checkWriteLockAlready()':
/home/acm/tmp/mongo-tmp-install/include/mongo/client/../util/../util/../db/../util/../db/concurrency.h:113: error: call of overloaded 'msgasserted(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' is ambiguous
/home/acm/tmp/mongo-tmp-install/include/mongo/bson/bson.h:94: note: candidates are: void mongo::msgasserted(int, const std::string&)
/home/acm/tmp/mongo-tmp-install/include/mongo/client/../util/assert_util.h:176: note: void mongo::msgasserted(int, std::string)

Generated at Thu Feb 08 02:56:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.