@@ -48,6 +48,7 @@ impl Drop for ObjectFile {
48
48
pub struct SectionIterator {
49
49
section_iterator : LLVMSectionIteratorRef ,
50
50
object_file : LLVMObjectFileRef ,
51
+ before_first : bool ,
51
52
}
52
53
53
54
impl SectionIterator {
@@ -56,7 +57,8 @@ impl SectionIterator {
56
57
57
58
SectionIterator {
58
59
section_iterator,
59
- object_file
60
+ object_file,
61
+ before_first : true
60
62
}
61
63
}
62
64
}
@@ -65,7 +67,14 @@ impl Iterator for SectionIterator {
65
67
type Item = Section ;
66
68
67
69
fn next ( & mut self ) -> Option < Self :: Item > {
68
- // REVIEW: Should it compare against 1? End checking order might also be off
70
+ if self . before_first {
71
+ self . before_first = false ;
72
+ } else {
73
+ unsafe {
74
+ LLVMMoveToNextSection ( self . section_iterator ) ;
75
+ }
76
+ }
77
+
69
78
let at_end = unsafe {
70
79
LLVMIsSectionIteratorAtEnd ( self . object_file , self . section_iterator ) == 1
71
80
} ;
@@ -76,10 +85,6 @@ impl Iterator for SectionIterator {
76
85
77
86
let section = Section :: new ( self . section_iterator , self . object_file ) ;
78
87
79
- unsafe {
80
- LLVMMoveToNextSection ( self . section_iterator )
81
- }
82
-
83
88
Some ( section)
84
89
}
85
90
}
@@ -151,6 +156,7 @@ pub struct RelocationIterator {
151
156
relocation_iterator : LLVMRelocationIteratorRef ,
152
157
section_iterator : LLVMSectionIteratorRef ,
153
158
object_file : LLVMObjectFileRef ,
159
+ before_first : bool ,
154
160
}
155
161
156
162
impl RelocationIterator {
@@ -161,6 +167,7 @@ impl RelocationIterator {
161
167
relocation_iterator,
162
168
section_iterator,
163
169
object_file,
170
+ before_first : true
164
171
}
165
172
}
166
173
}
@@ -169,7 +176,14 @@ impl Iterator for RelocationIterator {
169
176
type Item = Relocation ;
170
177
171
178
fn next ( & mut self ) -> Option < Self :: Item > {
172
- // REVIEW: Should it compare against 1? End checking order might also be off
179
+ if self . before_first {
180
+ self . before_first = false ;
181
+ } else {
182
+ unsafe {
183
+ LLVMMoveToNextRelocation ( self . relocation_iterator )
184
+ }
185
+ }
186
+
173
187
let at_end = unsafe {
174
188
LLVMIsRelocationIteratorAtEnd ( self . section_iterator , self . relocation_iterator ) == 1
175
189
} ;
@@ -180,10 +194,6 @@ impl Iterator for RelocationIterator {
180
194
181
195
let relocation = Relocation :: new ( self . relocation_iterator , self . object_file ) ;
182
196
183
- unsafe {
184
- LLVMMoveToNextRelocation ( self . relocation_iterator )
185
- }
186
-
187
197
Some ( relocation)
188
198
}
189
199
}
@@ -249,6 +259,7 @@ impl Relocation {
249
259
pub struct SymbolIterator {
250
260
symbol_iterator : LLVMSymbolIteratorRef ,
251
261
object_file : LLVMObjectFileRef ,
262
+ before_first : bool ,
252
263
}
253
264
254
265
impl SymbolIterator {
@@ -258,6 +269,7 @@ impl SymbolIterator {
258
269
SymbolIterator {
259
270
symbol_iterator,
260
271
object_file,
272
+ before_first : true
261
273
}
262
274
}
263
275
}
@@ -266,7 +278,14 @@ impl Iterator for SymbolIterator {
266
278
type Item = Symbol ;
267
279
268
280
fn next ( & mut self ) -> Option < Self :: Item > {
269
- // REVIEW: Should it compare against 1? End checking order might also be off
281
+ if self . before_first {
282
+ self . before_first = false ;
283
+ } else {
284
+ unsafe {
285
+ LLVMMoveToNextSymbol ( self . symbol_iterator )
286
+ }
287
+ }
288
+
270
289
let at_end = unsafe {
271
290
LLVMIsSymbolIteratorAtEnd ( self . object_file , self . symbol_iterator ) == 1
272
291
} ;
@@ -277,10 +296,6 @@ impl Iterator for SymbolIterator {
277
296
278
297
let symbol = Symbol :: new ( self . symbol_iterator ) ;
279
298
280
- unsafe {
281
- LLVMMoveToNextSymbol ( self . symbol_iterator )
282
- }
283
-
284
299
Some ( symbol)
285
300
}
286
301
}
0 commit comments