summaryrefslogtreecommitdiff
path: root/generic/Exceptions.cpp
diff options
context:
space:
mode:
authorPixel <Pixel>2002-08-25 14:39:48 +0000
committerPixel <Pixel>2002-08-25 14:39:48 +0000
commit38d60726082b04e79edae1c8c797c6dcb8314504 (patch)
tree4a056a158c6fc21c29dd8d8ed94c010a25cee19a /generic/Exceptions.cpp
parent1b0a5db816b7610c83615e93095155b1709f55da (diff)
Workiiiiiiiiiiiiiiiiiing!!!!
Diffstat (limited to 'generic/Exceptions.cpp')
-rw-r--r--generic/Exceptions.cpp49
1 files changed, 21 insertions, 28 deletions
diff --git a/generic/Exceptions.cpp b/generic/Exceptions.cpp
index f24c0fb..b7c00a6 100644
--- a/generic/Exceptions.cpp
+++ b/generic/Exceptions.cpp
@@ -3,6 +3,10 @@
#include <string.h>
#include <errno.h>
#include <stddef.h>
+#include <glib.h>
+#ifdef DEBUG
+#include <iostream>
+#endif
#include "String.h"
#include "Exceptions.h"
#include "generic.h"
@@ -82,36 +86,26 @@ void * xmalloc(size_t s) throw (GeneralException) {
return 0;
}
- if (!(r = (char *) ::malloc(s + 2 * sizeof(size_t)))) {
- throw MemoryException(s + 2 * sizeof(size_t));
+ if (!(r = (char *) ::malloc(s))) {
+ throw MemoryException(s);
}
+#ifdef DEBUG
+ fprintf(stderr, "Allocating %i bytes of memory, got it at %p\n", s, r);
+#endif
- memset(r, 0, s + 2 * sizeof(size_t));
+ memset(r, 0, s);
- *((size_t *)r) = s;
- *(((size_t *)r) + 1) = 0xdeedbeef;
-
- return (void *)(r + 2 * sizeof(size_t));
+ return (void *)(r);
}
void * xrealloc(void * ptr, size_t s) {
- char * r;
- size_t os;
-
- if (!ptr) {
- return xmalloc(s);
- }
-
- os = *(((size_t *) ptr) - 1);
-
- r = (char *) xmalloc(s);
-
- if (s) {
- memcpy(r, ptr, MIN(s, os));
- }
-
- xfree(ptr);
+#ifdef DEBUG
+ void * r = realloc(ptr, s);
+ fprintf(stderr, "Reallocating pointer at %p for %i bytes, now at %p\n", ptr, s, r);
return r;
+#else
+ return realloc(ptr, s);
+#endif
}
#ifdef OVER_FREE
@@ -123,12 +117,11 @@ void xfree(void *& p) {
}
void xfree(char *& p) {
+#ifdef DEBUG
+ fprintf(stderr, "Freeing pointer at %p\n", p);
+#endif
if (p) {
- if (*(((size_t *)p) - 1) != 0xdeedbeef) {
- fprintf(stderr, "Error: trying to xfree() a non xmalloc()ed bloc.\n");
- exit(-1);
- }
- ::free(p - 2 * sizeof(size_t));
+ ::free(p);
p = 0;
}
}