#include "stack.h"
#include <stdlib.h>
+#ifndef COMMANDLINEFLAGS
#define CHECKTYPE
#define CHECKMEMORY
+#endif
struct typemap * allocatetypemap() {
struct typemap *thisvar=(struct typemap *) malloc(sizeof(struct typemap));
return typemapassertvalidmemoryB(thisvar, low,((char *)low)+toadd);
}
+bool typemapassertexactmemory(struct typemap * thisvar, void* low, int s) {
+ int toadd=sizeBytes(s);
+#ifdef CHECKMEMORY
+ {
+ void * high=((char *)low)+toadd;
+ struct pair allocp=rbfind(low,high,thisvar->alloctree);
+ if (allocp.low == NULL) {
+ return false;
+ } else if ((allocp.low != low) || (allocp.high != high)) {
+ /* make sure this block exactly lines up */
+ return false;
+ } else {
+ return true;
+ }
+ }
+#else
+ return true;
+#endif
+}
+
bool typemapassertvalidmemoryB(struct typemap * thisvar, void* low, void* high) {
#ifdef CHECKMEMORY
return typemapcheckmemory(thisvar, low, high);
}
}
+void * typemapgetendofblock(struct typemap *thisvar, void* low) {
+ struct pair allocp=rbfind(low,((char*)low)+1,thisvar->alloctree);
+ if (allocp.low == NULL) {
+ return NULL;
+ } else if ((allocp.low > low)||(allocp.high <= allocp.low)) { /* make sure this block is used */
+ return NULL;
+ } else {
+ return (void *)allocp.high;
+ }
+}
+
bool typemapchecktype(struct typemap *thisvar, bool doaction,void *ptr, int structure) {
int ssize=sizeBytes(structure);