[Rubycocoa-devel 842] OverrideMixin.m imp_setValue_forUndefinedKey doesn't handle null values

Back to archive index

Jacob Wallström jacob****@ghost*****
Thu Apr 12 05:27:37 JST 2007


Hi,

I have a situation when I'm using bindings and a bound value is being  
set to nil in the GUI. This leads to a crash in  
imp_setValue_forUndefinedKey:270, using revision 1704 from trunk:

NSInvalidArgumentException - *** -[NSCFDictionary setObject:forKey:]:  
attempt to insert nil value (OSX::OCException)

This was working in 0.4.3d2. Below is the method in question:

static void imp_setValue_forUndefinedKey (id rcv, SEL method, id  
value, NSString* key)
{
   id slave = get_slave(rcv);
   id dict;

   if (value == NULL)
	return;
   /* In order to avoid ObjC values to be autorelease'd while they  
are still proxied in the
      Ruby world, we keep them in an internal hash. */
   if (object_getInstanceVariable(rcv, "__rb_kvc_dict__", (void *) 
&dict) == NULL) {
     dict = [[NSMutableDictionary alloc] init];
     object_setInstanceVariable(rcv, "__rb_kvc_dict__", dict);
   }

   if ([slave respondsToSelector: @selector(rbSetValue:forKey:)]) {
     [slave performSelector: @selector(rbSetValue:forKey:)  
withObject: value withObject: key];
     [dict setObject:value forKey:key];    /** CRASHES HERE **/
   }
   else
     [rcv performSelector: super_selector(method) withObject: value  
withObject: key];
}

I don't know much about this stuff but thanks to the helpful comment  
I thought that simply skipping nil values might do the trick. And it  
seems that it does. Below is my patch:

$ svn diff
Index: src/objc/OverrideMixin.m
===================================================================
--- src/objc/OverrideMixin.m    (revision 1704)
+++ src/objc/OverrideMixin.m    (working copy)
@@ -258,6 +258,8 @@
    id slave = get_slave(rcv);
    id dict;
+  if (value == NULL)
+       return;
    /* In order to avoid ObjC values to be autorelease'd while they  
are still proxied in the
       Ruby world, we keep them in an internal hash. */
    if (object_getInstanceVariable(rcv, "__rb_kvc_dict__", (void *) 
&dict) == NULL) {

Best regards,
Jacob Wallström
http://ghostparksoftware.com




More information about the Rubycocoa-devel mailing list
Back to archive index