[CXX-81] On Windows, MONGO_API functions should be decorated with __cdecl. Created: 19/Apr/12  Updated: 04/May/14  Resolved: 18/Apr/14

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: legacy-0.8.0

Type: Bug Priority: Major - P3
Reporter: Eric Milkie Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 0
Labels: cxxmove, legacy-cxx, windows
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CXX-112 Provide a SConstruct option to specif... Closed
Related
related to SERVER-3364 The C++ Driver compiled as shared lib... Closed
related to SERVER-9771 Enable support for building the C++ d... Closed
is related to SERVER-11879 Using Windows mongoclient.dll, static... Closed

 Description   

For example, in Windows, a proper library explicitly specifies the calling convention for each function:

void __cdecl mongo::connect(char* host)

We are using the default calling convention right now, which is __cdecl. If someone is using __stdcall in their project, they won't be able to use the C++ driver because the calling convention is wrong. Actually, they will be able to compile just fine but run time will not work (and it might not even be obvious what is wrong at first).

Typically, the __cdecl is hidden inside a macro; we could use MONGO_API:

#ifdef WIN32
#define MONGO_API __cdecl
#else
#define MONGO_API
#endif

If we decide to release a DLL or .so library in the future, we could also use the MONGO_API macro to affect the visibility of the API functions using dllexport or gcc attributes.



 Comments   
Comment by Githook User [ 22/Apr/14 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: CXX-81 Obtain cdecl via compiler headers rather than redefining
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/126ca2f8e5c39c0d7e3c201fc6de5fa00da81a3c

Comment by Andrew Morrow (Inactive) [ 18/Apr/14 ]

https://github.com/mongodb/mongo-cxx-driver/pull/55

Comment by Githook User [ 18/Apr/14 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: CXX-81 Tag all exported free functions with calling convention macro
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/7b5b9bd8d6ba15c3009285839704626fa8a9a4bc

Comment by Andrew Morrow (Inactive) [ 18/Apr/14 ]

https://github.com/mongodb/mongo-cxx-driver/pull/55

Comment by Andy Schwerin [ 10/Dec/13 ]

__cdecl declaration, to be complete, would probably involve annotating every member function in every class, and can only matter on 32-bit Windows in practice. Deferring.

Comment by Githook User [ 10/Dec/13 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@10gen.com'}

Message: SERVER-3364, SERVER-5650 Define away MONGO_CLIENT_API when not building the shared library.
Branch: master
https://github.com/mongodb/mongo/commit/82e8115bacf418f3fe8af50e04b7d6ca218d87f1

Comment by Githook User [ 09/Dec/13 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@10gen.com'}

Message: SERVER-3364 Introduce MONGO_CLIENT_API macro for labeling types, functions and variables.

Also addresses SERVER-5650.
Branch: master
https://github.com/mongodb/mongo/commit/1df18f9530aec174f384d5f4ff5efda8218ecd32

Comment by Githook User [ 09/Dec/13 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@10gen.com'}

Message: SERVER-3364 Add macros for putting visibility and calling convention declarations on declarations.

Also SERVER-5650.

MONGO_COMPILER_API_EXPORT Puts the "export visibility" declaration on a type,
function or variable.

MONGO_COMPILER_API_IMPORT Puts the "import from library" declaration on a type,
function or variable.

MONGO_COMPILER_API_CALLING_CONVENTION Labels a function declaration with its
calling convention.
Branch: master
https://github.com/mongodb/mongo/commit/3100d120989881a47b9efbaaad5aec49980301d4

Comment by Githook User [ 05/Dec/13 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@10gen.com'}

Message: SERVER-3364,SERVER-5650 Move documenation of MONGO_COMPILER macros to compiler.h.

This deduplicates documentation, hopefully preventing the documentation from diverging.
Branch: master
https://github.com/mongodb/mongo/commit/1f0b640fb7b0f6de22fe098f12d3b05b23c1caf4

Generated at Wed Feb 07 21:58:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.