Index: Source/NSKeyValueCoding.m
===================================================================
--- Source/NSKeyValueCoding.m	(revision 25633)
+++ Source/NSKeyValueCoding.m	(working copy)
@@ -51,6 +51,10 @@
 NSString* const NSUndefinedKeyException = @"NSUnknownKeyException";
 
 
+/* this should move into autoconf once it's accepted */
+#define WANT_DEPRECATED_KVC_COMPAT 1
+
+
 static void
 SetValueForKey(NSObject *self, id anObject, const char *key, unsigned size)
 {
@@ -197,18 +201,26 @@
 }
 
 
-+ (BOOL) useStoredAccessor
-{
-  return YES;
-}
-
-
 - (NSDictionary*) dictionaryWithValuesForKeys: (NSArray*)keys
 {
   NSMutableDictionary	*dictionary;
   NSEnumerator		*enumerator;
   id			key;
+#ifdef WANT_DEPRECATED_KVC_COMPAT
+  static IMP	o = 0;
 
+  /* Backward compatibility hack */
+  if (o == 0)
+    {
+      o = [NSObject instanceMethodForSelector:
+	@selector(valuesForKeys:)];
+    }
+  if ([self methodForSelector: @selector(valuesForKeys:)] != o)
+    {
+      return [self valuesForKeys: keys];
+    }
+#endif
+
   dictionary = [NSMutableDictionary dictionaryWithCapacity: [keys count]];
   enumerator = [keys objectEnumerator];
   while ((key = [enumerator nextObject]) != nil)
@@ -224,35 +236,6 @@
   return dictionary;
 }
 
-- (id) handleQueryWithUnboundKey: (NSString*)aKey
-{
-  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
-    self, @"NSTargetObjectUserInfoKey",
-    (aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
-    nil];
-  NSException *exp = [NSException exceptionWithName: NSUndefinedKeyException
-				  reason: @"Unable to find value for key"
-				  userInfo: dict];
-
-  GSOnceMLog(@"This method is deprecated, use -valueForUndefinedKey:");
-  [exp raise];
-  return nil;
-}
-
-
-- (void) handleTakeValue: (id)anObject forUnboundKey: (NSString*)aKey
-{
-  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
-    (anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
-    (aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
-    nil];
-  NSException *exp = [NSException exceptionWithName: NSUndefinedKeyException
-				  reason: @"Unable to set value for key"
-				  userInfo: dict];
-  GSOnceMLog(@"This method is deprecated, use -setValue:forUndefinedKey:");
-  [exp raise];
-}
-
 - (NSMutableSet*) mutableSetValueForKey: (NSString*)aKey
 {
   return [NSKeyValueMutableSet setForKey: aKey ofObject: self];
@@ -329,6 +312,7 @@
 
 - (void) setNilValueForKey: (NSString*)aKey
 {
+#ifdef WANT_DEPRECATED_KVC_COMPAT
   static IMP	o = 0;
 
   /* Backward compatibility hack */
@@ -340,19 +324,34 @@
   if ([self methodForSelector: @selector(unableToSetNilForKey:)] != o)
     {
       [self unableToSetNilForKey: aKey];
+      return;
     }
-  else
-    {
-      [NSException raise: NSInvalidArgumentException
-        format: @"%@ -- %@ 0x%x: Given nil value to set for key \"%@\"",
-        NSStringFromSelector(_cmd), NSStringFromClass([self class]),
-        self, aKey];
-    }
+#endif
+  [NSException raise: NSInvalidArgumentException
+    format: @"%@ -- %@ 0x%x: Given nil value to set for key \"%@\"",
+    NSStringFromSelector(_cmd), NSStringFromClass([self class]),
+    self, aKey];
 }
 
 
 - (void) setValue: (id)anObject forKey: (NSString*)aKey
 {
+#ifdef WANT_DEPRECATED_KVC_COMPAT
+  static IMP	o = 0;
+
+  /* Backward compatibility hack */
+  if (o == 0)
+    {
+      o = [NSObject instanceMethodForSelector:
+  @selector(takeValue:forKey:)];
+    }
+  if ([self methodForSelector: @selector(takeValue:forKey:)] != o)
+    {
+      [self takeValue: anObject forKey: aKey];
+      return;
+    }
+#endif
+
   unsigned	size = [aKey length] * 8;
   char		key[size+1];
 
@@ -370,13 +369,28 @@
   char		buf[size+1];
   unsigned	start = 0;
   unsigned	end = 0;
-  id		o = self;
+  id		obj = self;
+#ifdef WANT_DEPRECATED_KVC_COMPAT
+  static IMP	o = 0;
 
+  /* Backward compatibility hack */
+  if (o == 0)
+    {
+      o = [NSObject instanceMethodForSelector:
+  @selector(takeValue:forKeyPath:)];
+    }
+  if ([self methodForSelector: @selector(takeValue:forKeyPath:)] != o)
+    {
+      [self takeValue: anObject forKeyPath: aKey];
+      return;
+    }
+#endif
+
   [aKey getCString: buf
 	 maxLength: size+1
 	  encoding: NSUTF8StringEncoding];
   size = strlen(buf);
-  while (o != nil)
+  while (obj != nil)
     {
       end = start;
       while (end < size && buf[end] != '.')
@@ -389,10 +403,10 @@
       AUTORELEASE(aKey);
       if (end >= size)
 	{
-	  [o setValue: anObject forKey: aKey];
+	  [obj setValue: anObject forKey: aKey];
 	  return;
 	}
-      o = [o valueForKey: aKey];
+      obj = [obj valueForKey: aKey];
       start = ++end;
     }
 }
@@ -402,6 +416,7 @@
 {
   NSDictionary	*dict;
   NSException	*exp; 
+#ifdef WANT_DEPRECATED_KVC_COMPAT
   static IMP	o = 0;
 
   /* Backward compatibility hack */
@@ -415,6 +430,7 @@
       [self handleTakeValue: anObject forUnboundKey: aKey];
       return;
     }
+#endif
 
   dict = [NSDictionary dictionaryWithObjectsAndKeys:
     (anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
@@ -429,9 +445,25 @@
 
 - (void) setValuesForKeysWithDictionary: (NSDictionary*)aDictionary
 {
-  NSEnumerator	*enumerator = [aDictionary keyEnumerator];
+  NSEnumerator	*enumerator;
   NSString	*key;
+#ifdef WANT_DEPRECATED_KVC_COMPAT
+  static IMP	o = 0;
 
+  /* Backward compatibility hack */
+  if (o == 0)
+    {
+      o = [NSObject instanceMethodForSelector:
+	@selector(takeValuesFromDictionary:)];
+    }
+  if ([self methodForSelector: @selector(takeValuesFromDictionary:)] != o)
+    {
+      [self takeValuesFromDictionary: aDictionary];
+      return;
+    }
+#endif
+
+  enumerator = [aDictionary keyEnumerator];
   while ((key = [enumerator nextObject]) != nil)
     {
       [self setValue: [aDictionary objectForKey: key] forKey: key];
@@ -439,6 +471,190 @@
 }
 
 
+- (BOOL) validateValue: (id*)aValue
+                forKey: (NSString*)aKey
+                 error: (NSError**)anError
+{
+  unsigned	size;
+
+  if (aValue == 0 || (size = [aKey length] * 8) == 0)
+    {
+      [NSException raise: NSInvalidArgumentException format: @"nil argument"];
+    }
+  else
+    {
+      char		name[size+16];
+      SEL		sel;
+      BOOL		(*imp)(id,SEL,id*,id*);
+
+      strcpy(name, "validate");
+      [aKey getCString: &name[8]
+	     maxLength: size+1
+	      encoding: NSUTF8StringEncoding];
+      size = strlen(&name[8]);
+      strcpy(&name[size+8], ":error:");
+      if (islower(name[8]))
+	{
+	  name[8] = toupper(name[8]);
+	}
+      sel = GSSelectorFromName(name);
+      if (sel != 0
+	&& (imp = (BOOL (*)(id,SEL,id*,id*))[self methodForSelector: sel]) != 0)
+	{
+	  return (*imp)(self, sel, aValue, anError);
+	}
+    }
+  return YES;
+}
+
+- (BOOL) validateValue: (id*)aValue
+            forKeyPath: (NSString*)aKey
+                 error: (NSError**)anError
+{
+  unsigned	size = [aKey length] * 8;
+  char		buf[size+1];
+  unsigned	start = 0;
+  unsigned	end = 0;
+  id		o = self;
+
+  [aKey getCString: buf
+	 maxLength: size+1
+	  encoding: NSUTF8StringEncoding];
+  size = strlen(buf);
+  while (o != nil)
+    {
+      end = start;
+      while (end < size && buf[end] != '.')
+	{
+	  end++;
+	}
+      if (end >= size)
+	{
+	  break;
+	}
+      aKey = [[NSString alloc] initWithBytes: buf + start
+				      length: end - start
+				    encoding: NSUTF8StringEncoding];
+      AUTORELEASE(aKey);
+      o = [o valueForKey: aKey];
+      start = ++end;
+    }
+  if (o == nil)
+    {
+      return NO;
+    }
+  else
+    {
+      char		name[end-start+16];
+      SEL		sel;
+      BOOL		(*imp)(id,SEL,id*,id*);
+
+      size = end - start;
+      strcpy(name, "validate");
+      strcpy(&name[8], buf+start);
+      strcpy(&name[size+8], ":error:");
+      if (islower(name[8]))
+	{
+	  name[8] = toupper(name[8]);
+	}
+      sel = GSSelectorFromName(name);
+      if (sel != 0
+	&& (imp = (BOOL (*)(id,SEL,id*,id*))[self methodForSelector: sel]) != 0)
+	{
+	  return (*imp)(self, sel, aValue, anError);
+	}
+      return YES;
+    }
+}
+
+
+- (id) valueForKey: (NSString*)aKey
+{
+  unsigned	size = [aKey length] * 8;
+  char		key[size+1];
+
+  [aKey getCString: key
+	 maxLength: size+1
+	  encoding: NSUTF8StringEncoding];
+  size = strlen(key);
+  return ValueForKey(self, key, size);
+}
+
+
+- (id) valueForKeyPath: (NSString*)aKey
+{
+  unsigned	size = [aKey length] * 8;
+  char		buf[size+1];
+  unsigned	start = 0;
+  unsigned	end = 0;
+  id		o = self;
+
+  [aKey getCString: buf
+	 maxLength: size+1
+	  encoding: NSUTF8StringEncoding];
+  size = strlen(buf);
+  while (start < size && o != nil)
+    {
+      end = start;
+      while (end < size && buf[end] != '.')
+	{
+	  end++;
+	}
+      aKey = [[NSString alloc] initWithBytes: buf + start
+				      length: end - start
+				    encoding: NSUTF8StringEncoding];
+      AUTORELEASE(aKey);
+      o = [o valueForKey: aKey];
+      start = ++end;
+    }
+  return o;
+}
+
+
+- (id) valueForUndefinedKey: (NSString*)aKey
+{
+  NSDictionary	*dict;
+  NSException	*exp;
+  NSString *reason;
+
+#ifdef WANT_DEPRECATED_KVC_COMPAT
+  static IMP	o = 0;
+
+  /* Backward compatibility hack */
+  if (o == 0)
+    {
+      o = [NSObject instanceMethodForSelector:
+	@selector(handleQueryWithUnboundKey:)];
+    }
+  if ([self methodForSelector: @selector(handleQueryWithUnboundKey:)] != o)
+    {
+      return [self handleQueryWithUnboundKey: aKey];
+    }
+#endif
+  dict = [NSDictionary dictionaryWithObjectsAndKeys:
+    self, @"NSTargetObjectUserInfoKey",
+    (aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
+    nil];
+  reason = [NSString stringWithFormat:
+    @"Unable to find value for key \"%@\" of object %@ (%@)",
+    aKey, self, [self class]];
+  exp = [NSException exceptionWithName: NSUndefinedKeyException
+				reason: reason
+			      userInfo: dict];
+
+  [exp raise];
+  return nil;
+}
+
+
+#ifdef WANT_DEPRECATED_KVC_COMPAT
+
++ (BOOL) useStoredAccessor
+{
+  return YES;
+}
+
+
 - (id) storedValueForKey: (NSString*)aKey
 {
   unsigned	size;
@@ -615,7 +831,36 @@
     }
 }
 
+- (id) handleQueryWithUnboundKey: (NSString*)aKey
+{
+  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
+    self, @"NSTargetObjectUserInfoKey",
+    (aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
+    nil];
+  NSException *exp = [NSException exceptionWithName: NSUndefinedKeyException
+				  reason: @"Unable to find value for key"
+				  userInfo: dict];
 
+  GSOnceMLog(@"This method is deprecated, use -valueForUndefinedKey:");
+  [exp raise];
+  return nil;
+}
+
+
+- (void) handleTakeValue: (id)anObject forUnboundKey: (NSString*)aKey
+{
+  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
+    (anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
+    (aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
+    nil];
+  NSException *exp = [NSException exceptionWithName: NSUndefinedKeyException
+				  reason: @"Unable to set value for key"
+				  userInfo: dict];
+  GSOnceMLog(@"This method is deprecated, use -setValue:forUndefinedKey:");
+  [exp raise];
+}
+
+
 - (void) takeValue: (id)anObject forKey: (NSString*)aKey
 {
   SEL		sel = 0;
@@ -721,179 +966,6 @@
 }
 
 
-- (BOOL) validateValue: (id*)aValue
-                forKey: (NSString*)aKey
-                 error: (NSError**)anError
-{
-  unsigned	size;
-
-  if (aValue == 0 || (size = [aKey length] * 8) == 0)
-    {
-      [NSException raise: NSInvalidArgumentException format: @"nil argument"];
-    }
-  else
-    {
-      char		name[size+16];
-      SEL		sel;
-      BOOL		(*imp)(id,SEL,id*,id*);
-
-      strcpy(name, "validate");
-      [aKey getCString: &name[8]
-	     maxLength: size+1
-	      encoding: NSUTF8StringEncoding];
-      size = strlen(&name[8]);
-      strcpy(&name[size+8], ":error:");
-      if (islower(name[8]))
-	{
-	  name[8] = toupper(name[8]);
-	}
-      sel = GSSelectorFromName(name);
-      if (sel != 0
-	&& (imp = (BOOL (*)(id,SEL,id*,id*))[self methodForSelector: sel]) != 0)
-	{
-	  return (*imp)(self, sel, aValue, anError);
-	}
-    }
-  return YES;
-}
-
-- (BOOL) validateValue: (id*)aValue
-            forKeyPath: (NSString*)aKey
-                 error: (NSError**)anError
-{
-  unsigned	size = [aKey length] * 8;
-  char		buf[size+1];
-  unsigned	start = 0;
-  unsigned	end = 0;
-  id		o = self;
-
-  [aKey getCString: buf
-	 maxLength: size+1
-	  encoding: NSUTF8StringEncoding];
-  size = strlen(buf);
-  while (o != nil)
-    {
-      end = start;
-      while (end < size && buf[end] != '.')
-	{
-	  end++;
-	}
-      if (end >= size)
-	{
-	  break;
-	}
-      aKey = [[NSString alloc] initWithBytes: buf + start
-				      length: end - start
-				    encoding: NSUTF8StringEncoding];
-      AUTORELEASE(aKey);
-      o = [o valueForKey: aKey];
-      start = ++end;
-    }
-  if (o == nil)
-    {
-      return NO;
-    }
-  else
-    {
-      char		name[end-start+16];
-      SEL		sel;
-      BOOL		(*imp)(id,SEL,id*,id*);
-
-      size = end - start;
-      strcpy(name, "validate");
-      strcpy(&name[8], buf+start);
-      strcpy(&name[size+8], ":error:");
-      if (islower(name[8]))
-	{
-	  name[8] = toupper(name[8]);
-	}
-      sel = GSSelectorFromName(name);
-      if (sel != 0
-	&& (imp = (BOOL (*)(id,SEL,id*,id*))[self methodForSelector: sel]) != 0)
-	{
-	  return (*imp)(self, sel, aValue, anError);
-	}
-      return YES;
-    }
-}
-
-
-- (id) valueForKey: (NSString*)aKey
-{
-  unsigned	size = [aKey length] * 8;
-  char		key[size+1];
-
-  [aKey getCString: key
-	 maxLength: size+1
-	  encoding: NSUTF8StringEncoding];
-  size = strlen(key);
-  return ValueForKey(self, key, size);
-}
-
-
-- (id) valueForKeyPath: (NSString*)aKey
-{
-  unsigned	size = [aKey length] * 8;
-  char		buf[size+1];
-  unsigned	start = 0;
-  unsigned	end = 0;
-  id		o = self;
-
-  [aKey getCString: buf
-	 maxLength: size+1
-	  encoding: NSUTF8StringEncoding];
-  size = strlen(buf);
-  while (start < size && o != nil)
-    {
-      end = start;
-      while (end < size && buf[end] != '.')
-	{
-	  end++;
-	}
-      aKey = [[NSString alloc] initWithBytes: buf + start
-				      length: end - start
-				    encoding: NSUTF8StringEncoding];
-      AUTORELEASE(aKey);
-      o = [o valueForKey: aKey];
-      start = ++end;
-    }
-  return o;
-}
-
-
-- (id) valueForUndefinedKey: (NSString*)aKey
-{
-  NSDictionary	*dict;
-  NSException	*exp;
-  static IMP	o = 0;
-  NSString *reason;
-
-  /* Backward compatibility hack */
-  if (o == 0)
-    {
-      o = [NSObject instanceMethodForSelector:
-	@selector(handleQueryWithUnboundKey:)];
-    }
-  if ([self methodForSelector: @selector(handleQueryWithUnboundKey:)] != o)
-    {
-      return [self handleQueryWithUnboundKey: aKey];
-    }
-  dict = [NSDictionary dictionaryWithObjectsAndKeys:
-    self, @"NSTargetObjectUserInfoKey",
-    (aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
-    nil];
-  reason = [NSString stringWithFormat:
-    @"Unable to find value for key \"%@\" of object %@ (%@)",
-    aKey, self, [self class]];
-  exp = [NSException exceptionWithName: NSUndefinedKeyException
-				reason: reason
-			      userInfo: dict];
-
-  [exp raise];
-  return nil;
-}
-
-
 - (NSDictionary*) valuesForKeys: (NSArray*)keys
 {
   NSMutableDictionary	*dict;
@@ -901,6 +973,7 @@
   unsigned		count = [keys count];
   unsigned		pos;
 
+  GSOnceMLog(@"This method is deprecated, use -dictionaryWithValuesForKeys:");
   dict = [NSMutableDictionary dictionaryWithCapacity: count];
   for (pos = 0; pos < count; pos++)
     {
@@ -916,5 +989,7 @@
   return AUTORELEASE([dict copy]);
 }
 
+#endif
+
 @end
 
