return flag to indicate errors
[repair.git] / Repair / RepairCompiler / MCC / CRuntime / tmap.c
index 22333fd1570927e8c773944ab8207937f7da12d7..6cf599a495ea6fe2892a846d3cf0436059efbf9b 100755 (executable)
@@ -4,20 +4,26 @@
 #include "stack.h"
 #include <stdlib.h>
 
+#ifndef COMMANDLINEFLAGS
 #define CHECKTYPE
 #define CHECKMEMORY
+#endif
 
 struct typemap * allocatetypemap() {
+#ifdef CHECKTYPE||CHECKMEMORY
   struct typemap *thisvar=(struct typemap *) malloc(sizeof(struct typemap));
   thisvar->alloctree=rbinit();
   thisvar->typetree=rbinit();
   thisvar->low=GC_linux_stack_base();
   return thisvar;
+#else
+  return NULL;
+#endif
 }
 
 void freefunction(void *ptr) {
   if(ptr!=NULL) {
-    free((struct structuremap *)ptr);
+    freestructuremap((struct structuremap *)ptr);
   }
 }
 
@@ -28,20 +34,24 @@ void freetypemap(struct typemap * ptr) {
 }
 
 void typemapreset(struct typemap *ptr) {
+#ifdef CHECKTYPE||CHECKMEMORY
   rbdestroy(ptr->typetree,freefunction);
   ptr->typetree=rbinit();
   if (ptr->low<ptr->high)
     rbdelete(ptr->low,ptr->alloctree);
   else
     rbdelete(ptr->high,ptr->alloctree);
+#endif
 }
 
 void initializetypemapstack(struct typemap * ptr, void *high) {
+#ifdef CHECKTYPE||CHECKMEMORY
   ptr->high=high;
   if (ptr->low<ptr->high)
     rbinsert(ptr->low,ptr->high,NULL,ptr->alloctree);
   else
     rbinsert(ptr->high,ptr->low,NULL,ptr->alloctree);
+#endif
 }
 
 struct structuremap * allocatestructuremap(int s) {
@@ -80,6 +90,26 @@ bool typemapassertvalidmemory(struct typemap * thisvar, void* low, int s) {
   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);
@@ -161,6 +191,17 @@ bool typemapcheckmemory(struct typemap *thisvar, void* low, void* 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);