-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix swift_getFieldAt symbol missing in Swift 5
- Loading branch information
chantu
committed
Feb 2, 2019
1 parent
5aef695
commit da72f29
Showing
6 changed files
with
214 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// FieldDescriptor.swift | ||
// HandyJSON | ||
// | ||
// Created by chantu on 2019/1/31. | ||
// Copyright © 2019 aliyun. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum FieldDescriptorKind : UInt16 { | ||
// Swift nominal types. | ||
case Struct = 0 | ||
case Class | ||
case Enum | ||
|
||
// Fixed-size multi-payload enums have a special descriptor format that | ||
// encodes spare bits. | ||
// | ||
// FIXME: Actually implement this. For now, a descriptor with this kind | ||
// just means we also have a builtin descriptor from which we get the | ||
// size and alignment. | ||
case MultiPayloadEnum | ||
|
||
// A Swift opaque protocol. There are no fields, just a record for the | ||
// type itself. | ||
case `Protocol` | ||
|
||
// A Swift class-bound protocol. | ||
case ClassProtocol | ||
|
||
// An Objective-C protocol, which may be imported or defined in Swift. | ||
case ObjCProtocol | ||
|
||
// An Objective-C class, which may be imported or defined in Swift. | ||
// In the former case, field type metadata is not emitted, and | ||
// must be obtained from the Objective-C runtime. | ||
case ObjCClass | ||
} | ||
|
||
struct FieldDescriptor: PointerType { | ||
|
||
var pointer: UnsafePointer<_FieldDescriptor> | ||
|
||
var fieldRecordSize: Int { | ||
return Int(pointer.pointee.fieldRecordSize) | ||
} | ||
|
||
var numFields: Int { | ||
return Int(pointer.pointee.numFields) | ||
} | ||
|
||
var fieldRecords: [FieldRecord] { | ||
return (0..<numFields).map({ (i) -> FieldRecord in | ||
return FieldRecord(pointer: UnsafePointer<_FieldRecord>(pointer + 1) + i) | ||
}) | ||
} | ||
} | ||
|
||
struct _FieldDescriptor { | ||
var mangledTypeNameOffset: Int32 | ||
var superClassOffset: Int32 | ||
var fieldDescriptorKind: FieldDescriptorKind | ||
var fieldRecordSize: Int16 | ||
var numFields: Int32 | ||
} | ||
|
||
struct FieldRecord: PointerType { | ||
|
||
var pointer: UnsafePointer<_FieldRecord> | ||
|
||
var fieldRecordFlags: Int { | ||
return Int(pointer.pointee.fieldRecordFlags) | ||
} | ||
|
||
var mangledTypeName: UnsafePointer<UInt8>? { | ||
let address = Int(bitPattern: pointer) + 1 * 4 | ||
let offset = Int(pointer.pointee.mangledTypeNameOffset) | ||
let cString = UnsafePointer<UInt8>(bitPattern: address + offset) | ||
return cString | ||
} | ||
|
||
var fieldName: String { | ||
let address = Int(bitPattern: pointer) + 2 * 4 | ||
let offset = Int(pointer.pointee.fieldNameOffset) | ||
if let cString = UnsafePointer<UInt8>(bitPattern: address + offset) { | ||
return String(cString: cString) | ||
} | ||
return "" | ||
} | ||
} | ||
|
||
struct _FieldRecord { | ||
var fieldRecordFlags: Int32 | ||
var mangledTypeNameOffset: Int32 | ||
var fieldNameOffset: Int32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// MangledName.swift | ||
// HandyJSON | ||
// | ||
// Created by chantu on 2019/2/2. | ||
// Copyright © 2019 aliyun. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// mangled name might contain 0 but it is not the end, do not just use strlen | ||
func getMangledTypeNameSize(_ mangledName: UnsafePointer<UInt8>) -> Int { | ||
// TODO: should find the actually size | ||
return 256 | ||
} |
Oops, something went wrong.
da72f29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swift5.0 报错
da72f29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Xcode 10.2 Undefined symbol: _swift_getFieldAt