Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

object->isa introduced a bug for unsupported class handling #89

Open
wants to merge 2 commits into from

3 participants

@confucious

Sorry if this is a bit of a mess, it's my first pull request.

objectPtr in jk_encode_add_atom_to_buffer refers to the original object and never changes. After the unsupported Class delegate method gets called, object is updated to a new, serializable object but the code still uses objectPtr which messes up the objectISA assignment.

I believe the correct course of action is to use object for the objectISA call.

The other commit is just adds an addObject: method for JKArray.

@mouser

There are a number of compiler issues with XCode 4.5b4 (and previous betas I assume) regarding JSONKit.

The isa thing being the more worrying, but the change is rather easy to deal with. Changes from object->isa to object_getClass(object):

*** /Volumes/Ackbar/XData/XUsers/mouser/Dev/Oracle/Vulcan/ios/3rdparty/JSONKit/JSONKit.m 2012-08-13 14:47:41 +0000
--- /Volumes/Ackbar/XData/XUsers/mouser/Dev/Oracle/wc_rtc/ios/shared/src/JSONKIT/JSONKIT.m 2012-01-11 13:43:30 +0000


*** 742,750 ****

  • (void)getObjects:(id )objectsPtr range:(NSRange)range { NSParameterAssert((objects != NULL) && (count <= capacity)); ! if((objectsPtr == NULL) && (NSMaxRange(range) > 0UL)) { [NSException raise:NSRangeException format:@"** -[%@ %@]: pointer to objects array is NULL but range length is %u", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range)]; } ! if((range.location > count) || (NSMaxRange(range) > count)) { [NSException raise:NSRangeException format:@"*** -[%@ %@]: index (%u) beyond bounds (%u)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range), count]; } memcpy(objectsPtr, objects + range.location, range.length * sizeof(id)); }

--- 742,750 ----

  • (void)getObjects:(id )objectsPtr range:(NSRange)range { NSParameterAssert((objects != NULL) && (count <= capacity)); ! if((objectsPtr == NULL) && (NSMaxRange(range) > 0UL)) { [NSException raise:NSRangeException format:@"** -[%@ %@]: pointer to objects array is NULL but range length is %lu", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range)]; } ! if((range.location > count) || (NSMaxRange(range) > count)) { [NSException raise:NSRangeException format:@"*** -[%@ %@]: index (%lu) beyond bounds (%lu)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range), count]; } memcpy(objectsPtr, objects + range.location, range.length * sizeof(id)); }

The other is misuse of printf format hints like %lu (unsigned long) when passing NSUInteger (unsigned int). I changed those to

*** /Volumes/Ackbar/XData/XUsers/mouser/Dev/Oracle/Vulcan/ios/3rdparty/JSONKit/JSONKit.m 2012-08-13 14:47:41 +0000
--- /Volumes/Ackbar/XData/XUsers/mouser/Dev/Oracle/wc_rtc/ios/shared/src/JSONKIT/JSONKIT.m 2012-01-11 13:43:30 +0000


*** 742,750 ****

  • (void)getObjects:(id )objectsPtr range:(NSRange)range { NSParameterAssert((objects != NULL) && (count <= capacity)); ! if((objectsPtr == NULL) && (NSMaxRange(range) > 0UL)) { [NSException raise:NSRangeException format:@"** -[%@ %@]: pointer to objects array is NULL but range length is %u", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range)]; } ! if((range.location > count) || (NSMaxRange(range) > count)) { [NSException raise:NSRangeException format:@"*** -[%@ %@]: index (%u) beyond bounds (%u)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range), count]; } memcpy(objectsPtr, objects + range.location, range.length * sizeof(id)); }

--- 742,750 ----

  • (void)getObjects:(id )objectsPtr range:(NSRange)range { NSParameterAssert((objects != NULL) && (count <= capacity)); ! if((objectsPtr == NULL) && (NSMaxRange(range) > 0UL)) { [NSException raise:NSRangeException format:@"** -[%@ %@]: pointer to objects array is NULL but range length is %lu", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range)]; } ! if((range.location > count) || (NSMaxRange(range) > count)) { [NSException raise:NSRangeException format:@"*** -[%@ %@]: index (%lu) beyond bounds (%lu)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSMaxRange(range), count]; } memcpy(objectsPtr, objects + range.location, range.length * sizeof(id)); }
@ghost

I'm having the same issue. Your fix 785411e fixed the problem.
Thanks!

@jimerman

Awesome, the updated .m fixed the issues. I found I could not simply do a search & replace on ->isa like you said, because in some cases it was used on an expression result other than 'object', but the download of your new .m is solid. Thanks for sharing such a great resource!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 1, 2012
  1. @confucious
Commits on Aug 7, 2012
  1. @confucious

    Fix bug where jk_encode_add_atom_to_buffer does not look at the prope…

    confucious authored
    …r object after handling an unsupported class.
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +5 −1 JSONKit.m
View
6 JSONKit.m
@@ -790,6 +790,10 @@ - (void)removeObjectAtIndex:(NSUInteger)objectIndex
mutations = (mutations == NSUIntegerMax) ? 1UL : mutations + 1UL;
}
+- (void)addObject:(id)anObject {
+ [self insertObject: anObject atIndex: count];
+}
+
- (void)replaceObjectAtIndex:(NSUInteger)objectIndex withObject:(id)anObject
{
if(mutations == 0UL) { [NSException raise:NSInternalInconsistencyException format:@"*** -[%@ %@]: mutating method sent to immutable object", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; }
@@ -2596,7 +2600,7 @@ static int jk_encode_add_atom_to_buffer(JKEncodeState *encodeState, void *object
BOOL workAroundMacOSXABIBreakingBug = (JK_EXPECT_F(((NSUInteger)object) & 0x1)) ? YES : NO;
- void *objectISA = (JK_EXPECT_F(workAroundMacOSXABIBreakingBug)) ? NULL : *((void **)objectPtr);
+ void *objectISA = (JK_EXPECT_F(workAroundMacOSXABIBreakingBug)) ? NULL : *((void **)object);
if(JK_EXPECT_F(workAroundMacOSXABIBreakingBug)) { goto slowClassLookup; }
if(JK_EXPECT_T(objectISA == encodeState->fastClassLookup.stringClass)) { isClass = JKClassString; }
Something went wrong with that request. Please try again.