[librsvg: 3/18] Move all the GError machinery to c_api.rs
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/18] Move all the GError machinery to c_api.rs
- Date: Sat, 7 Dec 2019 02:38:17 +0000 (UTC)
commit be1f3edcd463d4fd1faf1564403eea3c0064c449
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Dec 5 22:05:29 2019 -0600
Move all the GError machinery to c_api.rs
It is not needed in rsvg_internals anymore.
librsvg/c_api.rs | 53 +++++++++++++++++++++++++++++++++++++++++++--
librsvg/pixbuf_utils.rs | 4 +++-
rsvg_internals/src/error.rs | 52 --------------------------------------------
rsvg_internals/src/lib.rs | 9 ++------
4 files changed, 56 insertions(+), 62 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 9b05d4aa..8086f935 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -11,6 +11,7 @@ use cairo::{self, ImageSurface};
use cairo_sys;
use gdk_pixbuf::Pixbuf;
use gdk_pixbuf_sys;
+use glib::error::ErrorDomain;
use libc;
use url::Url;
@@ -34,9 +35,9 @@ use glib_sys;
use gobject_sys::{self, GEnumValue, GFlagsValue};
use rsvg_internals::{
- rsvg_log, set_gerror, DefsLookupErrorKind, Dpi, Handle, IntrinsicDimensions,
+ rsvg_log, DefsLookupErrorKind, Dpi, Handle, IntrinsicDimensions,
LoadOptions, LoadingError, RenderingError, RsvgDimensionData, RsvgLength, RsvgPositionData,
- RsvgSizeFunc, SharedImageSurface, SizeCallback, SurfaceType, ViewBox, RSVG_ERROR_FAILED,
+ RsvgSizeFunc, SharedImageSurface, SizeCallback, SurfaceType, ViewBox,
};
use crate::pixbuf_utils::{empty_pixbuf, pixbuf_from_surface};
@@ -1530,6 +1531,54 @@ fn rsvg_g_critical(msg: &str) {
}
}
+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
+ assert!(code == 0);
+
+ glib_sys::g_set_error_literal(
+ err,
+ rsvg_rust_error_quark(),
+ code as libc::c_int,
+ msg.to_glib_none().0,
+ );
+ }
+}
+
+/// Used as a generic error to translate to glib::Error
+///
+/// This type implements `glib::error::ErrorDomain`, so it can be used
+/// to obtain the error code while calling `glib::Error::new()`. Unfortunately
+/// the public librsvg API does not have detailed error codes yet, so we use
+/// this single value as the only possible error code to return.
+#[derive(Copy, Clone)]
+pub struct RsvgError;
+
+// Keep in sync with rsvg.h:RsvgError
+pub const RSVG_ERROR_FAILED: i32 = 0;
+
+impl ErrorDomain for RsvgError {
+ fn domain() -> glib::Quark {
+ glib::Quark::from_string("rsvg-error-quark")
+ }
+
+ fn code(self) -> i32 {
+ RSVG_ERROR_FAILED
+ }
+
+ fn from(code: i32) -> Option<Self> {
+ match code {
+ // We don't have enough information from glib error codes
+ _ => Some(RsvgError),
+ }
+ }
+}
+
+#[no_mangle]
+pub extern "C" fn rsvg_rust_error_quark() -> glib_sys::GQuark {
+ RsvgError::domain().to_glib()
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/librsvg/pixbuf_utils.rs b/librsvg/pixbuf_utils.rs
index fa3b8ede..463e103a 100644
--- a/librsvg/pixbuf_utils.rs
+++ b/librsvg/pixbuf_utils.rs
@@ -12,10 +12,12 @@ use libc;
use url::Url;
use rsvg_internals::{
- set_gerror, Dpi, Handle, IRect, LoadOptions, LoadingError, Pixels, RenderingError,
+ Dpi, Handle, IRect, LoadOptions, LoadingError, Pixels, RenderingError,
RsvgDimensionData, SharedImageSurface, SizeCallback, SurfaceType,
};
+use crate::c_api::set_gerror;
+
fn pixbuf_new(width: i32, height: i32) -> Result<Pixbuf, RenderingError> {
assert!(width > 0 && height > 0);
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 2ae9878d..a27170c9 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -4,10 +4,6 @@ use std::fmt;
use cairo;
use cssparser::BasicParseError;
use glib;
-use glib::error::ErrorDomain;
-use glib::translate::*;
-use glib_sys;
-use libc;
use markup5ever::QualName;
use crate::allowed_url::Fragment;
@@ -313,20 +309,6 @@ impl From<glib::Error> for LoadingError {
}
}
-pub 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
- assert!(code == 0);
-
- glib_sys::g_set_error_literal(
- err,
- rsvg_rust_error_quark(),
- code as libc::c_int,
- msg.to_glib_none().0,
- );
- }
-}
-
#[cfg(test)]
pub fn is_parse_error<T>(r: &Result<T, ValueErrorKind>) -> bool {
match *r {
@@ -342,37 +324,3 @@ pub fn is_value_error<T>(r: &Result<T, ValueErrorKind>) -> bool {
_ => false,
}
}
-
-/// Used as a generic error to translate to glib::Error
-///
-/// This type implements `glib::error::ErrorDomain`, so it can be used
-/// to obtain the error code while calling `glib::Error::new()`. Unfortunately
-/// the public librsvg API does not have detailed error codes yet, so we use
-/// this single value as the only possible error code to return.
-#[derive(Copy, Clone)]
-pub struct RsvgError;
-
-// Keep in sync with rsvg.h:RsvgError
-pub const RSVG_ERROR_FAILED: i32 = 0;
-
-impl ErrorDomain for RsvgError {
- fn domain() -> glib::Quark {
- glib::Quark::from_string("rsvg-error-quark")
- }
-
- fn code(self) -> i32 {
- RSVG_ERROR_FAILED
- }
-
- fn from(code: i32) -> Option<Self> {
- match code {
- // We don't have enough information from glib error codes
- _ => Some(RsvgError),
- }
- }
-}
-
-#[no_mangle]
-pub extern "C" fn rsvg_rust_error_quark() -> glib_sys::GQuark {
- RsvgError::domain().to_glib()
-}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 2872782f..7b2bd688 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -44,10 +44,7 @@ pub use crate::color::{rsvg_css_parse_color, ColorKind, ColorSpec};
pub use crate::dpi::{rsvg_rust_set_default_dpi_x_y, Dpi};
-pub use crate::error::{
- rsvg_rust_error_quark, set_gerror, DefsLookupErrorKind, HrefError, LoadingError,
- RenderingError, RSVG_ERROR_FAILED,
-};
+pub use crate::error::{DefsLookupErrorKind, HrefError, LoadingError, RenderingError};
pub use crate::handle::{
Handle, LoadOptions, RsvgDimensionData, RsvgPositionData, RsvgSizeFunc, SizeCallback,
@@ -61,9 +58,7 @@ pub use crate::structure::IntrinsicDimensions;
pub use crate::surface_utils::{
iterators::Pixels,
- shared_surface::{
- SharedImageSurface, SurfaceType,
- },
+ shared_surface::{SharedImageSurface, SurfaceType},
};
pub use crate::viewbox::ViewBox;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]