Skip to content
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

Closed
andypotion opened this issue Apr 8, 2011 · 9 comments
Closed

Cannot serialize integers in Mac OS X 10.7 #15

andypotion opened this issue Apr 8, 2011 · 9 comments

Comments

@andypotion
Copy link

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.

@johnezang
Copy link
Owner

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.

@johnezang
Copy link
Owner

This is likely a duplicate of issue #9.

@ghost ghost assigned johnezang May 21, 2011
@snej
Copy link

snej commented Jul 17, 2011

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.

@snej
Copy link

snej commented Jul 22, 2011

Now that Lion is no longer under NDA, could someone please post the workaround as a patch?

@hiltonc
Copy link

hiltonc commented Jul 22, 2011

I'm also running into this problem. Anyone have a fix?

@snej
Copy link

snej commented Jul 22, 2011

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.

@0xced
Copy link

0xced commented Jul 23, 2011

I guess that Tagged pointers and fast-pathed CFNumber integers in Lion is the cause of this problem.

@andypotion
Copy link
Author

I just submitted a pull request for this. People needing the fix ASAP should check out my fork.

johnezang added a commit that referenced this issue Sep 23, 2011
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.
@johnezang
Copy link
Owner

Fixed in commit c2ef692.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants