|
1 | 1 | extern crate inkwell;
|
2 | 2 |
|
3 | 3 | use self::inkwell::context::Context;
|
4 |
| -use self::inkwell::module::Module; |
5 | 4 | use self::inkwell::targets::{
|
6 |
| - ByteOrdering, CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetData, |
7 |
| - TargetMachine, TargetTriple, |
| 5 | + CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetMachine, |
8 | 6 | };
|
9 | 7 | use self::inkwell::values::BasicValue;
|
10 | 8 | use self::inkwell::OptimizationLevel;
|
@@ -56,28 +54,26 @@ fn test_section_iterator() {
|
56 | 54 | let mut has_section_a = false;
|
57 | 55 | let mut has_section_b = false;
|
58 | 56 | let mut has_section_c = false;
|
59 |
| - for (i, section) in object_file.get_sections().enumerate() { |
60 |
| - // TODO: the first section has no name, skip it. |
61 |
| - if i == 0 { |
62 |
| - continue; |
63 |
| - } |
64 |
| - match section.get_name().to_str().unwrap() { |
65 |
| - "A" => { |
66 |
| - assert!(!has_section_a); |
67 |
| - has_section_a = true; |
68 |
| - assert_eq!(section.size(), 1); |
69 |
| - } |
70 |
| - "B" => { |
71 |
| - assert!(!has_section_b); |
72 |
| - has_section_b = true; |
73 |
| - assert_eq!(section.size(), 2); |
74 |
| - } |
75 |
| - "C" => { |
76 |
| - assert!(!has_section_c); |
77 |
| - has_section_c = true; |
78 |
| - assert_eq!(section.size(), 4); |
| 57 | + for section in object_file.get_sections() { |
| 58 | + if let Some(name) = section.get_name() { |
| 59 | + match name.to_str().unwrap() { |
| 60 | + "A" => { |
| 61 | + assert!(!has_section_a); |
| 62 | + has_section_a = true; |
| 63 | + assert_eq!(section.size(), 1); |
| 64 | + } |
| 65 | + "B" => { |
| 66 | + assert!(!has_section_b); |
| 67 | + has_section_b = true; |
| 68 | + assert_eq!(section.size(), 2); |
| 69 | + } |
| 70 | + "C" => { |
| 71 | + assert!(!has_section_c); |
| 72 | + has_section_c = true; |
| 73 | + assert_eq!(section.size(), 4); |
| 74 | + } |
| 75 | + _ => {} |
79 | 76 | }
|
80 |
| - _ => {} |
81 | 77 | }
|
82 | 78 | }
|
83 | 79 | assert!(has_section_a);
|
@@ -112,23 +108,25 @@ fn test_symbol_iterator() {
|
112 | 108 | let mut has_symbol_b = false;
|
113 | 109 | let mut has_symbol_c = false;
|
114 | 110 | for symbol in object_file.get_symbols() {
|
115 |
| - match symbol.get_name().to_str().unwrap() { |
116 |
| - "a" => { |
117 |
| - assert!(!has_symbol_a); |
118 |
| - has_symbol_a = true; |
119 |
| - assert_eq!(symbol.size(), 1); |
120 |
| - } |
121 |
| - "b" => { |
122 |
| - assert!(!has_symbol_b); |
123 |
| - has_symbol_b = true; |
124 |
| - assert_eq!(symbol.size(), 2); |
125 |
| - } |
126 |
| - "c" => { |
127 |
| - assert!(!has_symbol_c); |
128 |
| - has_symbol_c = true; |
129 |
| - assert_eq!(symbol.size(), 4); |
| 111 | + if let Some(name) = symbol.get_name() { |
| 112 | + match name.to_str().unwrap() { |
| 113 | + "a" => { |
| 114 | + assert!(!has_symbol_a); |
| 115 | + has_symbol_a = true; |
| 116 | + assert_eq!(symbol.size(), 1); |
| 117 | + } |
| 118 | + "b" => { |
| 119 | + assert!(!has_symbol_b); |
| 120 | + has_symbol_b = true; |
| 121 | + assert_eq!(symbol.size(), 2); |
| 122 | + } |
| 123 | + "c" => { |
| 124 | + assert!(!has_symbol_c); |
| 125 | + has_symbol_c = true; |
| 126 | + assert_eq!(symbol.size(), 4); |
| 127 | + } |
| 128 | + _ => {} |
130 | 129 | }
|
131 |
| - _ => {} |
132 | 130 | }
|
133 | 131 | }
|
134 | 132 | assert!(has_symbol_a);
|
|
0 commit comments