-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot serialize integers in Mac OS X 10.7 #15
Comments
After working with Andy on this bug (thanks @andypotion!), we were able to determine the cause of the problem. However, since this is a bug that is specific to Mac OS X 10.7 / Lion, there are various NDA issues involved in discussing the problem publicly. A work-around is known, but there's a legitimate question as to whether or not this is a bug in JSONKit or not. It's not clear if the work around should be checked in or if the problem should be resolved "up stream" from JSONKit, so to speak. |
This is likely a duplicate of issue #9. |
JSONKit is groping into an NSNumber object to dereference the 'isa' field. As far as I know this is not kosher since it makes assumptions about object memory layout that Apple could change in future OS versions, including Lion. I don't think you can assign blame upstream to Foundation. This is probably faster than using the Obj-C runtime API to look up the class, but I don't think you can continue to do it, at least not in these hypothetical future OS versions/configurations where Apple may or may not have changed the layout of certain objects. You might need to use #ifdefs to fall back to safer, if slower, techniques. |
Now that Lion is no longer under NDA, could someone please post the workaround as a patch? |
I'm also running into this problem. Anyone have a fix? |
My current workaround is to use NSJSONSerialization instead, when it's available. I do a runtime check to look up the class by name, and then call it if it's there instead of JSONKit. |
I guess that Tagged pointers and fast-pathed CFNumber integers in Lion is the cause of this problem. |
I just submitted a pull request for this. People needing the fix ASAP should check out my fork. |
This commit implements a work around for a bug in 10.7 that was caused by a 10.7 64-bit ABI breaking change. Technically, this is not a bug in JSONKit, but with Mac OS X. When making changes to the ABI, it is (at least de facto) required to bump the "major version" of a shared library so that code designed around and built against the "guarantees" provided by previous versions ABI / API are not violated. Not only was this not done in 10.7, the ABI breaking change isn't even officially documented (to the best of my knowledge). It's certainly not mentioned in the 10.7 release notes.
Fixed in commit c2ef692. |
The following code will crash in Mac OS X Lion Developer Preview 2:
[[NSArray arrayWithObject:[NSNumber numberWithInteger:1]] JSONString]
The crash happens when you try to get the isa value for the number object because they seem to be optimized special pointers in the runtime now.
The text was updated successfully, but these errors were encountered: