Move rsvg_g_warning() and rsvg_g_critical() to c_api.rs

parent 3e110499
......@@ -36,7 +36,6 @@ use crate::error::{set_gerror, DefsLookupErrorKind, LoadingError, RenderingError
use crate::handle::{Handle, LoadOptions};
use crate::length::RsvgLength;
use crate::structure::IntrinsicDimensions;
use crate::util::{rsvg_g_critical, rsvg_g_warning};
mod handle_flags {
// The following is entirely stolen from the auto-generated code
......@@ -1504,6 +1503,44 @@ fn warn_on_invalid_id(e: RenderingError) -> RenderingError {
e
}
#[cfg(feature = "c-library")]
pub fn rsvg_g_warning(msg: &str) {
unsafe {
extern "C" {
fn rsvg_g_warning_from_c(msg: *const libc::c_char);
}
rsvg_g_warning_from_c(msg.to_glib_none().0);
}
}
#[cfg(not(feature = "c-library"))]
pub fn rsvg_g_warning(_msg: &str) {
// This, and rsvg_g_critical() below, are intended to be called
// from Rust code which is directly called from the C API. When
// this crate is being built as part of the c-library, the purpose
// of the functions is to call the corresponding glib macros to
// print a warning or a critical error message. When this crate
// is being built as part of the standalone Rust crate, they do
// nothing, since the Rust code is able to propagate an error code
// all the way to the crate's public API.
}
#[cfg(feature = "c-library")]
pub fn rsvg_g_critical(msg: &str) {
unsafe {
extern "C" {
fn rsvg_g_critical_from_c(msg: *const libc::c_char);
}
rsvg_g_critical_from_c(msg.to_glib_none().0);
}
}
#[cfg(not(feature = "c-library"))]
pub fn rsvg_g_critical(_msg: &str) {
}
#[cfg(test)]
mod tests {
use super::*;
......
......@@ -4,9 +4,6 @@ use std::borrow::Cow;
use std::ffi::CStr;
use std::str;
#[cfg(feature = "c-library")]
use glib::translate::*;
/// Converts a `char *` which is known to be valid UTF-8 into a `&str`
///
/// The usual `from_glib_none(s)` allocates an owned String. The
......@@ -36,41 +33,3 @@ pub fn clamp<T: PartialOrd>(val: T, low: T, high: T) -> T {
val
}
}
#[cfg(feature = "c-library")]
pub fn rsvg_g_warning(msg: &str) {
unsafe {
extern "C" {
fn rsvg_g_warning_from_c(msg: *const libc::c_char);
}
rsvg_g_warning_from_c(msg.to_glib_none().0);
}
}
#[cfg(not(feature = "c-library"))]
pub fn rsvg_g_warning(_msg: &str) {
// This, and rsvg_g_critical() below, are intended to be called
// from Rust code which is directly called from the C API. When
// this crate is being built as part of the c-library, the purpose
// of the functions is to call the corresponding glib macros to
// print a warning or a critical error message. When this crate
// is being built as part of the standalone Rust crate, they do
// nothing, since the Rust code is able to propagate an error code
// all the way to the crate's public API.
}
#[cfg(feature = "c-library")]
pub fn rsvg_g_critical(msg: &str) {
unsafe {
extern "C" {
fn rsvg_g_critical_from_c(msg: *const libc::c_char);
}
rsvg_g_critical_from_c(msg.to_glib_none().0);
}
}
#[cfg(not(feature = "c-library"))]
pub fn rsvg_g_critical(_msg: &str) {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment