summaryrefslogtreecommitdiff
path: root/src/base/exception.cpp
diff options
context:
space:
mode:
authorTim King <taking@google.com>2016-01-05 11:36:30 -0800
committerTim King <taking@google.com>2016-01-05 11:36:30 -0800
commitb717513e2a1d956c4456d13e0625957fc84c2449 (patch)
tree50b8a1fbd720fd5094004bde02de0ca61780df30 /src/base/exception.cpp
parent541c88a37f0880d7ea42a1aaa3a8688fc86ac811 (diff)
Adding a new class LastExceptionBuffer for the purpose of owning the memory for the last exception C string. This replaces s_debugLastException.
Diffstat (limited to 'src/base/exception.cpp')
-rw-r--r--src/base/exception.cpp49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/base/exception.cpp b/src/base/exception.cpp
index 87bdfcfa5..e1486e5bc 100644
--- a/src/base/exception.cpp
+++ b/src/base/exception.cpp
@@ -16,10 +16,11 @@
#include "base/exception.h"
-#include <string>
+#include <cstdarg>
#include <cstdio>
#include <cstdlib>
-#include <cstdarg>
+#include <cstring>
+#include <string>
#include "base/cvc4_assert.h"
@@ -27,6 +28,28 @@ using namespace std;
namespace CVC4 {
+CVC4_THREADLOCAL(LastExceptionBuffer*) LastExceptionBuffer::s_currentBuffer = NULL;
+
+LastExceptionBuffer::LastExceptionBuffer() : d_contents(NULL) {}
+
+LastExceptionBuffer::~LastExceptionBuffer() {
+ if(d_contents != NULL){
+ free(d_contents);
+ d_contents = NULL;
+ }
+}
+
+void LastExceptionBuffer::setContents(const char* string) {
+ if(d_contents != NULL){
+ free(d_contents);
+ d_contents = NULL;
+ }
+
+ if(string != NULL){
+ d_contents = strdup(string);
+ }
+}
+
char* IllegalArgumentException::s_header = "Illegal argument detected";
std::string IllegalArgumentException::formatVariadic() {
@@ -107,13 +130,14 @@ void IllegalArgumentException::construct(const char* header, const char* extra,
setMessage(string(buf));
#ifdef CVC4_DEBUG
- if(s_debugLastException == NULL) {
- // we leak buf[] but only in debug mode with assertions failing
- s_debugLastException = buf;
+ LastExceptionBuffer* buffer = LastExceptionBuffer::getCurrent();
+ if(buffer != NULL){
+ if(buffer->getContents() == NULL) {
+ buffer->setContents(buf);
+ }
}
-#else /* CVC4_DEBUG */
- delete [] buf;
#endif /* CVC4_DEBUG */
+ delete [] buf;
}
void IllegalArgumentException::construct(const char* header, const char* extra,
@@ -147,13 +171,14 @@ void IllegalArgumentException::construct(const char* header, const char* extra,
setMessage(string(buf));
#ifdef CVC4_DEBUG
- if(s_debugLastException == NULL) {
- // we leak buf[] but only in debug mode with assertions failing
- s_debugLastException = buf;
+ LastExceptionBuffer* buffer = LastExceptionBuffer::getCurrent();
+ if(buffer != NULL){
+ if(buffer->getContents() == NULL) {
+ buffer->setContents(buf);
+ }
}
-#else /* CVC4_DEBUG */
- delete [] buf;
#endif /* CVC4_DEBUG */
+ delete [] buf;
}
} /* namespace CVC4 */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback