Skip to content

Commit 94fe4fa

Browse files
authored
Merge pull request #145 from p-x9/feature/symbols-random-access-collection
Fix to use `RandomAccessCollection` of symbols
2 parents b4b5132 + 911695f commit 94fe4fa

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Sources/MachOKit/Protocol/MachORepresentable.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ extension MachORepresentable {
376376
inSection sectionNumber: Int = 0,
377377
isGlobalOnly: Bool = false
378378
) -> [Symbol] {
379-
let symbols = Array(self.symbols)
379+
let symbols = self.symbols
380380
var bestOffset: Int?
381381
var bestSymbols: [Symbol] = []
382382

@@ -401,7 +401,7 @@ extension MachORepresentable {
401401
let globalStart: Int = numericCast(dysym.iextdefsym)
402402
let globalCount: Int = numericCast(dysym.nextdefsym)
403403
for i in globalStart ..< globalStart + globalCount {
404-
let symbol = symbols[i]
404+
let symbol = symbols[AnyIndex(i)]
405405
let nlist = symbol.nlist
406406
let symbolSectionNumber = symbol.nlist.sectionNumber
407407

@@ -418,7 +418,7 @@ extension MachORepresentable {
418418
let localStart: Int = numericCast(dysym.ilocalsym)
419419
let localCount: Int = numericCast(dysym.nlocalsym)
420420
for i in localStart ..< localStart + localCount {
421-
let symbol = symbols[i]
421+
let symbol = symbols[AnyIndex(i)]
422422
let nlist = symbol.nlist
423423
let symbolSectionNumber = symbol.nlist.sectionNumber
424424

@@ -552,15 +552,15 @@ extension MachORepresentable {
552552
return nil
553553
}
554554

555-
let symbols = Array(self.symbols)
555+
let symbols = self.symbols
556556
var bestSymbol: Symbol?
557557

558558
if let dysym = loadCommands.dysymtab {
559559
// find closest match in globals
560560
let globalStart: Int = numericCast(dysym.iextdefsym)
561561
let globalCount: Int = numericCast(dysym.nextdefsym)
562562
for i in globalStart ..< globalStart + globalCount {
563-
let symbol = symbols[i]
563+
let symbol = symbols[AnyIndex(i)]
564564
let nlist = symbol.nlist
565565
guard nlist.flags?.type == .sect,
566566
matchesName(nameC, symbol) else {
@@ -574,7 +574,7 @@ extension MachORepresentable {
574574
let localStart: Int = numericCast(dysym.ilocalsym)
575575
let localCount: Int = numericCast(dysym.nlocalsym)
576576
for i in localStart ..< localStart + localCount {
577-
let symbol = symbols[i]
577+
let symbol = symbols[AnyIndex(i)]
578578
let nlist = symbol.nlist
579579
guard nlist.flags?.type == .sect,
580580
nlist.flags?.stab == nil,

Tests/MachOKitTests/MachOFilePrintTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ final class MachOFilePrintTests: XCTestCase {
9999
}
100100

101101
func testSectionRelocationInfos() {
102-
let symbols = Array(machO.symbols)
102+
let symbols = machO.symbols
103103
for section in machO.sections32 where section.nreloc > 0 {
104104
print("----")
105105
print("Name:", "\(section.segmentName).\(section.sectionName)"
@@ -118,7 +118,7 @@ final class MachOFilePrintTests: XCTestCase {
118118
print("pcRelative:", info.isRelocatedPCRelative)
119119
if let symbolIndex = info.symbolIndex {
120120
print("SymbolIndex:", symbolIndex)
121-
print("SymbolName:", symbols[symbolIndex].name)
121+
print("SymbolName:", symbols[AnyIndex(symbolIndex)].name)
122122
}
123123
if let sectionOrdinal = info.sectionOrdinal {
124124
print("SectionOrdinal:", sectionOrdinal)
@@ -239,7 +239,7 @@ final class MachOFilePrintTests: XCTestCase {
239239

240240
func testIndirectSymbols() throws {
241241
guard let _indirectSymbols = machO.indirectSymbols else { return }
242-
let symbols = Array(machO.symbols)
242+
let symbols = machO.symbols
243243
let indirectSymbols = Array(_indirectSymbols)
244244

245245
for section in machO.sections {
@@ -253,7 +253,7 @@ final class MachOFilePrintTests: XCTestCase {
253253
for symbol in indirectSymbols {
254254
print(" ", symbol._value, terminator: " ")
255255
if let index = symbol.index {
256-
print(symbols[index].name)
256+
print(symbols[AnyIndex(index)].name)
257257
} else {
258258
print(symbol)
259259
}

Tests/MachOKitTests/MachOPrintTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ final class MachOPrintTests: XCTestCase {
170170

171171
func testIndirectSymbols() throws {
172172
guard let _indirectSymbols = machO.indirectSymbols else { return }
173-
let symbols = Array(machO.symbols)
173+
let symbols = machO.symbols
174174
let indirectSymbols = Array(_indirectSymbols)
175175

176176
for section in machO.sections {
@@ -184,7 +184,7 @@ final class MachOPrintTests: XCTestCase {
184184
for symbol in indirectSymbols {
185185
print(" ", symbol._value, terminator: " ")
186186
if let index = symbol.index {
187-
print(symbols[index].name)
187+
print(symbols[AnyIndex(index)].name)
188188
} else {
189189
print(symbol)
190190
}

0 commit comments

Comments
 (0)