[librsvg] rsvg_handle_rust_has_sub(): Port to Rust.
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] rsvg_handle_rust_has_sub(): Port to Rust.
- Date: Wed, 19 Dec 2018 19:37:50 +0000 (UTC)
commit 999497014457faa4aeefe8c860b1dcc0a0aff033
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Dec 19 13:24:15 2018 -0600
rsvg_handle_rust_has_sub(): Port to Rust.
librsvg/rsvg-handle.c | 16 +++-------------
rsvg_internals/src/handle.rs | 20 ++++++++++++++++++++
rsvg_internals/src/lib.rs | 1 +
3 files changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 965de1ac..6242f2d0 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -178,6 +178,7 @@ extern gboolean rsvg_handle_rust_get_geometry_sub (RsvgHandle *handle,
RsvgRectangle *out_ink_rect,
RsvgRectangle *out_logical_rect,
const char *id);
+extern gboolean rsvg_handle_rust_has_sub(RsvgHandle *handle, const char *id);
/* Implemented in rust/src/node.rs */
/* Call this as node = rsvg_node_unref (node); Then node will be NULL and you don't own it anymore! */
@@ -1253,27 +1254,16 @@ rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_d
* Since: 2.22
*/
gboolean
-rsvg_handle_has_sub (RsvgHandle * handle,
+rsvg_handle_has_sub (RsvgHandle *handle,
const char *id)
{
- RsvgNode *node;
- gboolean has_sub;
-
g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
if (!is_loaded (handle)) {
return FALSE;
}
- if (G_UNLIKELY (!id || !id[0]))
- return FALSE;
-
- node = rsvg_handle_defs_lookup (handle, id);
- has_sub = node != NULL;
-
- node = rsvg_node_unref (node);
-
- return has_sub;
+ return rsvg_handle_rust_has_sub (handle, id);
}
/**
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index fa743b0a..5b7c47f6 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -363,6 +363,10 @@ impl Handle {
_ => unreachable!(), // we explicitly requested a with_fragment after all
}
}
+
+ fn has_sub(&mut self, handle: *const RsvgHandle, name: &str) -> bool {
+ self.defs_lookup(handle, name).is_ok()
+ }
}
enum DefsLookupErrorKind {
@@ -858,3 +862,19 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_geometry_sub(
}
}
}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_has_sub(
+ handle: *mut RsvgHandle,
+ id: *const libc::c_char,
+) -> glib_sys::gboolean {
+ if id.is_null() {
+ false.to_glib()
+ } else {
+ let id: String = from_glib_none(id);
+
+ let rhandle = get_rust_handle(handle);
+
+ rhandle.has_sub(handle, &id).to_glib()
+ }
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 78531f7d..e55b35a7 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -48,6 +48,7 @@ pub use handle::{
rsvg_handle_rust_get_flags,
rsvg_handle_rust_get_geometry_sub,
rsvg_handle_rust_get_load_state,
+ rsvg_handle_rust_has_sub,
rsvg_handle_rust_new,
rsvg_handle_rust_read_stream_sync,
rsvg_handle_rust_set_base_url,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]