kakaopensource / KakaJSON

Fast conversion between JSON and model in Swift.
MIT License
1.17k stars 127 forks source link

iOS 9 Crash #31

Closed shaop closed 5 years ago

shaop commented 5 years ago

crash at

Thread 1: EXC_BAD_ACCESS (code=1, address=0x100000003) (Type.swift line 47)

use description.pointee on iOS 9

shaop commented 5 years ago

on iOS 9 the base class object.superclass is named _TtCs12_SwiftObject .

Maybe it should be changed like this ?

public struct Metadata {
        ...
        // name
        let name = String(describing: type)
        if name == "Swift._SwiftObject" || name == "NSObject" || name == "_TtCs12_SwiftObject" { return nil }
        ...
huhaosanxiong commented 5 years ago

我也遇到了这个问题,我和同事的环境都是macOS 10.15,同样的代码,我的不会崩溃,而他的就会崩溃。

CoderMJLee commented 5 years ago

@shaop 你加上name == "_TtCs12_SwiftObject"判断之后是否有效?

huhaosanxiong commented 5 years ago

@shaop 你加上name == "_TtCs12_SwiftObject"判断之后是否有效?

我尝试了一下,确实有效避免了崩溃。

shaop commented 5 years ago

@CoderMJLee 是的,可以避免奔溃。

shaop commented 5 years ago

@CoderMJLee 并且多线程的时候经常在第 18 行奔溃,是否应该在将锁放在第 18 行前?

    public static func type(_ type: Any.Type) -> BaseType? {
        // get from cache
        let key = typeKey(type)
        typeLock.lock()
        defer { typeLock.unlock() }
        if let mt = types[key] { return mt }
        .....
        // judge after lock
        if let mt = types[key] { return mt }
shaop commented 5 years ago

SwiftObject.h 这里有表明 _TtCs12_SwiftObject, 但是注释中也写了

// Real class name: mangled "Swift._SwiftObject"

目前不太清楚为什么一些低版本的系统上出现了问题

CoderMJLee commented 5 years ago

@shaop @huhaosanxiong 1.1.1版本已经修复

shaop commented 5 years ago

thanks 👍