[librsvg] rsvg_handle_new_from_flags(): Port the implementation to Rust



commit 46b5a286cb8ce43578ce6fc8b8c730291c532d47
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jan 16 14:10:22 2019 -0600

    rsvg_handle_new_from_flags(): Port the implementation to Rust

 librsvg/rsvg-handle.c        |  5 ++---
 rsvg_internals/src/handle.rs | 18 ++++++++++++++----
 rsvg_internals/src/lib.rs    |  1 +
 3 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 88621087..c86b76e1 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -181,6 +181,7 @@ extern void rsvg_handle_rust_set_size_callback (RsvgHandleRust *raw_handle,
                                                 RsvgSizeFunc size_func,
                                                 gpointer user_data,
                                                 GDestroyNotify destroy_notify);
+extern RsvgHandle *rsvg_handle_rust_new_with_flags (RsvgHandleFlags flags);
 extern RsvgHandle *rsvg_handle_rust_new_from_file (const char *filename,
                                                    GError **error);
 extern RsvgHandle *rsvg_handle_rust_new_from_gfile_sync (GFile *file,
@@ -520,9 +521,7 @@ rsvg_handle_new_from_file (const gchar *filename, GError **error)
 RsvgHandle *
 rsvg_handle_new_with_flags (RsvgHandleFlags flags)
 {
-    return g_object_new (RSVG_TYPE_HANDLE,
-                         "flags", flags,
-                         NULL);
+    return rsvg_handle_rust_new_with_flags (flags);
 }
 
 /**
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index c7516f21..ca49adad 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -14,7 +14,7 @@ use gdk_pixbuf_sys;
 use gio::{self, FileExt};
 use gio_sys;
 use glib::translate::*;
-use glib::{Bytes, Cast};
+use glib::{self, Bytes, Cast};
 use glib_sys;
 use gobject_sys;
 use libc;
@@ -569,7 +569,7 @@ impl LoadFlags {
 
 #[allow(improper_ctypes)]
 extern "C" {
-    fn rsvg_handle_new_with_flags(flags: u32) -> *mut RsvgHandle;
+    fn rsvg_handle_get_type() -> glib_sys::GType;
 
     fn rsvg_handle_get_rust(handle: *const RsvgHandle) -> *mut Handle;
 }
@@ -1012,6 +1012,16 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_position_sub(
     }
 }
 
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_new_with_flags(flags: u32) -> *mut RsvgHandle {
+    let obj: *mut gobject_sys::GObject =
+        glib::Object::new(from_glib(rsvg_handle_get_type()), &[("flags", &flags)])
+            .unwrap()
+            .to_glib_full();
+
+    obj as *mut _
+}
+
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_handle_rust_new_from_file(
     filename: *const libc::c_char,
@@ -1040,7 +1050,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_new_from_gfile_sync(
     cancellable: *mut gio_sys::GCancellable,
     error: *mut *mut glib_sys::GError,
 ) -> *mut RsvgHandle {
-    let raw_handle = rsvg_handle_new_with_flags(flags);
+    let raw_handle = rsvg_handle_rust_new_with_flags(flags);
 
     let rhandle = get_rust_handle(raw_handle);
 
@@ -1066,7 +1076,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_new_from_stream_sync(
     cancellable: *mut gio_sys::GCancellable,
     error: *mut *mut glib_sys::GError,
 ) -> *mut RsvgHandle {
-    let raw_handle = rsvg_handle_new_with_flags(flags);
+    let raw_handle = rsvg_handle_rust_new_with_flags(flags);
 
     let rhandle = get_rust_handle(raw_handle);
 
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 72e7d572..fdafca77 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -58,6 +58,7 @@ pub use handle::{
     rsvg_handle_rust_new_from_file,
     rsvg_handle_rust_new_from_gfile_sync,
     rsvg_handle_rust_new_from_stream_sync,
+    rsvg_handle_rust_new_with_flags,
     rsvg_handle_rust_read_stream_sync,
     rsvg_handle_rust_render_cairo_sub,
     rsvg_handle_rust_set_base_gfile,


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