From 49824860715c16f3f31c221a54d1ee210eef5595 Mon Sep 17 00:00:00 2001 From: Gabriel Smith Date: Sun, 7 May 2017 16:13:33 -0400 Subject: [PATCH] Fix two issues with bounds creation The first issue came about when a DTS include was at the very start of a bound. Due to old logic that hadn't been thought through after the change to bounds this did not create a zero length bound before the include which is needed to be able to figure out the include tree later on. The second issue was that new CPP bounds sometimes did not have the proper length at creation due to only knowing of the slice of input before a DTS include. The fix just passes in the length of the remaining section. This length will be trimmed by the following split from the DTS include, but ensures that the proper remainder is left after splitting. --- device_tree_source/src/include.rs | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/device_tree_source/src/include.rs b/device_tree_source/src/include.rs index 938e9ae..6950770 100644 --- a/device_tree_source/src/include.rs +++ b/device_tree_source/src/include.rs @@ -162,8 +162,8 @@ impl IncludeBounds { // println!("split s: {} e: {} off: {}", start, end, offset); for b in bounds.iter_mut() { - // println!("g_start: {} g_end: {}", b.global_start, b.global_end()); - if b.start() < start && b.end() >= start { + // println!("b.start: {} b.end: {} b.len: {}", b.start(), b.end(), b.len()); + if b.start() <= start && b.end() >= start { // global_start -- start -- global_end let remainder = b.end() - start; @@ -178,15 +178,6 @@ impl IncludeBounds { }); b.len = start - b.start(); - } else if b.start() == start { - // split is at begining of the bound - // offset the start - { - let offset = end - start; - b.global_start += offset; - } - // shrink the len by the offset - b.len -= offset; } } @@ -337,17 +328,22 @@ named!(find_linemarker<(&[u8], Linemarker)>, do_parse!( (pre, marker) )); -fn parse_linemarkers(buf: &[u8], bounds: &mut Vec, global_offset: usize) +fn parse_linemarkers(buf: &[u8], + bounds: &mut Vec, + global_offset: usize, + post_len: usize) -> Result<(), IncludeError> { let end_offset = global_offset + buf.len(); - // println!("{}", str::from_utf8(buf).unwrap()); + // println!("{}", String::from_utf8_lossy(buf)); let mut buf = buf; // println!("parsing linemarkers"); while let IResult::Done(rem, (pre, marker)) = find_linemarker(buf) { - // println!("{}", str::from_utf8(line).unwrap()); // println!("{:?}", marker); // println!("pre.len() {}", pre.len()); + // println!("rem.len() {}", rem.len()); + // println!("post_len {}", post_len); + // println!("{:#?}", bounds); // double check that last bound was from a linemarker match bounds.last_mut() { Some(ref mut bound) if bound.method == IncludeMethod::CPP => { bound.len = pre.len() } @@ -364,7 +360,7 @@ fn parse_linemarkers(buf: &[u8], bounds: &mut Vec, global_offset: Ok(f) => line_to_byte_offset(f.bytes().filter_map(|e| e.ok()), marker.child_line)?, Err(_) => 0, }, - len: rem.len(), + len: rem.len() + post_len, method: IncludeMethod::CPP, }; @@ -435,6 +431,9 @@ pub fn include_files>(path: P) -> Result<(Vec, Vec, @@ -488,7 +487,7 @@ pub fn include_files>(path: P) -> Result<(Vec, Vec>(path: P) -> Result<(Vec, Vec