Git Product home page Git Product logo

Comments (8)

Kirow avatar Kirow commented on June 2, 2024 2

If you using code from #158 you can replace (straight forward solution)

return(((uintptr_t)objectPtr) >> 60);

with

if (@available(iOS 14, *)) {
   return(((uintptr_t)objectPtr) & 0x7);
} else {
   return(((uintptr_t)objectPtr) >> 60);
}

if you using code from master branch you will need to update isa usage

patch.diff
diff --git a/JSONKit.m b/JSONKit.m
index 0e9331f..c47ab02 100644
--- a/JSONKit.m
+++ b/JSONKit.m
@@ -677,7 +677,7 @@ static JKArray *_JKArrayCreate(id *objects, NSUInteger count, BOOL mutableCollec
   NSCParameterAssert((objects != NULL) && (_JKArrayClass != NULL) && (_JKArrayInstanceSize > 0UL));
   JKArray *array = NULL;
   if(JK_EXPECT_T((array = (JKArray *)calloc(1UL, _JKArrayInstanceSize)) != NULL)) { // Directly allocate the JKArray instance via calloc.
-    array->isa      = _JKArrayClass;
+    object_setClass(array, _JKArrayClass);
     if((array = [array init]) == NULL) { return(NULL); }
     array->capacity = count;
     array->count    = count;
@@ -928,7 +928,7 @@ static JKDictionary *_JKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *ob
   NSCParameterAssert((keys != NULL) && (keyHashes != NULL) && (objects != NULL) && (_JKDictionaryClass != NULL) && (_JKDictionaryInstanceSize > 0UL));
   JKDictionary *dictionary = NULL;
   if(JK_EXPECT_T((dictionary = (JKDictionary *)calloc(1UL, _JKDictionaryInstanceSize)) != NULL)) { // Directly allocate the JKDictionary instance via calloc.
-    dictionary->isa      = _JKDictionaryClass;
+    object_setClass(dictionary, _JKDictionaryClass);
     if((dictionary = [dictionary init]) == NULL) { return(NULL); }
     dictionary->capacity = _JKDictionaryCapacityForCount(count);
     dictionary->count    = 0UL;
@@ -2596,7 +2596,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_getClass(objectPtr));
   if(JK_EXPECT_F(workAroundMacOSXABIBreakingBug)) { goto slowClassLookup; }
 
        if(JK_EXPECT_T(objectISA == encodeState->fastClassLookup.stringClass))     { isClass = JKClassString;     }
@@ -2792,7 +2792,7 @@ static int jk_encode_add_atom_to_buffer(JKEncodeState *encodeState, void *object
           for(id keyObject in enumerateObject) {
             if(JK_EXPECT_T(printComma)) { if(JK_EXPECT_F(jk_encode_write1(encodeState, 0L, ","))) { return(1); } }
             printComma = 1;
-            void *keyObjectISA = *((void **)keyObject);
+            void *keyObjectISA = (void *)object_getClass(keyObject);
             if(JK_EXPECT_F((keyObjectISA != encodeState->fastClassLookup.stringClass)) && JK_EXPECT_F(([keyObject isKindOfClass:[NSString class]] == NO))) { jk_encode_error(encodeState, @"Key must be a string object."); return(1); }
             if(JK_EXPECT_F(jk_encode_add_atom_to_buffer(encodeState, keyObject)))                                                        { return(1); }
             if(JK_EXPECT_F(jk_encode_write1(encodeState, 0L, ":")))                                                                      { return(1); }
@@ -2804,7 +2804,7 @@ static int jk_encode_add_atom_to_buffer(JKEncodeState *encodeState, void *object
           for(idx = 0L; idx < dictionaryCount; idx++) {
             if(JK_EXPECT_T(printComma)) { if(JK_EXPECT_F(jk_encode_write1(encodeState, 0L, ","))) { return(1); } }
             printComma = 1;
-            void *keyObjectISA = *((void **)keys[idx]);
+            void *keyObjectISA = (void *)object_getClass(keys[idx]);
             if(JK_EXPECT_F(keyObjectISA != encodeState->fastClassLookup.stringClass) && JK_EXPECT_F([(id)keys[idx] isKindOfClass:[NSString class]] == NO)) { jk_encode_error(encodeState, @"Key must be a string object."); return(1); }
             if(JK_EXPECT_F(jk_encode_add_atom_to_buffer(encodeState, keys[idx])))    { return(1); }
             if(JK_EXPECT_F(jk_encode_write1(encodeState, 0L, ":")))                  { return(1); }

however there was comment not to use object_getClass due to performance impact, but goal was to fix the crashes.

P.S. Did not test this deeply, but seems to be working...

from jsonkit.

codedeman avatar codedeman commented on June 2, 2024 1

If you using code from #158 you can replace (straight forward solution)

return(((uintptr_t)objectPtr) >> 60);

with

if (@available(iOS 14, *)) {
   return(((uintptr_t)objectPtr) & 0x7);
} else {
   return(((uintptr_t)objectPtr) >> 60);
}

if you using code from master branch you will need to update isa usage

patch.diff
however there was comment not to use object_getClass due to performance impact, but goal was to fix the crashes.

P.S. Did not test this deeply, but seems to be working...

it's work for me

from jsonkit.

asgeo1 avatar asgeo1 commented on June 2, 2024

I'm having this issue too. Is there any workaround?

from jsonkit.

adancondori avatar adancondori commented on June 2, 2024

I'm having this issue too. Exist any alternative for this error.?

from jsonkit.

garyZJ avatar garyZJ commented on June 2, 2024

I'm having this issue too.

from jsonkit.

miyiyake avatar miyiyake commented on June 2, 2024

NSNumber 类型数据都有问题,换成NSString类型就没有问题

from jsonkit.

jcbertin avatar jcbertin commented on June 2, 2024

I have fixed #158 for new format of tagged pointers in macOS on Apple Silicon and last versions of iOS, watchOS and tvOS. Also replaced isa dereference by fast class lookup.

Please comment if it is not working for you…

from jsonkit.

jcbertin avatar jcbertin commented on June 2, 2024

For people curious to compare #158 and NSJSON, see JSONKitTest.

from jsonkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.