[librsvg] rsvg_g_warning(): Mechanism to call g_warning() from Rust



commit 9207856546d206d1b3cd01bc34b5396901af273e
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Nov 29 10:48:47 2018 -0600

    rsvg_g_warning(): Mechanism to call g_warning() from Rust

 librsvg/rsvg-base.c        | 12 ++++++++++++
 rsvg_internals/src/util.rs | 12 ++++++++++++
 2 files changed, 24 insertions(+)
---
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 2242fadb..d086f353 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -158,3 +158,15 @@ rsvg_css_parse_color_ (const char *str)
 {
     return rsvg_css_parse_color (str);
 }
+
+G_GNUC_INTERNAL
+void rsvg_g_warning_from_c(const char *msg);
+
+/* This function exists just so that we can effectively call g_warning() from Rust,
+ * since glib-rs doesn't bind the g_log functions yet.
+ */
+void
+rsvg_g_warning_from_c(const char *msg)
+{
+    g_warning ("%s", msg);
+}
diff --git a/rsvg_internals/src/util.rs b/rsvg_internals/src/util.rs
index 1117b51e..ab5cd5be 100644
--- a/rsvg_internals/src/util.rs
+++ b/rsvg_internals/src/util.rs
@@ -3,6 +3,8 @@ use libc;
 use std::ffi::CStr;
 use std::str;
 
+use glib::translate::*;
+
 // In paint servers (patterns, gradients, etc.), we have an
 // Option<String> for fallback names.  This is a utility function to
 // clone one of those.
@@ -35,3 +37,13 @@ pub fn clamp<T: PartialOrd>(val: T, low: T, high: T) -> T {
         val
     }
 }
+
+extern "C" {
+    fn rsvg_g_warning_from_c(msg: *const libc::c_char);
+}
+
+pub fn rsvg_g_warning(msg: &str) {
+    unsafe {
+        rsvg_g_warning_from_c(msg.to_glib_none().0);
+    }
+}


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