[librsvg/wip/rust-api: 8/11] rsvg_error_quark(): Port to Rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/wip/rust-api: 8/11] rsvg_error_quark(): Port to Rust
- Date: Sat, 16 Feb 2019 01:35:05 +0000 (UTC)
commit 4357053826708314352d2aa07bfdf28a68fff70b
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Feb 13 18:32:10 2019 -0600
rsvg_error_quark(): Port to Rust
This lets us avoid calling into C to get the error quark from Rust.
librsvg/rsvg-base.c | 7 ++++---
librsvg_crate/src/lib.rs | 4 +++-
rsvg_internals/src/error.rs | 13 +++++++------
rsvg_internals/src/lib.rs | 2 +-
4 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 1afb1582..380176af 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -31,6 +31,9 @@
/* Implemented in rsvg_internals/src/dpi.rs */
extern void rsvg_rust_set_default_dpi_x_y(double dpi_x, double dpi_y);
+/* Implemented in rsvg_internals/src/error.rs */
+extern GQuark rsvg_rust_error_quark (void);
+
/**
* rsvg_error_quark:
*
@@ -41,9 +44,7 @@ extern void rsvg_rust_set_default_dpi_x_y(double dpi_x, double dpi_y);
GQuark
rsvg_error_quark (void)
{
- /* don't use from_static_string(), since librsvg might be used in a module
- that's ultimately unloaded */
- return g_quark_from_string ("rsvg-error-quark");
+ return rsvg_rust_error_quark ();
}
/**
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index 48f6e8d4..e680c19f 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -115,7 +115,9 @@ impl<'a> CairoRenderer<'a> {
}
pub fn get_dimensions(&self) -> Result<(i32, i32), RenderingError> {
- self.handle.0.get_dimensions()
+ self.handle
+ .0
+ .get_dimensions()
.map(|dimensions| (dimensions.width, dimensions.height))
}
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index a9ef26f5..48c86db8 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -277,10 +277,6 @@ impl From<glib::Error> for LoadingError {
}
}
-extern "C" {
- fn rsvg_error_quark() -> glib_sys::GQuark;
-}
-
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
@@ -288,7 +284,7 @@ pub fn set_gerror(err: *mut *mut glib_sys::GError, code: u32, msg: &str) {
glib_sys::g_set_error_literal(
err,
- rsvg_error_quark(),
+ rsvg_rust_error_quark(),
code as libc::c_int,
msg.to_glib_none().0,
);
@@ -325,7 +321,7 @@ pub const RSVG_ERROR_FAILED: i32 = 0;
impl ErrorDomain for RsvgError {
fn domain() -> glib::Quark {
- from_glib(unsafe { rsvg_error_quark() })
+ glib::Quark::from_string("rsvg-error-quark")
}
fn code(self) -> i32 {
@@ -339,3 +335,8 @@ impl ErrorDomain for 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 b6dbac2c..704421af 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -44,7 +44,7 @@ pub use color::{rsvg_css_parse_color, ColorKind, ColorSpec};
pub use dpi::{rsvg_rust_set_default_dpi_x_y, Dpi};
-pub use error::{LoadingError, RenderingError};
+pub use error::{rsvg_rust_error_quark, LoadingError, RenderingError};
pub use handle::{
rsvg_handle_rust_close,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]