[MacRuby-devel] NSNumber Numeric Patch

Jonathan deWerd jjoonathan at gmail.com
Fri Nov 28 19:08:48 PST 2008


Hi!
I was tracking down a bug in my app that caused a crash, and I finally  
narrowed it down to the conversion between NSNumber and the Numeric  
types. I don't think that was the direct cause of the crash (the  
immediate cause was a longjmp to a nonexistant "thread"), but manually  
converting it via to_i made it work just fine. In the spirit of "if  
it's worth doing once, it's worth automating" I wrote some code that  
patches NSNumber itself to act more like a a Numeric. You can now mix  
it in just about anywhere, with bignums and floats and ints and it  
should all Just Work.

This patch doesn't replace any ruby Numeric machinery, it just adds a  
bit of sugar to the bridge.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: numeric.c.patch
Type: application/octet-stream
Size: 18779 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20081128/00155139/attachment.obj>
-------------- next part --------------



I didn't write any formal test cases for it since I was hoping a  
greater ruby mind than I could figure out an easy way to subvert the  
Numeric test cases to my purposes :)
I would love for anyone experienced with boundary conditions to take a  
look at it. I think I got just about everything, but an awful lot of  
hackery goes on with ruby's numeric types, so a second opinion would  
be most welcome.

Thanks to everyone here working on macruby, you've done an amazing  
job. It's a very worthy successor to rubycocoa :)

PS
While you're applying patches, I've got another quick one in a ticket  
that deals with macruby_main and absolute paths: http://www.macruby.org/trac/ticket/163

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1748 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20081128/00155139/attachment.bin>


More information about the MacRuby-devel mailing list