johnezang / JSONKit

Objective-C JSON
6.21k stars 1.66k forks source link

Fix "Bitmasking for introspection of Objective-C object pointers is strongly discouraged" warning in Xcode 5 #133

Open roustem opened 11 years ago

roustem commented 11 years ago

.../JSONKit/JSONKit.m:2600:77: warning: bitmasking for introspection of Objective-C object pointers is strongly discouraged [-Wdeprecated-objc-pointer-introspection] BOOL workAroundMacOSXABIBreakingBug = (JK_EXPECT_F(((NSUInteger)object) & 0x1)) ? YES : NO;


.../JSONKit/JSONKit.m:199:53: note: expanded from macro 'JK_EXPECT_F'
# define JK_EXPECT_F(cond)               JK_EXPECTED(cond, 0U)

```
                                                ^
```

.../JSONKit/JSONKit.m:197:65: note: expanded from macro 'JK_EXPECTED'
# define JK_EXPECTED(cond, expect)       __builtin_expect((long)(cond), (expect))
johnz2 commented 11 years ago

+1

mikeabdullah commented 11 years ago

We (@karelia) would appreciate this being fixed too

jdberry commented 11 years ago

+1

mralexgray commented 11 years ago

+1

Oh, btw, you can shut this up, like so...

#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection" BOOL workAroundMacOSXABIBreakingBug = (JK_EXPECT_F(((NSUInteger)object) & 0x1)) ? YES : NO; #pragma clang diagnostic pop

jslicari commented 11 years ago

+1

WeeTom commented 11 years ago

+1

vjacheslav-volodko commented 11 years ago

+1

odyth commented 11 years ago

For iOS apps I just commented that line out and it hasnt had any negative impact on my app as far as i can tell. Been in production for about 6 months now.

coveloper commented 11 years ago

+1

ramakula commented 11 years ago

+1

demodit commented 11 years ago

+1

mmcer commented 11 years ago

@roustem ,what about (JK_EXPECT_F(((NSUInteger)object) % 2)) ?

vchav73 commented 11 years ago

If you're using JSONKit I suggest you consider migrating to Apple's NSJSONSerialization. It does what JSONKit does, but according to the article below it's faster. Unlike JSONKit, it's also being maintained. The only downside I'm aware of is that it's only available in iOS 5+ / OS X 10.7+.

http://stackoverflow.com/questions/16218583/jsonkit-benchmarks

abhibeckert commented 11 years ago

@vchav73 it's also not entirely clear it's faster. That test you linked to only showed a slight performance difference and was run in the simulator, so complied for x86 instead of ARM.

There is also another comment that NSJSONSerialization is only fast on iOS 6, not 5. On 5 it was definitely too slow.

Since I'm decoding megabytes of JSON at a time, it's pretty important to me... when I get a chance I'll test it out and post an update here. Unless someone else beats me to it.

jslicari commented 11 years ago

In my experience NSJSONSerialization can be a bit buggy on iOS 5. I have definite cases of perfectly valid JSON that crap out on iOS 5 (produce a nil result) but work fine on iOS 6. So if your app is does not need to support iOS 5 or less I would say definitely migrate to NSJSONSerialization. Otherwise I would keep using JSONKit.

And if you really want to get rid of the JSONKit warning, I found that just putting these #pragma statements around the offending line does the trick:

pragma clang diagnostic push

pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection"

BOOL workAroundMacOSXABIBreakingBug = (JK_EXPECT_F(((NSUInteger)object) & 0x1)) ? YES : NO;

pragma clang diagnostic pop

vchav73 commented 11 years ago

Thanks for the warnings about NSJSONSerialization on iOS 5.x. I ran some quick benchmarks (JSONKit vs NSJSONSerialization) on both an iPhone 3GS using iOS 5.1.1 and an iPad 2 using iOS 6.1.3 using the repo at this link: https://github.com/bontoJR/iOS-JSON-Performance

Seems, generally speaking, JSONKit is faster in iOS 5 while NSJSONSerialization is faster in iOS 6.

iPhone 3GS iOS 5.1.1: iphone3gs_ios5 1 1

iPad 2 iOS 6.1.3 ipad2_ios6 1 3

Bo98 commented 11 years ago

Yep, probably even more so in iOS 7.

vchav73 commented 11 years ago

I'll add iOS 7 to the mix once it's released. Based on this (and the comment about NSJSONSerialization being buggy in 5.x) I'll be using NSJSONSerialization for iOS 6 and JSONKit for iOS 5 and earlier.

abhibeckert commented 11 years ago

Seems, generally speaking, JSONKit is faster in iOS 5 while NSJSONSerialization is faster in iOS 6.

Or JSONKit is more suited to the 3GS processor than the iPad 2 processor.

Bo98 commented 11 years ago

I did the test a few months ago on the same device and got the same result.

odyth commented 11 years ago

I did some tests of my own and NSJSONSerialization is marginally faster on serialization and about 1.5x faster on deserialization, however you loose the ability to serialize custom objects. JSONKit lets you specify a block call back for custom classes NSJSONSerialization doesn't have this. I will have to loop through all the custom objects changing them into array's or dictionaries prior to handing it off to NSJSONSerialization, this will make it so JSONKit is clearly faster at serialization. Also since JSONKIt is open source I had modified it to omit NSNull from the dictionaries it returns, which since I want this feature requires me to strip NSNull's either at runtime or right after deserializing which will reduce the 1.5x speed advantage of NSJSONSerialization. JSONKit is more flexible then NSJSONSerialization its a shame the project has been abandoned.

abhibeckert commented 11 years ago

JSONKit is more flexible then NSJSONSerialization its a shame the project has been abandoned.

I wonder if JSONKit could be changed/forked as a wrapper around NSJSONSerialization. Just switch to using Apple's library under the hood, but keep the flexibility.

For example, omitting NSNull and custom objects could be done by using dispatch_apply() recursively after decoding with NSJSONSerialization.

odyth commented 11 years ago

@abhibeckert it wouldn't be as fast as just JSONKIt if it used NSJSONSerialization under the hood. also how would you use dispatch_apply to edit a mutable collection? wouldn't it crash as you were iterating and editing?

abhibeckert commented 11 years ago

@odyth you just create a new collection. That's a pretty inexpensive thing to do, in terms of performance. The actual contents of the dispatch_apply() will be much slower.

jdberry commented 11 years ago

Due to the fact that this project is apparently abandoned, I've now given up on JSONKit in favor of NSJSONSerialization.

odyth commented 11 years ago

What are you doing for custom object serialization?

On Wednesday, September 11, 2013, James Berry wrote:

Due to the fact that this project is apparently abandoned, I've now given up on JSONKit in favor of NSJSONSerialization.

— Reply to this email directly or view it on GitHubhttps://github.com/johnezang/JSONKit/issues/133#issuecomment-24289840 .

-justin

benliong commented 11 years ago

@abhibeckert probably the only reason to fork JSONKit is so that people with deployed codes using JSONKit do not need to change their code.

innocarpe commented 11 years ago

+1 :)

alvinchan commented 10 years ago

+1

BryanOne commented 10 years ago

+1

toddfreese commented 10 years ago

+1 Anyone have a fix for this?

abhibeckert commented 10 years ago

I wish people would stop hitting +1, as everyone who's subscribed to this issue gets an email notification each time.

@toddfreese the solutions are:

akinLiu commented 10 years ago

+1

erloncabral commented 10 years ago

+1

Pandan commented 10 years ago

+1

jcbertin commented 9 years ago

Have a look at #158. It will fix tagged pointers even for iOS 8 or MacOS 10.10.