[Rubycocoa-devel 843] Re: OverrideMixin.m imp_setValue_forUndefinedKey doesn't handle null values

Zurück zum Archiv-Index

Laurent Sansonetti lsans****@apple*****
Thu Apr 12 05:30:30 JST 2007


Jacob, that's very funny because Benjamin just reported me the same  
problem and I just committed a fix a few seconds ago (with r1705) :-)

It would be great if you could svn update and see if the problem has  
been fixed.

Thanks,
Laurent

On Apr 11, 2007, at 10:27 PM, Jacob Wallström wrote:

> 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
>
> _______________________________________________
> Rubycocoa-devel mailing list
> Rubyc****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel




More information about the Rubycocoa-devel mailing list
Zurück zum Archiv-Index