From a84489dd72e996d415880e7625733cfd6be5394e Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 11 Aug 2017 11:25:54 +0200
Subject: [PATCH] move stack trace, signal handling to ext namespace

---
 alib2common/src/debug/sigHandler.cpp          |  6 +++---
 alib2common/src/debug/sigHandler.h            |  4 ++--
 alib2common/src/debug/simpleStacktrace.cpp    | 18 +++++++++---------
 alib2common/src/debug/simpleStacktrace.h      |  6 +++---
 alib2common/src/exception/CommonException.cpp |  2 +-
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/alib2common/src/debug/sigHandler.cpp b/alib2common/src/debug/sigHandler.cpp
index e6c0658ac0..a3cfbb3ce4 100644
--- a/alib2common/src/debug/sigHandler.cpp
+++ b/alib2common/src/debug/sigHandler.cpp
@@ -9,7 +9,7 @@
 #include "simpleStacktrace.h"
 #include <iostream>
 
-namespace std {
+namespace ext {
 
 void SigHandler::handler(int signal) {
 	switch(signal) {
@@ -24,7 +24,7 @@ void SigHandler::handler(int signal) {
 			break;
 	}
 	#ifdef DEBUG
-		std::cout << std::simpleStacktrace() << std::endl;
+		std::cout << ext::simpleStacktrace() << std::endl;
 	#endif
 	exit(1);
 }
@@ -36,4 +36,4 @@ SigHandler::SigHandler() {
 
 SigHandler SigHandler::HANDLER;
 
-} /* namespace std */
+} /* namespace ext */
diff --git a/alib2common/src/debug/sigHandler.h b/alib2common/src/debug/sigHandler.h
index 4de86c251b..0d304c3afc 100644
--- a/alib2common/src/debug/sigHandler.h
+++ b/alib2common/src/debug/sigHandler.h
@@ -3,7 +3,7 @@
 
 #include <string>
 
-namespace std {
+namespace ext {
 
 class SigHandler {
 	static void handler(int);
@@ -16,6 +16,6 @@ protected:
 
 };
 
-} /* namespace std */
+} /* namespace ext */
 
 #endif /* SIG_HANDLER_H_ */
diff --git a/alib2common/src/debug/simpleStacktrace.cpp b/alib2common/src/debug/simpleStacktrace.cpp
index 88766b9904..794a41e690 100644
--- a/alib2common/src/debug/simpleStacktrace.cpp
+++ b/alib2common/src/debug/simpleStacktrace.cpp
@@ -15,7 +15,7 @@
 #include <string>
 #include <map>
 
-namespace std {
+namespace ext {
 
 int callback(struct dl_phdr_info *info, size_t, void * data) {
 	ext::map<std::string, long>& dlToBaseAddress = *(reinterpret_cast<ext::map<std::string, long>*>(data));
@@ -26,7 +26,7 @@ int callback(struct dl_phdr_info *info, size_t, void * data) {
 }
 
 /** Print a demangled stack backtrace of the caller function to FILE* out. */
-string simpleStacktrace(unsigned int max_frames) {
+std::string simpleStacktrace(unsigned int max_frames) {
 	char linkname[512]; /* /proc/exe */
 	char buf[512];
 	pid_t pid;
@@ -40,8 +40,8 @@ string simpleStacktrace(unsigned int max_frames) {
 	ret = readlink(linkname, buf, 512);
 	buf[ret] = 0;
 
-	stringstream ss;
-	ss << "stack trace for process " << buf << " (PID:" << pid << "):"<< endl;
+	std::stringstream ss;
+	ss << "stack trace for process " << buf << " (PID:" << pid << "):"<< std::endl;
 
 	// storage array for stack trace address data
 	void** addrlist = (void**) malloc( (max_frames + 1 ) * sizeof(void*) );
@@ -50,7 +50,7 @@ string simpleStacktrace(unsigned int max_frames) {
 	int addrlen = backtrace(addrlist, max_frames);
 
 	if (addrlen == 0) {
-		ss << "  <empty, possibly corrupt>" << endl;
+		ss << "  <empty, possibly corrupt>" << std::endl;
 		free(addrlist);
 		return std::move(ss).str();
 	}
@@ -114,15 +114,15 @@ string simpleStacktrace(unsigned int max_frames) {
 			char* demangled = abi::__cxa_demangle(begin_name, funcname, &funcnamesize, &status);
 			if (status == 0) {
 				funcname = demangled; // use possibly realloc()-ed string
-				ss << "  " << symbollist[i] << " : " << funcname << "+" << begin_offset << " " << begin_name << " [0x" << addr_offset_by_dl.c_str() << "; @ " << addr_offset << "]" << endl;
+				ss << "  " << symbollist[i] << " : " << funcname << "+" << begin_offset << " " << begin_name << " [0x" << addr_offset_by_dl.c_str() << "; @ " << addr_offset << "]" << std::endl;
 			} else {
 				// demangling failed. Output function name as a C function with
 				// no arguments.
-				ss << "  " << symbollist[i] << " : " << begin_name << "()+" << begin_offset << " " << " [0x" << addr_offset_by_dl.c_str() << "; @ " << addr_offset << "]" << endl;
+				ss << "  " << symbollist[i] << " : " << begin_name << "()+" << begin_offset << " " << " [0x" << addr_offset_by_dl.c_str() << "; @ " << addr_offset << "]" << std::endl;
 			}
 		} else {
 			// couldn't parse the line? print the whole line.
-			ss << "  " << symbollist[i] << endl;
+			ss << "  " << symbollist[i] << std::endl;
 		}
 	}
 	free(funcname);
@@ -131,4 +131,4 @@ string simpleStacktrace(unsigned int max_frames) {
 	return std::move(ss).str();
 }
 
-} /* namespace std */
+} /* namespace ext */
diff --git a/alib2common/src/debug/simpleStacktrace.h b/alib2common/src/debug/simpleStacktrace.h
index 3bab18f1e6..4c5ffaf396 100644
--- a/alib2common/src/debug/simpleStacktrace.h
+++ b/alib2common/src/debug/simpleStacktrace.h
@@ -6,11 +6,11 @@
 
 #include <string>
 
-namespace std {
+namespace ext {
 
 /** Print a demangled stack backtrace of the caller function to FILE* out. */
-string simpleStacktrace(unsigned int max_frames = 1000);
+std::string simpleStacktrace(unsigned int max_frames = 1000);
 
-} /* namespace std */
+} /* namespace ext */
 
 #endif // _SIMPLE_STACKTRACE_H_
diff --git a/alib2common/src/exception/CommonException.cpp b/alib2common/src/exception/CommonException.cpp
index f44cef3372..54513c789a 100644
--- a/alib2common/src/exception/CommonException.cpp
+++ b/alib2common/src/exception/CommonException.cpp
@@ -23,7 +23,7 @@ namespace exception {
 
 CommonException::CommonException ( std::string cause ) : m_cause(std::move(cause)) {
 	#ifdef DEBUG
-		this->m_backtrace = std::simpleStacktrace();
+		this->m_backtrace = ext::simpleStacktrace();
 	#else
 		this->m_backtrace = "";
 	#endif
-- 
GitLab