[librsvg: 1/8] Move rsvg_g_warning and rsvg_g_critical to messages.rs



commit e0267975b75dd16a1f39487f199f5173656a7fa8
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Apr 8 17:15:42 2020 -0500

    Move rsvg_g_warning and rsvg_g_critical to messages.rs

 Makefile.am         |  1 +
 librsvg/c_api.rs    | 79 +----------------------------------------------------
 librsvg/lib.rs      |  1 +
 librsvg/messages.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 78 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index bf2c1888..0b1e2aa3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,6 +119,7 @@ LIBRSVG_C_API_SRC =                                         \
        librsvg/c_api.rs                                        \
        librsvg/color_utils.rs                                  \
        librsvg/lib.rs                                          \
+       librsvg/messages.rs                                     \
        librsvg/pixbuf_utils.rs                                 \
        $(NULL)
 
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 8bdb59a1..c29c9d7c 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -27,8 +27,6 @@ use glib::{
     ToValue, Type, Value,
 };
 
-use glib_sys::{G_LOG_LEVEL_WARNING, G_LOG_LEVEL_CRITICAL, GLogField, g_log_structured_array};
-
 use gobject_sys::{GEnumValue, GFlagsValue};
 
 use rsvg_internals::{
@@ -37,6 +35,7 @@ use rsvg_internals::{
     SharedImageSurface, SizeCallback, SurfaceType, ViewBox,
 };
 
+use crate::messages::{rsvg_g_critical, rsvg_g_warning};
 use crate::pixbuf_utils::{empty_pixbuf, pixbuf_from_surface};
 
 mod handle_flags {
@@ -1557,82 +1556,6 @@ fn warn_on_invalid_id(e: RenderingError) -> RenderingError {
     e
 }
 
-/*
-  G_LOG_LEVEL_CRITICAL          = 1 << 3,
-  G_LOG_LEVEL_WARNING           = 1 << 4,
-
-#define g_critical(...) g_log_structured_standard (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
-                                                   __FILE__, G_STRINGIFY (__LINE__), \
-                                                   G_STRFUNC, __VA_ARGS__)
-#define g_warning(...)  g_log_structured_standard (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, \
-                                                   __FILE__, G_STRINGIFY (__LINE__), \
-                                                   G_STRFUNC, __VA_ARGS__)
-  GLogField fields[] =
-    {
-      { "PRIORITY", log_level_to_priority (log_level), -1 },
-      { "CODE_FILE", file, -1 },
-      { "CODE_LINE", line, -1 },
-      { "CODE_FUNC", func, -1 },
-      /* Filled in later: */
-      { "MESSAGE", NULL, -1 },
-      /* If @log_domain is %NULL, we will not pass this field: */
-      { "GLIB_DOMAIN", log_domain, -1 },
-    };
-
-  g_log_structured_array (log_level, fields, n_fields);
- */
-
-/// Helper for `rsvg_g_warning` and `rsvg_g_critical`
-///
-/// This simulates what in C would be a call to the g_warning() or g_critical()
-/// macros, but with the underlying function g_log_structured_array().
-///
-/// If the implementation of g_warning() or g_critical() changes, we'll have
-/// to change this function.
-fn rsvg_g_log(level: glib_sys::GLogLevelFlags, msg: &str) {
-    // stolen from gmessages.c:log_level_to_priority()
-    let priority = match level {
-        G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL => b"4\0",
-        _ => unreachable!("please add another log level priority to rsvg_g_log()"),
-    };
-
-    // Glib's g_log_structured_standard() adds a few more fields for the source
-    // file, line number, etc., but those are not terribly useful without a stack
-    // trace.  So, we'll omit them.
-    let fields = [
-        GLogField {
-            key: b"PRIORITY\0" as *const u8 as *const _,
-            value: priority as *const u8 as *const _,
-            length: -1,
-        },
-
-        GLogField {
-            key: b"MESSAGE\0" as *const u8 as *const _,
-            value: msg.as_ptr() as *const _,
-            length: msg.len() as _,
-        },
-
-        // This is the G_LOG_DOMAIN set from the Makefile
-        GLogField {
-            key: b"GLIB_DOMAIN\0" as *const u8 as *const _,
-            value: b"librsvg\0" as *const u8 as *const _,
-            length: -1,
-        },
-    ];
-
-    unsafe {
-        g_log_structured_array(level, fields.as_ptr(), fields.len());
-    }
-}
-
-fn rsvg_g_warning(msg: &str) {
-    rsvg_g_log(glib_sys::G_LOG_LEVEL_WARNING, msg);
-}
-
-fn rsvg_g_critical(msg: &str) {
-    rsvg_g_log(glib_sys::G_LOG_LEVEL_CRITICAL, msg);
-}
-
 pub(crate) fn set_gerror(err: *mut *mut glib_sys::GError, code: u32, msg: &str) {
     unsafe {
         // this is RSVG_ERROR_FAILED, the only error code available in RsvgError
diff --git a/librsvg/lib.rs b/librsvg/lib.rs
index 6a5b8c16..f408bdb6 100644
--- a/librsvg/lib.rs
+++ b/librsvg/lib.rs
@@ -50,4 +50,5 @@ pub use crate::pixbuf_utils::{
 
 mod c_api;
 mod color_utils;
+mod messages;
 mod pixbuf_utils;
diff --git a/librsvg/messages.rs b/librsvg/messages.rs
new file mode 100644
index 00000000..09c7979b
--- /dev/null
+++ b/librsvg/messages.rs
@@ -0,0 +1,77 @@
+use glib_sys::{G_LOG_LEVEL_WARNING, G_LOG_LEVEL_CRITICAL, GLogField, g_log_structured_array};
+
+/*
+  G_LOG_LEVEL_CRITICAL          = 1 << 3,
+  G_LOG_LEVEL_WARNING           = 1 << 4,
+
+#define g_critical(...) g_log_structured_standard (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
+                                                   __FILE__, G_STRINGIFY (__LINE__), \
+                                                   G_STRFUNC, __VA_ARGS__)
+#define g_warning(...)  g_log_structured_standard (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, \
+                                                   __FILE__, G_STRINGIFY (__LINE__), \
+                                                   G_STRFUNC, __VA_ARGS__)
+  GLogField fields[] =
+    {
+      { "PRIORITY", log_level_to_priority (log_level), -1 },
+      { "CODE_FILE", file, -1 },
+      { "CODE_LINE", line, -1 },
+      { "CODE_FUNC", func, -1 },
+      /* Filled in later: */
+      { "MESSAGE", NULL, -1 },
+      /* If @log_domain is %NULL, we will not pass this field: */
+      { "GLIB_DOMAIN", log_domain, -1 },
+    };
+
+  g_log_structured_array (log_level, fields, n_fields);
+ */
+
+/// Helper for `rsvg_g_warning` and `rsvg_g_critical`
+///
+/// This simulates what in C would be a call to the g_warning() or g_critical()
+/// macros, but with the underlying function g_log_structured_array().
+///
+/// If the implementation of g_warning() or g_critical() changes, we'll have
+/// to change this function.
+fn rsvg_g_log(level: glib_sys::GLogLevelFlags, msg: &str) {
+    // stolen from gmessages.c:log_level_to_priority()
+    let priority = match level {
+        G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL => b"4\0",
+        _ => unreachable!("please add another log level priority to rsvg_g_log()"),
+    };
+
+    // Glib's g_log_structured_standard() adds a few more fields for the source
+    // file, line number, etc., but those are not terribly useful without a stack
+    // trace.  So, we'll omit them.
+    let fields = [
+        GLogField {
+            key: b"PRIORITY\0" as *const u8 as *const _,
+            value: priority as *const u8 as *const _,
+            length: -1,
+        },
+
+        GLogField {
+            key: b"MESSAGE\0" as *const u8 as *const _,
+            value: msg.as_ptr() as *const _,
+            length: msg.len() as _,
+        },
+
+        // This is the G_LOG_DOMAIN set from the Makefile
+        GLogField {
+            key: b"GLIB_DOMAIN\0" as *const u8 as *const _,
+            value: b"librsvg\0" as *const u8 as *const _,
+            length: -1,
+        },
+    ];
+
+    unsafe {
+        g_log_structured_array(level, fields.as_ptr(), fields.len());
+    }
+}
+
+pub fn rsvg_g_warning(msg: &str) {
+    rsvg_g_log(glib_sys::G_LOG_LEVEL_WARNING, msg);
+}
+
+pub fn rsvg_g_critical(msg: &str) {
+    rsvg_g_log(glib_sys::G_LOG_LEVEL_CRITICAL, msg);
+}


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