(XCode 7.2.1)
我有一个想要将自己传递给C函数的Swift对象:
some_c_function(UnsafeMutablePointer(Unmanaged.passUnretained(self).toOpaque()));
其中some_c_function是通过桥接头访问的C函数:
void some_c_function(void* swiftObject);
对some_c_function的调用崩溃了Swift编译器:
0 swift 0x00000001028c2fbb llvm::sys::PrintStackTrace(__sFILE*) + 43
1 swift 0x00000001028c36fb SignalHandler(int) + 379
2 libsystem_platform.dylib 0x00007fff88809f1a _sigtramp + 26
3 swift 0x00000001026a64cf llvm::DICompositeType::getImpl(llvm::LLVMContext&, unsigned int, llvm::MDString*, llvm::Metadata*, unsigned int, llvm::Metadata*, llvm::Metadata*, unsigned long long, unsigned long long, unsigned long long, unsigned int, llvm::Metadata*, unsigned int, llvm::Metadata*, llvm::Metadata*, llvm::MDString*, llvm::Metadata::StorageType, bool) + 975
4 swift 0x0000000100ace9ad swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 10973
5 swift 0x0000000100a35053 swift::irgen::IRGenModuleDispatcher::emitLazyDefinitions() + 307
6 swift 0x0000000100ab549a performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1034
7 swift 0x0000000100ab5830 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 64
8 swift 0x00000001009b4265 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 13701
9 swift 0x00000001009b0ad3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
10 swift 0x00000001009ad154 main + 2324
11 libdyld.dylib 0x00007fff8f1555c9 start + 1
我做错了吗?