Index: unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp =================================================================== --- unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp +++ unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp @@ -33,8 +33,8 @@ #if defined(_WIN32) || (defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)) -typedef void (*SetStrings)(std::string &GStr, std::string &LStr); -typedef void (*TestOrder)(std::vector &V); +typedef void (*SetStrings)(int &GStr, int &LStr); +typedef void (*TestOrder)(std::vector &V); typedef const char *(*GetString)(); template static T FuncPtr(void *Ptr) { @@ -110,13 +110,15 @@ } TEST(DynamicLibrary, Shutdown) { - std::string A("PipSqueak"), B, C("SecondLib"); - std::vector Order; + std::string A_lib("PipSqueak"), C_lib("SecondLib"); + int A = State::FIRST_CONSTANT, B = 0, C = State::SECOND_CONSTANT; + std::vector Order; + Order.reserve(2); { std::string Err; llvm_shutdown_obj Shutdown; DynamicLibrary DL = - DynamicLibrary::getPermanentLibrary(LibPath(A).c_str(), &Err); + DynamicLibrary::getPermanentLibrary(LibPath(A_lib).c_str(), &Err); EXPECT_TRUE(DL.isValid()); EXPECT_TRUE(Err.empty()); @@ -125,14 +127,14 @@ EXPECT_TRUE(SS_0 != nullptr); SS_0(A, B); - EXPECT_EQ(B, "Local::Local(PipSqueak)"); + EXPECT_TRUE(B == State::LOCAL_CONSTRUCTOR_CALL); TestOrder TO_0 = FuncPtr( DynamicLibrary::SearchForAddressOfSymbol("TestOrder")); EXPECT_TRUE(TO_0 != nullptr); - + DynamicLibrary DL2 = - DynamicLibrary::getPermanentLibrary(LibPath(C).c_str(), &Err); + DynamicLibrary::getPermanentLibrary(LibPath(C_lib).c_str(), &Err); EXPECT_TRUE(DL2.isValid()); EXPECT_TRUE(Err.empty()); @@ -147,22 +149,24 @@ EXPECT_TRUE(TO_1 != nullptr); EXPECT_TRUE(TO_0 != TO_1); - B.clear(); + B = 0; SS_1(C, B); - EXPECT_EQ(B, "Local::Local(SecondLib)"); + EXPECT_TRUE(B == State::LOCAL_CONSTRUCTOR_CALL); TO_0(Order); TO_1(Order); } - EXPECT_EQ(A, "Global::~Global"); - EXPECT_EQ(B, "Local::~Local"); + + EXPECT_TRUE(A == State::GLOBAL_DESTRUCTOR_CALL); + EXPECT_TRUE(B == State::LOCAL_DESTRUCTOR_CALL); + EXPECT_TRUE(FuncPtr(DynamicLibrary::SearchForAddressOfSymbol( "SetStrings")) == nullptr); // Test unload/destruction ordering EXPECT_EQ(Order.size(), 2UL); - EXPECT_EQ(Order.front(), "SecondLib"); - EXPECT_EQ(Order.back(), "PipSqueak"); + EXPECT_EQ(Order.front(), State::SECOND_CONSTANT); + EXPECT_EQ(Order.back(), State::FIRST_CONSTANT); } #else Index: unittests/Support/DynamicLibrary/PipSqueak.h =================================================================== --- unittests/Support/DynamicLibrary/PipSqueak.h +++ unittests/Support/DynamicLibrary/PipSqueak.h @@ -29,6 +29,10 @@ #define PIPSQUEAK_EXPORT #endif +enum State { FIRST_CONSTANT, SECOND_CONSTANT, + GLOBAL_CONSTRUCTOR_CALL, GLOBAL_DESTRUCTOR_CALL, + LOCAL_CONSTRUCTOR_CALL, LOCAL_DESTRUCTOR_CALL }; + extern "C" PIPSQUEAK_EXPORT const char *TestA(); #endif Index: unittests/Support/DynamicLibrary/PipSqueak.cpp =================================================================== --- unittests/Support/DynamicLibrary/PipSqueak.cpp +++ unittests/Support/DynamicLibrary/PipSqueak.cpp @@ -10,14 +10,14 @@ #include "PipSqueak.h" struct Global { - std::string *Str; - std::vector *Vec; + int *Str; + std::vector *Vec; Global() : Str(nullptr), Vec(nullptr) {} ~Global() { if (Str) { if (Vec) Vec->push_back(*Str); - *Str = "Global::~Global"; + *Str = State::GLOBAL_DESTRUCTOR_CALL; } } }; @@ -25,23 +25,20 @@ static Global Glb; struct Local { - std::string &Str; - Local(std::string &S) : Str(S) { - Str = "Local::Local"; - if (Glb.Str && !Glb.Str->empty()) - Str += std::string("(") + *Glb.Str + std::string(")"); + int &Str; + Local(int &S) : Str(S) { + Str = State::LOCAL_CONSTRUCTOR_CALL; } - ~Local() { Str = "Local::~Local"; } + ~Local() { Str = State::LOCAL_DESTRUCTOR_CALL; } }; - -extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr, - std::string &LStr) { +extern "C" PIPSQUEAK_EXPORT void SetStrings(int &GStr, + int &LStr) { Glb.Str = &GStr; static Local Lcl(LStr); } -extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector &V) { +extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector &V) { Glb.Vec = &V; }