使用 FileManager.default.currentDirectoryPath 时出现 Segmentation fault: 11 with Swift 5.2 [英] Getting a Segmentation fault: 11 with Swift 5.2 when using FileManager.default.currentDirectoryPath
问题描述
我有一个类似于以下内容的自定义 Swift 脚本:
I've got a custom Swift script that is similar to the following:
#!/usr/bin/env xcrun --sdk macosx swift
import Foundation
let path = FileManager.default.currentDirectoryPath
在 Swift 5.1 及更低版本上它运行得很好,但更新到 Swift 5.2 后,我得到
On Swift 5.1 and lower it runs just fine, but upon updating to Swift 5.2, I get
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret test.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name test
1. Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2. While running user code "test.swift"
0 swift 0x000000010dd2f4ea PrintStackTraceSignalHandler(void*) + 42
1 swift 0x000000010dd2ecc0 SignalHandler(int) + 352
2 libsystem_platform.dylib 0x00007fff6710f42d _sigtramp + 29
3 libsystem_platform.dylib 0x00007ffee6222018 _sigtramp + 2131831816
4 swift 0x0000000109ab29ba llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458
5 swift 0x0000000109ab9a2b llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 2011
6 swift 0x0000000109a8eaea performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14362
7 swift 0x0000000109a834a5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
8 swift 0x00000001099f94d3 main + 1283
9 libdyld.dylib 0x00007fff66f167fd start + 1
10 libdyld.dylib 0x000000000000000b start + 2567870479
Segmentation fault: 11
是否有任何我不知道的重大更改?
Have there been any breaking changes that I'm not aware of?
推荐答案
事实证明,在这种情况下,问题出在流氓覆盖 dylib 中,因为我一直在使用 SwiftGen.
Turns out that in this case, the problem was in rogue overlay dylibs that were in place because I've been using SwiftGen.
解决方案是通过调用卸载 SwiftGen
The solution is to either uninstall SwiftGen by calling
brew uninstall swiftgen
或关注 Nikolaj 的回答来自 Swift 错误跟踪系统,通过重新安装 SwiftGen
or following Nikolaj's answer from Swift bug tracking system by reinstalling SwiftGen with
--build-from-source
选项并从lib"文件夹中删除 dylib.
option and removing the dylibs from "lib" folder.
这篇关于使用 FileManager.default.currentDirectoryPath 时出现 Segmentation fault: 11 with Swift 5.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!