changeset 102:14d96c95dd56

Moved the malloc debugging code to the dynamic program file The malloc debugging code should not be in the library, it is now solely in the program that exists to debug the functions I added a few TODOs to std.c
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sun, 29 May 2011 19:35:17 -0400
parents 6f81e6ae3f64
children 963bed9f5592
files include/std.h src/dynamic.c src/std.c
diffstat 3 files changed, 32 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/include/std.h	Mon May 23 08:56:13 2011 -0400
+++ b/include/std.h	Sun May 29 19:35:17 2011 -0400
@@ -40,7 +40,5 @@
 void malloc_init(size_t memSize);
 void* malloc(size_t size);
 void free(void *ptr);
-void printHeader(Header* head);
-void printMem();
 
 #endif
--- a/src/dynamic.c	Mon May 23 08:56:13 2011 -0400
+++ b/src/dynamic.c	Sun May 29 19:35:17 2011 -0400
@@ -6,6 +6,34 @@
 #include <string.h>
 #include <stack.h>
 
+//This are simple debug functions for the memory
+
+void printHeader(Header* head)
+{
+	char buffer[20];
+	sPrint("Memory address is: ");
+	sPrint(itoa((intptr_t)head, buffer, 16));
+	sPrint("\n");
+	sPrint("The size of the block is: ");
+	sPrint(itoa(head->size, buffer, 10));
+	sPrint("\n");
+	sPrint("Next memory address is: ");
+	sPrint(itoa((intptr_t)head->next, buffer, 16));
+	sPrint("\n\n");
+}
+
+void printMem()
+{
+	Header *start = malloc(0);
+	Header *cur = start - 1; //this will be a block in the memory
+	free(start--);
+	do {
+		printHeader(cur);
+		cur = cur->next;
+	} while(cur != start);
+	sPrint("PRINTOUT DONE\n\n");
+}
+
 void dumpBuffer(char *a, int b)
 {
 	int i;
--- a/src/std.c	Mon May 23 08:56:13 2011 -0400
+++ b/src/std.c	Sun May 29 19:35:17 2011 -0400
@@ -118,14 +118,14 @@
 	char *b = a;
 	while(*b && *++b);
 	do {
-		putline(a, (b - a > CON_LEN)?CON_LEN:(b - a));
+		putline(a, (b - a > CON_LEN)?CON_LEN:(b - a)); //TODO supervisor call
 		a += CON_LEN;
 	} while(a < b);
 }
 
 char* sGet(char *a, unsigned int n)
 {
-	int length = getline(a, n);
+	int length = getline(a, n); //TODO supervisor call
 	a[(length < n)?length:n - 1] = '\0';
 	return a;
 }
@@ -135,7 +135,7 @@
 static Header base;
 static Header *allocp = NULL; //the location of the last known free block
 
-void malloc_init(size_t memSize)
+void malloc_init(size_t memSize) //TODO get rid of this
 {
 	allocp = &base;
 	allocp->size = 0;
@@ -167,6 +167,7 @@
 			allocp = prev;
 			return (void*)(cur + 1);
 		} else if(cur == allocp) { //We went back to the start...
+			//TODO ask the OS for more momory
 			return NULL;
 		}
 	}
@@ -190,27 +191,3 @@
 		toFree->next = toFree->next->next;
 	}
 }
-
-void printHeader(Header* head)
-{
-	char buffer[20];
-	sPrint("Memory address is: ");
-	sPrint(itoa((intptr_t)head, buffer, 16));
-	sPrint("\n");
-	sPrint("The size of the block is: ");
-	sPrint(itoa(head->size, buffer, 10));
-	sPrint("\n");
-	sPrint("Next memory address is: ");
-	sPrint(itoa((intptr_t)head->next, buffer, 16));
-	sPrint("\n\n");
-}
-
-void printMem()
-{
-	Header *cur = allocp;
-	do {
-		printHeader(cur);
-		cur = cur->next;
-	} while(cur != allocp);
-	sPrint("PRINTOUT DONE\n\n");
-}