From ed60d98bc6fa0d61d77abc1a86f93b97b76e46b3 Mon Sep 17 00:00:00 2001 From: enawder <60314455+enawder@users.noreply.github.com> Date: Mon, 5 Aug 2024 22:47:18 +0200 Subject: [PATCH] Release owned pointer when dropping PopplerDocument and PopplerPage (#12) Co-authored-by: Denys Vitali --- Cargo.toml | 1 + src/lib.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dbac33b..8cf257c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ render = ["dep:cairo-rs"] [dependencies] cairo-rs = { version = "0.18.5", features = ["png", "pdf"], optional = true } glib = "0.18.5" +gobject-sys = "0.15" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 4607c16..fda5319 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,6 +125,14 @@ impl PopplerDocument { } } +impl Drop for PopplerDocument { + fn drop(&mut self) { + unsafe { + gobject_sys::g_object_unref(self.0 as *mut gobject_sys::GObject); + } + } +} + impl PopplerPage { pub fn get_size(&self) -> (f64, f64) { let mut width: f64 = 0.0; @@ -182,6 +190,14 @@ impl<'a> Iterator for PagesIter<'a> { } } +impl Drop for PopplerPage { + fn drop(&mut self) { + unsafe { + gobject_sys::g_object_unref(self.0 as *mut gobject_sys::GObject); + } + } +} + #[cfg(test)] mod tests { use crate::PopplerDocument; @@ -226,7 +242,6 @@ mod tests { ctx.show_page().unwrap(); })(&ctx); } - // g_object_unref (page); //surface.write_to_png("file.png"); #[cfg(feature = "render")] surface.finish();