From b938c7daabf77f1a080d215266065449728a55c1 Mon Sep 17 00:00:00 2001 From: RedPhoenixQ Date: Sat, 28 Sep 2024 21:35:42 +0200 Subject: [PATCH 1/2] Bump quick-xml to 0.37.0 change error types to io::Error --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/bin/flamegraph.rs | 4 ++-- src/flamegraph/merge.rs | 6 +++--- src/flamegraph/mod.rs | 44 ++++++++++++++++++----------------------- src/flamegraph/svg.rs | 10 +++++----- tests/flamegraph.rs | 6 +++--- 7 files changed, 35 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39102f3a..18de8d44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -713,9 +713,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.26.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" +checksum = "ffbfb3ddf5364c9cfcd65549a1e7b801d0e8d1b14c1a1590a6408aa93cfbfa84" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 8b393baf..4e7ead80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ indexmap = { version = "2.0", optional = true } itoa = "1" log = "0.4" num-format = { version = "0.4.3", default-features = false } -quick-xml = { version = "0.26", default-features = false } +quick-xml = { version = "0.37", default-features = false } rgb = "0.8.13" str_stack = "0.1" clap = { version = "4.0.1", optional = true, features = ["derive"] } diff --git a/src/bin/flamegraph.rs b/src/bin/flamegraph.rs index 6b7606e3..f82cf076 100644 --- a/src/bin/flamegraph.rs +++ b/src/bin/flamegraph.rs @@ -309,7 +309,7 @@ impl<'a> Opt { const PALETTE_MAP_FILE: &str = "palette.map"; // default name for the palette map file -fn main() -> quick_xml::Result<()> { +fn main() -> io::Result<()> { let opt = Opt::parse(); // Initialize logger @@ -343,7 +343,7 @@ fn main() -> quick_xml::Result<()> { )?; } - save_consistent_palette_if_needed(&palette_map, PALETTE_MAP_FILE).map_err(quick_xml::Error::Io) + save_consistent_palette_if_needed(&palette_map, PALETTE_MAP_FILE) } fn fetch_consistent_palette_if_needed( diff --git a/src/flamegraph/merge.rs b/src/flamegraph/merge.rs index 83c4c422..056c0993 100644 --- a/src/flamegraph/merge.rs +++ b/src/flamegraph/merge.rs @@ -109,7 +109,7 @@ fn flow<'a, LI, TI>( pub(super) fn frames<'a, I>( lines: I, suppress_sort_check: bool, -) -> quick_xml::Result<(Vec>, usize, usize, usize)> +) -> io::Result<(Vec>, usize, usize, usize)> where I: IntoIterator, { @@ -128,10 +128,10 @@ where if !suppress_sort_check { if let Some(prev_line) = prev_line { if prev_line > line { - return Err(quick_xml::Error::Io(io::Error::new( + return Err(io::Error::new( io::ErrorKind::InvalidData, "unsorted input lines detected", - ))); + )); } } } diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 86a5f99b..e43422e4 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -393,7 +393,7 @@ impl Rectangle { /// /// [differential flame graph]: http://www.brendangregg.com/blog/2014-11-09/differential-flame-graphs.html #[allow(clippy::cognitive_complexity)] -pub fn from_lines<'a, I, W>(opt: &mut Options<'_>, lines: I, writer: W) -> quick_xml::Result<()> +pub fn from_lines<'a, I, W>(opt: &mut Options<'_>, lines: I, writer: W) -> io::Result<()> where I: IntoIterator, W: Write, @@ -500,10 +500,10 @@ where )?; svg.write_event(Event::End(BytesEnd::new("svg")))?; svg.write_event(Event::Eof)?; - return Err(quick_xml::Error::Io(io::Error::new( + return Err(io::Error::new( io::ErrorKind::InvalidData, "No stack counts found", - ))); + )); } let image_width = opt.image_width.unwrap_or(DEFAULT_IMAGE_WIDTH) as f64; @@ -724,9 +724,9 @@ where buffer.clear(); if has_href { - svg.write_event(&cache_a_end)?; + svg.write_event(cache_a_end.borrow())?; } else { - svg.write_event(&cache_g_end)?; + svg.write_event(cache_g_end.borrow())?; } } @@ -746,7 +746,7 @@ fn write_container_start<'a, W: Write>( cache_g: &mut Event<'_>, frame: &merge::TimedFrame<'_>, mut title: &'a str, -) -> quick_xml::Result<(bool, &'a str)> { +) -> io::Result<(bool, &'a str)> { let frame_attributes = opt .func_frameattrs .frameattrs_for_func(frame.location.function); @@ -755,18 +755,18 @@ fn write_container_start<'a, W: Write>( if let Some(frame_attributes) = frame_attributes { if frame_attributes.attrs.contains_key("xlink:href") { write_container_attributes(cache_a, frame_attributes); - svg.write_event(cache_a)?; + svg.write_event(cache_a.borrow())?; has_href = true; } else { write_container_attributes(cache_g, frame_attributes); - svg.write_event(cache_g)?; + svg.write_event(cache_g.borrow())?; } if let Some(ref t) = frame_attributes.title { title = t.as_str(); } } else if let Event::Start(ref mut c) = cache_g { c.clear_attributes(); - svg.write_event(cache_g)?; + svg.write_event(cache_g.borrow())?; } Ok((has_href, title)) @@ -780,10 +780,10 @@ fn write_container_start<'a, W: Write>( cache_g: &mut Event<'_>, _frame: &merge::TimedFrame<'_>, title: &'a str, -) -> quick_xml::Result<(bool, &'a str)> { +) -> io::Result<(bool, &'a str)> { if let Event::Start(ref mut c) = cache_g { c.clear_attributes(); - svg.write_event(&cache_g)?; + svg.write_event(cache_g.borrow())?; } Ok((false, title)) @@ -810,7 +810,7 @@ fn write_container_attributes(event: &mut Event<'_>, frame_attributes: &FrameAtt /// See [`from_lines`] for the expected format of each line. /// /// The resulting flame graph will be written out to `writer` in SVG format. -pub fn from_reader(opt: &mut Options<'_>, reader: R, writer: W) -> quick_xml::Result<()> +pub fn from_reader(opt: &mut Options<'_>, reader: R, writer: W) -> io::Result<()> where R: Read, W: Write, @@ -823,7 +823,7 @@ where /// See [`from_lines`] for the expected format of each line. /// /// The resulting flame graph will be written out to `writer` in SVG format. -pub fn from_readers(opt: &mut Options<'_>, readers: R, writer: W) -> quick_xml::Result<()> +pub fn from_readers(opt: &mut Options<'_>, readers: R, writer: W) -> io::Result<()> where R: IntoIterator, R::Item: Read, @@ -831,9 +831,7 @@ where { let mut input = String::new(); for mut reader in readers { - reader - .read_to_string(&mut input) - .map_err(quick_xml::Error::Io)?; + reader.read_to_string(&mut input)?; } from_lines(opt, input.lines(), writer) } @@ -842,17 +840,13 @@ where /// and write the result to provided `writer`. /// /// If files is empty, STDIN will be used as input. -pub fn from_files( - opt: &mut Options<'_>, - files: &[PathBuf], - writer: W, -) -> quick_xml::Result<()> { +pub fn from_files(opt: &mut Options<'_>, files: &[PathBuf], writer: W) -> io::Result<()> { if files.is_empty() || files.len() == 1 && files[0].to_str() == Some("-") { let stdin = io::stdin(); let r = BufReader::with_capacity(128 * 1024, stdin.lock()); from_reader(opt, r, writer) } else if files.len() == 1 { - let r = File::open(&files[0]).map_err(quick_xml::Error::Io)?; + let r = File::open(&files[0])?; from_reader(opt, r, writer) } else { let stdin = io::stdin(); @@ -866,7 +860,7 @@ pub fn from_files( stdin_added = true; } } else { - let r = File::open(infile).map_err(quick_xml::Error::Io)?; + let r = File::open(infile)?; readers.push(Box::new(r)); } } @@ -892,7 +886,7 @@ fn filled_rectangle( rect: &Rectangle, color: Color, cache_rect: &mut Event<'_>, -) -> quick_xml::Result<()> { +) -> io::Result<()> { let x = write!(buffer, "{:.4}%", rect.x1_pct); let y = write_usize(buffer, rect.y1); let width = write!(buffer, "{:.4}%", rect.width_pct()); @@ -916,7 +910,7 @@ fn filled_rectangle( } else { unreachable!("cache wrapper was of wrong type: {:?}", cache_rect); } - svg.write_event(cache_rect) + svg.write_event(cache_rect.borrow()) } fn write_usize(buffer: &mut StrStack, value: usize) -> usize { diff --git a/src/flamegraph/svg.rs b/src/flamegraph/svg.rs index 5055bab6..0ac955af 100644 --- a/src/flamegraph/svg.rs +++ b/src/flamegraph/svg.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; use std::cell::RefCell; -use std::io::prelude::*; +use std::io::{self, prelude::*}; use std::iter; use quick_xml::events::{BytesCData, BytesDecl, BytesEnd, BytesStart, BytesText, Event}; @@ -59,7 +59,7 @@ pub(super) fn write_header( svg: &mut Writer, imageheight: usize, opt: &Options<'_>, -) -> quick_xml::Result<()> +) -> io::Result<()> where W: Write, { @@ -91,7 +91,7 @@ pub(super) fn write_prelude( svg: &mut Writer, style_options: &StyleOptions, opt: &Options<'_>, -) -> quick_xml::Result<()> +) -> io::Result<()> where W: Write, { @@ -261,7 +261,7 @@ pub(super) fn write_str<'a, W, I>( svg: &mut Writer, buf: &mut StrStack, item: TextItem<'a, I>, -) -> quick_xml::Result<()> +) -> std::io::Result<()> where W: Write, I: IntoIterator, @@ -290,7 +290,7 @@ where unreachable!("cache wrapper was of wrong type: {:?}", start_event); } - svg.write_event(&*start_event.borrow()) + svg.write_event(start_event.borrow().borrow()) })?; let s = match text { TextArgument::String(ref s) => s, diff --git a/tests/flamegraph.rs b/tests/flamegraph.rs index 9f30dc50..167da77c 100644 --- a/tests/flamegraph.rs +++ b/tests/flamegraph.rs @@ -17,7 +17,7 @@ fn test_flamegraph( input_file: &str, expected_result_file: &str, options: Options<'_>, -) -> quick_xml::Result<()> { +) -> io::Result<()> { test_flamegraph_multiple_files( vec![PathBuf::from_str(input_file).unwrap()], expected_result_file, @@ -29,7 +29,7 @@ fn test_flamegraph_multiple_files( input_files: Vec, expected_result_file: &str, mut options: Options<'_>, -) -> quick_xml::Result<()> { +) -> io::Result<()> { // Always pretty print XML to make it easier to find differences when tests fail. options.pretty_xml = true; // Never include static JavaScript in tests so we don't have to have it duplicated @@ -45,7 +45,7 @@ fn test_flamegraph_multiple_files( flamegraph::from_files(&mut options, &input_files, &mut f)?; fs::metadata(expected_result_file).unwrap() } else { - return Err(e.into()); + return Err(e); } } }; From d717b6b02afb37448274922a918b4044771134e1 Mon Sep 17 00:00:00 2001 From: RedPhoenixQ Date: Sun, 27 Oct 2024 15:12:29 +0100 Subject: [PATCH 2/2] Add changelog for quick_xml public API changes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c602447..a3ba6ebc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Remove `quick_xml::Error` from the public API. [#332](https://github.com/jonhoo/inferno/pull/332) + ### Removed ## [0.11.21] - 2024-08-03