From c45ced7599ad187aa94c616f3f8586520cb004a9 Mon Sep 17 00:00:00 2001 From: Rubens Brandao Date: Mon, 22 Apr 2024 10:43:00 -0300 Subject: [PATCH] only create FlowGraph with Ref --- rust/examples/dwarf/dwarfdump/src/lib.rs | 2 +- rust/examples/flowgraph/src/lib.rs | 2 +- rust/src/binaryview.rs | 2 +- rust/src/flowgraph.rs | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/rust/examples/dwarf/dwarfdump/src/lib.rs b/rust/examples/dwarf/dwarfdump/src/lib.rs index 8c6b32b78..c062ac63d 100644 --- a/rust/examples/dwarf/dwarfdump/src/lib.rs +++ b/rust/examples/dwarf/dwarfdump/src/lib.rs @@ -281,7 +281,7 @@ fn dump_dwarf(bv: &BinaryView) { } } - view.show_graph_report("DWARF", graph); + view.show_graph_report("DWARF", &graph); } struct DWARFDump; diff --git a/rust/examples/flowgraph/src/lib.rs b/rust/examples/flowgraph/src/lib.rs index 0375705dd..2a03341c8 100644 --- a/rust/examples/flowgraph/src/lib.rs +++ b/rust/examples/flowgraph/src/lib.rs @@ -36,7 +36,7 @@ fn test_graph(view: &BinaryView) { &EdgeStyle::default(), ); - view.show_graph_report("Rust Graph Title", graph); + view.show_graph_report("Rust Graph Title", &graph); } #[no_mangle] diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 52d688b84..7953da251 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -1056,7 +1056,7 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNApplyDebugInfo(self.as_ref().handle, debug_info.handle) } } - fn show_graph_report(&self, raw_name: S, graph: FlowGraph) { + fn show_graph_report(&self, raw_name: S, graph: &FlowGraph) { let raw_name = raw_name.into_bytes_with_nul(); unsafe { BNShowGraphReport( diff --git a/rust/src/flowgraph.rs b/rust/src/flowgraph.rs index 9d95cc495..c2d4d559e 100644 --- a/rust/src/flowgraph.rs +++ b/rust/src/flowgraph.rs @@ -114,8 +114,6 @@ impl<'a> ToOwned for FlowGraphNode<'a> { } } -// TODO : FlowGraph are RefCounted objects, this needs to be changed to only return Refs to FlowGraph - #[derive(PartialEq, Eq, Hash)] pub struct FlowGraph { pub(crate) handle: *mut BNFlowGraph, @@ -126,8 +124,8 @@ impl FlowGraph { Self { handle: raw } } - pub fn new() -> Self { - unsafe { FlowGraph::from_raw(BNCreateFlowGraph()) } + pub fn new() -> Ref { + unsafe { Ref::new(FlowGraph::from_raw(BNCreateFlowGraph())) } } pub fn append(&self, node: &FlowGraphNode) -> usize {