【问题标题】:Xcode 6.0.1 segmentation fault at compile time with Swift projectSwift 项目在编译时出现 Xcode 6.0.1 分段错误
【发布时间】:2014-11-21 05:37:28
【问题描述】:

我在尝试编译我的 Swift 项目时遇到了分段错误。

这是导致错误的代码的简化版本:

enum PluginType
{
    case PluginC
    case PluginD
}

class Plugin
{
    var pluginType : PluginType
    var setter : Void -> Void
    var unsetter : Void -> Void

    init(pluginType : PluginType, setter : Void -> Void, unsetter : Void -> Void)
    {
        self.pluginType = pluginType
        self.setter = setter
        self.unsetter = unsetter
    }
}

@objc protocol BProtocol
{
    func getPlugins() -> [Plugin]
}

class B : BProtocol
{
    var a : AProtocol?

    func getPlugins() -> [Plugin]
    {
        return [Plugin(pluginType : .PluginC, setter : a!.setPluginC, unsetter : a!.unsetPluginC),
            Plugin(pluginType : .PluginD, setter : a!.setPluginD, unsetter: a!.unsetPluginD)]
    }
}

@objc protocol AProtocol
{
    func setPluginC()
    func unsetPluginC()
    func setPluginD()
    func unsetPluginD()
}

class A : AProtocol
{
    var b : BProtocol?

    func setPluginC()
    {

    }

    func unsetPluginC()
    {

    }

    func setPluginD()
    {

    }

    func unsetPluginD()
    {

    }
}

问题来自这种方法:

    func getPlugins() -> [Plugin]
    {
        return [Plugin(pluginType : .PluginC, setter : a!.setPluginC, unsetter : a!.unsetPluginC),
            Plugin(pluginType : .PluginD, setter : a!.setPluginD, unsetter: a!.unsetPluginD)]
    }

问题是由我初始化的setter和unsetter引起的。

这是 Xcode 上的错误:

0 迅速 0x000000010456a028 llvm::sys::PrintStackTrace(__sFILE*) + 40 1 快速
0x000000010456a514 SignalHandler(int) + 452 2 libsystem_platform.dylib 0x00007fff9596f5aa _sigtramp + 26 3 libsystem_platform.dylib 0x000007f83527198b _sigtramp + 2677023739 4 迅速0x00000001049290df swift::AbstractStorageDecl::hasObjCGetterAndSetter() const + 31 5 迅速0x0000000104929205 swift::AbstractStorageDecl::requiresObjCGetterAndSetter() const + 69 6 迅速0x00000001039ff3f4 swift::Lowering::SILGenFunction::emitGetAccessor(swift::SILLocation, swift::AbstractStorageDecl*, llvm::ArrayRef, swift::Lowering::RValueSource&&, bool, swift::Lowering::RValue&&, swift::Lowering::SGFContext) + 68 7 swift
0x0000000103a15ca4 swift::Lowering::SILGenFunction::emitRValueForPropertyLoad(swift::SILLocation, swift::Lowering::ManagedValue, bool, swift::VarDecl*, llvm::ArrayRef, bool, swift::Type, swift::Lowering::SGFContext) + 1284 8 swift
0x0000000103a2a012 swift::ASTVisitor::visit(swift::Expr*, 斯威夫特::降低::SGFContext) + 28402 9 斯威夫特
0x0000000103a2b6ed swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 45 10 swift
0x00000001039f3720 swift::Lowering::RValueSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 176 11 swift
0x0000000103a44154 swift::Lowering::RValueSource::forwardInto(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*, swift::Lowering::TypeLowering const&) && + 260 12 swift
0x0000000103a4400e swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::SILType) && + 334 13 swift 0x0000000103a340fc swift::Lowering::SILGenFunction::emitInjectOptionalValueInto(swift::SILLocation, swift::Lowering::RValueSource&&, swift::SILValue, swift::Lowering::TypeLowering const&) + 268 14 swift
0x0000000103a2b1fb swift::ASTVisitor::visit(swift::Expr*, swift::Lowering::SGFContext) + 32987 15 swift
0x0000000103a2a325 swift::ASTVisitor::visit(swift::Expr*, swift::Lowering::SGFContext) + 29189 16 swift
0x0000000103a2b63f swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 191 17 迅速 0x0000000103a483f9 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 297 18 迅速0x0000000103a4b2d4 swift::ASTVisitor::visit(swift::Stmt*) + 148 19 swift
0x0000000103a188c3 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 243 20 迅速 0x00000001039f8646 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 230 21 迅速0x0000000103a12763 swift::ASTVisitor::visit(swift::Decl*) + 355 22 swift
0x0000000103a1112b SILGenType::emitType() + 203 23 swift
0x0000000103a0c0fe swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30 24 swift 0x00000001039fa5cb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, 无符号整数)+ 411 25 快速 0x00000001039fa88f swift::SILModule::constructSIL(swift::Module*, swift::SourceFile*, swift::可选)+ 335 26 swift
0x00000001039fa9d8 swift::performSILGeneration(swift::SourceFile&, 快速::可选) + 72 27 快速
0x00000001038dfda9 frontend_main(llvm::ArrayRef, 字符 const*, void*) + 3353 28 快速 0x00000001038dd94d 主要 + 1677 29 libdyld.dylib 0x00007fff99b5c5fd 开始 + 1 30 libdyld.dylib 0x000000000000015a 开始 + 1716140894

我正在寻找一种解决方法来避免编译器出现“分段错误”。

有什么建议吗?

谢谢!

【问题讨论】:

    标签: xcode swift xcode6


    【解决方案1】:

    最后,我找到了解决方法:

    func getPlugins() -> [Plugin]
    {
        return [Plugin(pluginType : .PluginC, setter : { a!.setPluginC() }, unsetter : { a!.unsetPluginC() }),
            Plugin(pluginType : .PluginD, setter : { a!.setPluginD() }, unsetter: { a!.unsetPluginD() })]
    }
    

    这成功地适用于 Xcode 6.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多