diff --git a/SConstruct b/SConstruct index 66e17f299d1..67138a3ebf7 100644 --- a/SConstruct +++ b/SConstruct @@ -311,7 +311,7 @@ env["LIBPATH"] = [] if GetOption( "recstore" ) != None: env.Append( CPPDEFINES=[ "_RECSTORE" ] ) -env.Append( CPPDEFINES=[ "_SCONS" ] ) +env.Append( CPPDEFINES=[ "_SCONS" , "MONGO_EXPOSE_MACROS" ] ) env.Append( CPPPATH=[ "." ] ) diff --git a/client/cleanup.h b/client/cleanup.h deleted file mode 100644 index db18fec23ae..00000000000 --- a/client/cleanup.h +++ /dev/null @@ -1,66 +0,0 @@ -/** @file cleanup.h - remove mongo-specific macros that might cause issues - * If included, it must be the last of the mongo headers - */ - -/* Copyright 2009 10gen Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// If you define a new global un-prefixed macro, please undef it here - -// util/allocator.h -#undef malloc -#undef realloc - -// util/assert_util.h -#undef assert -#undef dassert -#undef massert -#undef uassert -#undef wassert -#undef yassert -#undef xassert -#undef ASSERT_ID_DUPKEY -#undef ASSERT_STREAM_GOOD -#undef BOOST_CHECK_EXCEPTION -#undef DESTRUCTOR_GUARD - -// util/goodies.h -#undef PRINT -#undef PRINTFL -#undef asctime -#undef gmtime -#undef localtime -#undef ctime - -// util/log.h -#undef OUTPUT_ERRNOX -#undef OUTPUT_ERRNO - -// util/debug_util.h -#undef WIN -#undef DEV -#undef DEBUGGING -#undef SOMETIMES -#undef OCCASIONALLY -#undef RARELY -#undef ONCE - -// db/instance.h -#undef OPREAD -#undef OPWRITE - -// stdafx.h -#undef null - diff --git a/client/connpool.h b/client/connpool.h index 7f1763c22a2..f5c0c866974 100644 --- a/client/connpool.h +++ b/client/connpool.h @@ -19,6 +19,7 @@ #include #include "dbclient.h" +#include "redef_macros.h" namespace mongo { @@ -134,3 +135,5 @@ namespace mongo { }; } // namespace mongo + +#include "undef_macros.h" diff --git a/client/dbclient.h b/client/dbclient.h index e90a66e57d6..ca7218835cb 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -960,3 +960,5 @@ namespace mongo { DBClientBase * createDirectClient(); } // namespace mongo + +#include "undef_macros.h" diff --git a/client/gridfs.h b/client/gridfs.h index 3165d5f2988..3b8001ba6a6 100644 --- a/client/gridfs.h +++ b/client/gridfs.h @@ -18,6 +18,7 @@ #pragma once #include "dbclient.h" +#include "redef_macros.h" namespace mongo { @@ -200,4 +201,4 @@ namespace mongo { }; } - +#include "undef_macros.h" diff --git a/client/model.h b/client/model.h index 907b2eaca4e..108efc06ba7 100644 --- a/client/model.h +++ b/client/model.h @@ -18,6 +18,7 @@ #pragma once #include "dbclient.h" +#include "redef_macros.h" namespace mongo { @@ -57,3 +58,5 @@ namespace mongo { }; } // namespace mongo + +#include "undef_macros.h" diff --git a/client/parallel.h b/client/parallel.h index 4431e358bfa..c3181bc6237 100644 --- a/client/parallel.h +++ b/client/parallel.h @@ -21,6 +21,8 @@ #include "../stdafx.h" #include "dbclient.h" +#include "redef_macros.h" + #include "../db/dbmessage.h" #include "../db/matcher.h" @@ -270,3 +272,5 @@ namespace mongo { } + +#include "undef_macros.h" diff --git a/client/redef_macros.h b/client/redef_macros.h new file mode 100644 index 00000000000..0af9111fb01 --- /dev/null +++ b/client/redef_macros.h @@ -0,0 +1,72 @@ +/** @file redef_macros.h - redefine macros from undef_macros.h */ + +/* Copyright 2009 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// If you define a new global un-prefixed macro, please add it here and in undef_macros +// The push_macro and pop_macro pragmas as specific to MSVC and GCC + +// #pragma once // this file is intended to be processed multiple times + +#if defined(MONGO_MACROS_CLEANED) + +// util/allocator.h +#pragma pop_macro("malloc") +#pragma pop_macro("realloc") + +// util/assert_util.h +#pragma pop_macro("assert") +#pragma pop_macro("dassert") +#pragma pop_macro("massert") +#pragma pop_macro("uassert") +#pragma pop_macro("wassert") +#pragma pop_macro("yassert") +#pragma pop_macro("xassert") +#pragma pop_macro("ASSERT_ID_DUPKEY") +#pragma pop_macro("ASSERT_STREAM_GOOD") +#pragma pop_macro("BOOST_CHECK_EXCEPTION") +#pragma pop_macro("DESTRUCTOR_GUARD") + +// util/goodies.h +#pragma pop_macro("PRINT") +#pragma pop_macro("PRINTFL") +#pragma pop_macro("asctime") +#pragma pop_macro("gmtime") +#pragma pop_macro("localtime") +#pragma pop_macro("ctime") + +// util/log.h +#pragma pop_macro("OUTPUT_ERRNOX") +#pragma pop_macro("OUTPUT_ERRNO") + +// util/debug_util.h +#pragma pop_macro("WIN") +#pragma pop_macro("DEV") +#pragma pop_macro("DEBUGGING") +#pragma pop_macro("SOMETIMES") +#pragma pop_macro("OCCASIONALLY") +#pragma pop_macro("RARELY") +#pragma pop_macro("ONCE") + +// db/instance.h +#pragma pop_macro("OPREAD") +#pragma pop_macro("OPWRITE") + +// stdafx.h +#pragma pop_macro("null") + +#undef MONGO_MACROS_CLEANED +#endif + diff --git a/client/syncclusterconnection.h b/client/syncclusterconnection.h index 9efed93071f..ff8bb2bfc86 100644 --- a/client/syncclusterconnection.h +++ b/client/syncclusterconnection.h @@ -18,6 +18,7 @@ #include "../stdafx.h" #include "dbclient.h" +#include "redef_macros.h" namespace mongo { @@ -102,3 +103,5 @@ namespace mongo { }; + +#include "undef_macros.h" diff --git a/client/undef_macros.h b/client/undef_macros.h new file mode 100644 index 00000000000..9c14c9bff81 --- /dev/null +++ b/client/undef_macros.h @@ -0,0 +1,102 @@ +/** @file undef_macros.h - remove mongo-specific macros that might cause issues */ + +/* Copyright 2009 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// If you define a new global un-prefixed macro, please add it here and in redef_macros +// The push_macro and pop_macro pragmas as specific to MSVC and GCC + +// #pragma once // this file is intended to be processed multiple times + +#if !defined(MONGO_EXPOSE_MACROS) && !defined(MONGO_MACROS_CLEANED) + +// util/allocator.h +#pragma push_macro("malloc") +#undef malloc +#pragma push_macro("realloc") +#undef realloc + +// util/assert_util.h +#pragma push_macro("assert") +#undef assert +#pragma push_macro("dassert") +#undef dassert +#pragma push_macro("massert") +#undef massert +#pragma push_macro("uassert") +#undef uassert +#pragma push_macro("wassert") +#undef wassert +#pragma push_macro("yassert") +#undef yassert +#pragma push_macro("xassert") +#undef xassert +#pragma push_macro("ASSERT_ID_DUPKEY") +#undef ASSERT_ID_DUPKEY +#pragma push_macro("ASSERT_STREAM_GOOD") +#undef ASSERT_STREAM_GOOD +#pragma push_macro("BOOST_CHECK_EXCEPTION") +#undef BOOST_CHECK_EXCEPTION +#pragma push_macro("DESTRUCTOR_GUARD") +#undef DESTRUCTOR_GUARD + +// util/goodies.h +#pragma push_macro("PRINT") +#undef PRINT +#pragma push_macro("PRINTFL") +#undef PRINTFL +#pragma push_macro("asctime") +#undef asctime +#pragma push_macro("gmtime") +#undef gmtime +#pragma push_macro("localtime") +#undef localtime +#pragma push_macro("ctime") +#undef ctime + +// util/log.h +#pragma push_macro("OUTPUT_ERRNOX") +#undef OUTPUT_ERRNOX +#pragma push_macro("OUTPUT_ERRNO") +#undef OUTPUT_ERRNO + +// util/debug_util.h +#pragma push_macro("WIN") +#undef WIN +#pragma push_macro("DEV") +#undef DEV +#pragma push_macro("DEBUGGING") +#undef DEBUGGING +#pragma push_macro("SOMETIMES") +#undef SOMETIMES +#pragma push_macro("OCCASIONALLY") +#undef OCCASIONALLY +#pragma push_macro("RARELY") +#undef RARELY +#pragma push_macro("ONCE") +#undef ONCE + +// db/instance.h +#pragma push_macro("OPREAD") +#undef OPREAD +#pragma push_macro("OPWRITE") +#undef OPWRITE + +// stdafx.h +#pragma push_macro("null") +#undef null + +#define MONGO_MACROS_CLEANED +#endif diff --git a/dbtests/clienttests.cpp b/dbtests/clienttests.cpp index c4caa43b387..1d4e1d6bfe2 100644 --- a/dbtests/clienttests.cpp +++ b/dbtests/clienttests.cpp @@ -20,9 +20,6 @@ #include "../client/dbclient.h" #include "dbtests.h" #include "../db/concurrency.h" - -// must be last -#include "../client/cleanup.h" namespace ClientTests { @@ -157,16 +154,6 @@ namespace ClientTests { } }; - class HiddenMacros{ - public: - void run(){ - ASSERT_EQUALS(&malloc, &std::malloc); -#ifdef assert - ASSERT(!"assert macro still defined"); -#endif - } - }; - class All : public Suite { public: All() : Suite( "client" ){ @@ -179,7 +166,6 @@ namespace ClientTests { add(); add(); add(); - add(); } } all; diff --git a/dbtests/macrotests.cpp b/dbtests/macrotests.cpp new file mode 100644 index 00000000000..7aed519ba3e --- /dev/null +++ b/dbtests/macrotests.cpp @@ -0,0 +1,31 @@ +#undef MONGO_EXPOSE_MACROS + +#include "../client/dbclient.h" + +#ifdef malloc +# error malloc defined 0 +#endif + +#ifdef assert +# error assert defined 1 +#endif + +#include "../client/parallel.h" //uses assert + +#ifdef assert +# error assert defined 2 +#endif + +#include "../client/redef_macros.h" + +#ifndef assert +# error assert not defined 3 +#endif + +#include "../client/undef_macros.h" + +#ifdef assert +# error assert defined 3 +#endif + +