From 206e9d65a486e7f01e9fe32b2ef66bc4b0c22798 Mon Sep 17 00:00:00 2001
From: Matthias Andreas Benkard <matthias@benkard.de>
Date: Fri, 13 Jun 2008 23:20:02 +0200
Subject: Override -dealloc in every class.

---
 MLKCons.h                       |  2 ++
 MLKCons.m                       |  8 +++++++-
 MLKDynamicContext.h             |  6 ++++--
 MLKDynamicContext.m             | 15 +++++++++++++--
 MLKEnvironment.h                |  2 ++
 MLKEnvironment.m                |  7 +++++++
 MLKLinkedList.h                 |  2 ++
 MLKLinkedList.m                 |  6 ++++++
 MLKLowLevelTests.m              |  2 +-
 MLKSymbol.h                     |  2 ++
 MLKSymbol.m                     |  8 +++++++-
 MLKThrowException.h             |  2 ++
 MLKThrowException.m             | 11 +++++++++--
 MLKUndefinedVariableException.h |  2 ++
 MLKUndefinedVariableException.m |  7 +++++++
 15 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/MLKCons.h b/MLKCons.h
index 4430275..a278e98 100644
--- a/MLKCons.h
+++ b/MLKCons.h
@@ -18,4 +18,6 @@
 -(id) cdr;
 -(void) setCar:(id)value;
 -(void) setCdr:(id)value;
+
+-(void) dealloc;
 @end
diff --git a/MLKCons.m b/MLKCons.m
index e9e6360..f1db7e6 100644
--- a/MLKCons.m
+++ b/MLKCons.m
@@ -37,5 +37,11 @@
 {
   ASSIGN (_cdr, value);
 }
-@end
 
+-(void) dealloc
+{
+  RELEASE (_car);
+  RELEASE (_cdr);
+  [super dealloc];
+}
+@end
diff --git a/MLKDynamicContext.h b/MLKDynamicContext.h
index ba67ad8..8dc1a2f 100644
--- a/MLKDynamicContext.h
+++ b/MLKDynamicContext.h
@@ -4,12 +4,12 @@
 @class MLKClosure, MLKEnvironment, NSLinkedList, NSMutableDictionary, NSString;
 
 
-@interface MLKDynamicContext
+@interface MLKDynamicContext : NSObject
 {
   MLKEnvironment *_conditionHandlers;
   MLKEnvironment *_restarts;
   MLKEnvironment *_catchTags;
-  MLKClosure *_currentConditionHandler;
+  MLKClosure *_currentConditionHandler;  // needed for the Condition Firewall
   MLKEnvironment *_environment;
   MLKDynamicContext *_parent;
 }
@@ -25,4 +25,6 @@
 
 +(MLKDynamicContext *) currentContext;
 +(MLKDynamicContext *) popContext;
+
+-(void) dealloc;
 @end
diff --git a/MLKDynamicContext.m b/MLKDynamicContext.m
index ed4357a..7be5748 100644
--- a/MLKDynamicContext.m
+++ b/MLKDynamicContext.m
@@ -17,7 +17,7 @@
                             ? (id) parent_member                        \
                             : nil)                                      \
                   bindings:vars]                                        \
-   : (id) (parent ? (id) parent_member : nil));
+   : (id) (parent ? (id) RETAIN (parent_member) : nil));
 
 
 @implementation MLKDynamicContext
@@ -28,7 +28,7 @@
                             catchTags:(NSDictionary *)catchTags
                        currentHandler:(MLKClosure *)handler
 {
-  _parent = (aContext ? aContext : [MLKDynamicContext currentContext]);
+  ASSIGN (_parent, (aContext ? aContext : [MLKDynamicContext currentContext]));
   _environment = MAKE_ENVIRONMENT(vars, _parent, _parent->_environment);
   _conditionHandlers = MAKE_ENVIRONMENT(handlers,
                                         _parent,
@@ -62,4 +62,15 @@
                                                forKey:@"MLKDynamicContext"];
   return context;
 }
+
+-(void) dealloc
+{
+  RELEASE (_conditionHandlers);
+  RELEASE (_restarts);
+  RELEASE (_catchTags);
+  RELEASE (_currentConditionHandler);
+  RELEASE (_environment);
+  RELEASE (_parent);
+  [super dealloc];
+}
 @end
diff --git a/MLKEnvironment.h b/MLKEnvironment.h
index b40ea5a..cda8576 100644
--- a/MLKEnvironment.h
+++ b/MLKEnvironment.h
@@ -25,4 +25,6 @@
 // Private methods.
 -(void) setBinding:(MLKSymbol *)symbol to:(id)value inEnvironment:(MLKEnvironment *)env;
 -(id) valueForBinding:(MLKSymbol *)symbol inEnvironment:(MLKEnvironment *)env;
+
+-(void) dealloc;
 @end
diff --git a/MLKEnvironment.m b/MLKEnvironment.m
index 6df4e11..0da3a14 100644
--- a/MLKEnvironment.m
+++ b/MLKEnvironment.m
@@ -79,4 +79,11 @@
 {
   [_bindings setObject:value forKey:symbol];
 }
+
+-(void) dealloc
+{
+  RELEASE (_bindings);
+  RELEASE (_parent);
+  [super dealloc];
+}
 @end
diff --git a/MLKLinkedList.h b/MLKLinkedList.h
index 70e4604..67e8ba0 100644
--- a/MLKLinkedList.h
+++ b/MLKLinkedList.h
@@ -23,4 +23,6 @@
 #ifdef __OBJC2__
 -(NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
 #endif
+
+-(void) dealloc;
 @end
diff --git a/MLKLinkedList.m b/MLKLinkedList.m
index 40174e0..3f047a0 100644
--- a/MLKLinkedList.m
+++ b/MLKLinkedList.m
@@ -61,4 +61,10 @@
     return 0;
 }
 #endif
+
+-(void) dealloc
+{
+  RELEASE (_firstCons);
+  [super dealloc];
+}
 @end
diff --git a/MLKLowLevelTests.m b/MLKLowLevelTests.m
index 1de05ff..c47fd2a 100644
--- a/MLKLowLevelTests.m
+++ b/MLKLowLevelTests.m
@@ -38,7 +38,7 @@
 -(id) testCons
 {
   id obj1 = @"Mulk.";
-  id obj2 = [[NSMutableDictionary alloc] init];
+  id obj2 = AUTORELEASE ([[NSMutableDictionary alloc] init]);
 
   MLKCons *cons2 = [MLKCons cons:obj1 with:obj2];
   MLKCons *cons3 = [MLKCons cons:obj1 with:nil];
diff --git a/MLKSymbol.h b/MLKSymbol.h
index e239c67..d048451 100644
--- a/MLKSymbol.h
+++ b/MLKSymbol.h
@@ -17,4 +17,6 @@
 -(NSString *) name;
 -(MLKPackage *) homePackage;
 -(void) setHomePackage:(MLKPackage *)aPackage;
+
+-(void) dealloc;
 @end
diff --git a/MLKSymbol.m b/MLKSymbol.m
index 6d19323..6ef0411 100644
--- a/MLKSymbol.m
+++ b/MLKSymbol.m
@@ -26,5 +26,11 @@
 {
   ASSIGN (homePackage, aPackage);
 }
-@end
 
+-(void) dealloc
+{
+  RELEASE (name);
+  RELEASE (homePackage);
+  [super dealloc];
+}
+@end
diff --git a/MLKThrowException.h b/MLKThrowException.h
index 567cbcc..32e39c8 100644
--- a/MLKThrowException.h
+++ b/MLKThrowException.h
@@ -17,4 +17,6 @@
 
 -(MLKSymbol *) catchTag;
 -(id) value;
+
+-(void) dealloc;
 @end
diff --git a/MLKThrowException.m b/MLKThrowException.m
index 799db7e..e3f3e0c 100644
--- a/MLKThrowException.m
+++ b/MLKThrowException.m
@@ -8,8 +8,8 @@
 -(MLKThrowException *) initWithCatchTag:(MLKSymbol *)catchTag
                                   value:(id)value
 {
-  _catchTag = catchTag;
-  _value = value;
+  ASSIGN (_catchTag, catchTag);
+  ASSIGN (_value, value);
   return self;
 }
 
@@ -22,4 +22,11 @@
 {
   return _value;
 }
+
+-(void) dealloc
+{
+  RELEASE (_catchTag);
+  RELEASE (_value);
+  [super dealloc];
+}
 @end
diff --git a/MLKUndefinedVariableException.h b/MLKUndefinedVariableException.h
index 16005ce..d373656 100644
--- a/MLKUndefinedVariableException.h
+++ b/MLKUndefinedVariableException.h
@@ -14,4 +14,6 @@
 
 -(MLKUndefinedVariableException *) initWithEnvironment:(id)environment
                                           variableName:(id)symbol;
+
+-(void) dealloc;
 @end
diff --git a/MLKUndefinedVariableException.m b/MLKUndefinedVariableException.m
index 531a394..5795b55 100644
--- a/MLKUndefinedVariableException.m
+++ b/MLKUndefinedVariableException.m
@@ -12,4 +12,11 @@
   environment = anEnvironment;
   return self;
 }
+
+-(void) dealloc
+{
+  RELEASE (variableName);
+  RELEASE (environment);
+  [super dealloc];
+}
 @end
-- 
cgit v1.2.3