Close DynamicLibraries in reverse order they were opened.
Summary: Matches C++ destruction ordering better and fixes possible problems of loaded libraries having inter-dependencies.
Reviewers: efriedma, v.g.vassilev, chapuni
Reviewed By: efriedma
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D33652
llvm-svn: 304720
diff --git a/llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx b/llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx
index d1cf7c0..79cf592 100644
--- a/llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx
+++ b/llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx
@@ -9,38 +9,40 @@
#include "PipSqueak.h"
-#if defined(_WIN32) && !defined(__GNUC__)
-// Disable warnings from inclusion of xlocale & exception
-#pragma warning(push)
-#pragma warning(disable: 4530)
-#pragma warning(disable: 4577)
-#include <string>
-#pragma warning(pop)
-#else
-#include <string>
-#endif
-
struct Global {
std::string *Str;
- Global() : Str(nullptr) {}
+ std::vector<std::string> *Vec;
+ Global() : Str(nullptr), Vec(nullptr) {}
~Global() {
- if (Str)
+ if (Str) {
+ if (Vec)
+ Vec->push_back(*Str);
*Str = "Global::~Global";
+ }
}
};
-struct Local {
- std::string &Str;
- Local(std::string &S) : Str(S) { Str = "Local::Local"; }
- ~Local() { Str = "Local::~Local"; }
-};
-
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(")");
+ }
+ ~Local() { Str = "Local::~Local"; }
+};
+
+
extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr,
std::string &LStr) {
- static Local Lcl(LStr);
Glb.Str = &GStr;
+ static Local Lcl(LStr);
+}
+
+extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector<std::string> &V) {
+ Glb.Vec = &V;
}
extern "C" PIPSQUEAK_EXPORT const char *TestA() { return "LibCall"; }