Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass() #106

Open
Whirlwind opened this Issue Nov 15, 2012 · 11 comments

Comments

Projects
None yet
7 participants
@Whirlwind

JSONKit.m:680:12: Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()
JSONKit.m:931:17: Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()
XCODE 4.6DP2

@vchav73

This comment has been minimized.

Show comment
Hide comment
@vchav73

vchav73 Nov 25, 2012

I researched this. Seems isa holds the class for the object. The warnings can be eliminated by replacing the offending lines with:

object_setClass(dictionary, _JKDictionaryClass); // Dictionary case
object_setClass(array, _JKArrayClass); // Array case

Haven't tested this yet, but I did verify that the changes eliminate the warnings in Xcode 4.6 DP2.

vchav73 commented Nov 25, 2012

I researched this. Seems isa holds the class for the object. The warnings can be eliminated by replacing the offending lines with:

object_setClass(dictionary, _JKDictionaryClass); // Dictionary case
object_setClass(array, _JKArrayClass); // Array case

Haven't tested this yet, but I did verify that the changes eliminate the warnings in Xcode 4.6 DP2.

@Bo98

This comment has been minimized.

Show comment
Hide comment
@Bo98

Bo98 Dec 5, 2012

A fix is to probably to use something like this:

5663f2d

Bo98 commented Dec 5, 2012

A fix is to probably to use something like this:

5663f2d

@Daij-Djan

This comment has been minimized.

Show comment
Hide comment
@Daij-Djan

Daij-Djan Jan 11, 2013

how is silencing warnings 'ever' a fix... that setClass call looks cool.

how is silencing warnings 'ever' a fix... that setClass call looks cool.

@Bo98

This comment has been minimized.

Show comment
Hide comment
@Bo98

Bo98 Jan 11, 2013

It's how johnezang did it.

Bo98 commented Jan 11, 2013

It's how johnezang did it.

@Daij-Djan

This comment has been minimized.

Show comment
Hide comment
@Daij-Djan

Daij-Djan Jan 11, 2013

where? its not in the trunk.

where? its not in the trunk.

@Bo98

This comment has been minimized.

Show comment
Hide comment
@vchav73

This comment has been minimized.

Show comment
Hide comment
@vchav73

vchav73 Jan 11, 2013

I have the object_setClass fix in production. I haven't measured the performance impact, but saw the notes below in the comments of JSONKit.m, which makes me believe that the change will hurt performance. For my application it's good enough.

// Why not just use object_getClass()? Because object->isa reduces to (typically) a single instruction. Calling object_getClass() requires
// that the compiler potentially spill registers, establish a function call frame / environment, and finally execute a "jump subroutine" instruction.
// Then, the called subroutine must spend half a dozen instructions in its prolog, however many instructions doing whatever it does, then half a dozen
// instructions in its prolog. One instruction compared to dozens, maybe a hundred instructions.
//
// Yes, that's one to two orders of magnitude difference. Which is compelling in its own right. When going for performance, you're often happy with
// gains in the two to three percent range.

vchav73 commented Jan 11, 2013

I have the object_setClass fix in production. I haven't measured the performance impact, but saw the notes below in the comments of JSONKit.m, which makes me believe that the change will hurt performance. For my application it's good enough.

// Why not just use object_getClass()? Because object->isa reduces to (typically) a single instruction. Calling object_getClass() requires
// that the compiler potentially spill registers, establish a function call frame / environment, and finally execute a "jump subroutine" instruction.
// Then, the called subroutine must spend half a dozen instructions in its prolog, however many instructions doing whatever it does, then half a dozen
// instructions in its prolog. One instruction compared to dozens, maybe a hundred instructions.
//
// Yes, that's one to two orders of magnitude difference. Which is compelling in its own right. When going for performance, you're often happy with
// gains in the two to three percent range.

@davidsielert

This comment has been minimized.

Show comment
Hide comment
@davidsielert

davidsielert Apr 13, 2013

+1 for the above pull ..

+1 for the above pull ..

@grichards-trulia

This comment has been minimized.

Show comment
Hide comment

+1 for pull req #121

@vakulenkom

This comment has been minimized.

Show comment
Hide comment
@vakulenkom

vakulenkom Jul 22, 2013

Can please someone explain me if i could still use JSONKit after Xcode auto-fix?

dictionary->isa = _JKDictionaryClass -------> object_setClass(dictionary, _JKDictionaryClass);

Can please someone explain me if i could still use JSONKit after Xcode auto-fix?

dictionary->isa = _JKDictionaryClass -------> object_setClass(dictionary, _JKDictionaryClass);

@Bo98

This comment has been minimized.

Show comment
Hide comment
@Bo98

Bo98 Jul 22, 2013

Should do. I've not seen any breakages after applying the fix.

Bo98 commented Jul 22, 2013

Should do. I've not seen any breakages after applying the fix.

@ArtSeo ArtSeo referenced this issue in ArtSeo/Multiples Jun 8, 2014

Open

CocoaPods #5

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