[librsvg] Use plain Pixbuf::new() now that it detects out-of-memory properly



commit 5c986d598297c88a6621301d8a7d03d588207900
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Oct 3 10:00:31 2019 -0500

    Use plain Pixbuf::new() now that it detects out-of-memory properly

 rsvg_internals/src/pixbuf_utils.rs | 33 ++++-----------------------------
 1 file changed, 4 insertions(+), 29 deletions(-)
---
diff --git a/rsvg_internals/src/pixbuf_utils.rs b/rsvg_internals/src/pixbuf_utils.rs
index bab49565..041ee1ad 100644
--- a/rsvg_internals/src/pixbuf_utils.rs
+++ b/rsvg_internals/src/pixbuf_utils.rs
@@ -21,45 +21,20 @@ use crate::surface_utils::{
     shared_surface::SurfaceType,
 };
 
-// Pixbuf::new() doesn't return out-of-memory errors properly
-// See https://github.com/gtk-rs/gdk-pixbuf/issues/96
 fn pixbuf_new(width: i32, height: i32) -> Result<Pixbuf, RenderingError> {
     assert!(width > 0 && height > 0);
 
-    unsafe {
-        let raw_pixbuf = gdk_pixbuf_sys::gdk_pixbuf_new(
-            Colorspace::Rgb.to_glib(),
-            true.to_glib(),
-            8,
-            width,
-            height,
-        );
-
-        if raw_pixbuf.is_null() {
-            return Err(RenderingError::OutOfMemory);
-        }
-
-        Ok(from_glib_full(raw_pixbuf))
-    }
+    Pixbuf::new(Colorspace::Rgb, true, 8, width, height).ok_or(RenderingError::OutOfMemory)
 }
 
 pub fn empty_pixbuf() -> Result<Pixbuf, RenderingError> {
     // GdkPixbuf does not allow zero-sized pixbufs, but Cairo allows zero-sized
     // surfaces.  In this case, return a 1-pixel transparent pixbuf.
 
-    unsafe {
-        let raw_pixbuf =
-            gdk_pixbuf_sys::gdk_pixbuf_new(Colorspace::Rgb.to_glib(), true.to_glib(), 8, 1, 1);
-
-        if raw_pixbuf.is_null() {
-            return Err(RenderingError::OutOfMemory);
-        }
+    let pixbuf = pixbuf_new(1, 1)?;
+    pixbuf.put_pixel(0, 0, 0, 0, 0, 0);
 
-        let pixbuf: Pixbuf = from_glib_full(raw_pixbuf);
-        pixbuf.put_pixel(0, 0, 0, 0, 0, 0);
-
-        Ok(pixbuf)
-    }
+    Ok(pixbuf)
 }
 
 pub fn pixbuf_from_surface(surface: &SharedImageSurface) -> Result<Pixbuf, RenderingError> {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]