[librsvg] handle: check start state in the rust side of set_base_uri
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] handle: check start state in the rust side of set_base_uri
- Date: Sun, 6 Jan 2019 09:41:45 +0000 (UTC)
commit 28643c1f8e075fd01eeb1c827e5d8f86709f134f
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jan 6 01:13:28 2019 +0100
handle: check start state in the rust side of set_base_uri
librsvg/rsvg-handle.c | 14 +---------
rsvg_internals/src/handle.rs | 61 +++++++++++++++++++-------------------------
rsvg_internals/src/lib.rs | 1 -
3 files changed, 27 insertions(+), 49 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index e4d1df95..6023cd9f 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -154,7 +154,6 @@ extern GFile *rsvg_handle_rust_get_base_gfile (RsvgHandleRust *raw_handle);
extern guint rsvg_handle_rust_get_flags (RsvgHandleRust *raw_handle);
extern void rsvg_handle_rust_set_flags (RsvgHandleRust *raw_handle, guint flags);
extern guint rsvg_handle_rust_set_testing (RsvgHandleRust *raw_handle, gboolean testing);
-extern gboolean rsvg_handle_rust_is_at_start_for_setting_base_file (RsvgHandle *handle);
extern gboolean rsvg_handle_rust_read_stream_sync (RsvgHandle *handle,
GInputStream *stream,
GCancellable *cancellable,
@@ -826,10 +825,6 @@ rsvg_handle_set_base_uri (RsvgHandle * handle, const char *base_uri)
g_return_if_fail (RSVG_IS_HANDLE (handle));
- if (!rsvg_handle_rust_is_at_start_for_setting_base_file (handle)) {
- return;
- }
-
if (base_uri == NULL) {
return;
}
@@ -860,20 +855,13 @@ void
rsvg_handle_set_base_gfile (RsvgHandle *handle,
GFile *base_file)
{
- RsvgHandlePrivate *priv;
char *uri;
g_return_if_fail (RSVG_IS_HANDLE (handle));
g_return_if_fail (G_IS_FILE (base_file));
- if (!rsvg_handle_rust_is_at_start_for_setting_base_file (handle)) {
- return;
- }
-
- priv = handle->priv;
-
uri = g_file_get_uri (base_file);
- rsvg_handle_rust_set_base_url (priv->rust_handle, uri);
+ rsvg_handle_rust_set_base_url (handle->priv->rust_handle, uri);
g_free (uri);
}
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 37538f29..b9e6aeda 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -126,6 +126,26 @@ impl Handle {
}
}
+ fn set_base_url(&self, url: &str) {
+ match Url::parse(&url) {
+ Ok(u) => {
+ let url_cstring = CString::new(u.as_str()).unwrap();
+
+ rsvg_log!("setting base_uri to \"{}\"", u.as_str());
+ *self.base_url.borrow_mut() = Some(u);
+ *self.base_url_cstring.borrow_mut() = Some(url_cstring);
+ }
+
+ Err(e) => {
+ rsvg_log!(
+ "not setting base_uri to \"{}\" since it is invalid: {}",
+ url,
+ e
+ );
+ }
+ }
+ }
+
pub fn read_stream_sync(
&mut self,
handle: *mut RsvgHandle,
@@ -762,27 +782,15 @@ pub unsafe extern "C" fn rsvg_handle_rust_set_base_url(
) {
let handle = &*raw_handle;
+ if handle.load_state.get() != LoadState::Start {
+ rsvg_g_warning("Please set the base file or URI before loading any data into RsvgHandle");
+ return;
+ }
+
assert!(!uri.is_null());
let uri: String = from_glib_none(uri);
- let url = match Url::parse(&uri) {
- Ok(u) => u,
-
- Err(e) => {
- rsvg_log!(
- "not setting base_uri to \"{}\" since it is invalid: {}",
- uri,
- e
- );
- return;
- }
- };
-
- let url_cstring = CString::new(url.as_str()).unwrap();
-
- rsvg_log!("setting base_uri to \"{}\"", url);
- *handle.base_url.borrow_mut() = Some(url);
- *handle.base_url_cstring.borrow_mut() = Some(url_cstring);
+ handle.set_base_url(&uri);
}
#[no_mangle]
@@ -875,23 +883,6 @@ pub unsafe extern "C" fn rsvg_handle_rust_set_testing(
rhandle.is_testing.set(from_glib(testing));
}
-#[no_mangle]
-pub unsafe extern "C" fn rsvg_handle_rust_is_at_start_for_setting_base_file(
- handle: *const RsvgHandle,
-) -> glib_sys::gboolean {
- let rhandle = get_rust_handle(handle);
-
- match rhandle.load_state.get() {
- LoadState::Start => true.to_glib(),
- _ => {
- rsvg_g_warning(
- "Please set the base file or URI before loading any data into RsvgHandle",
- );
- false.to_glib()
- }
- }
-}
-
fn is_loaded(handle: &Handle) -> bool {
match handle.load_state.get() {
LoadState::Start => {
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 24262c4b..dd467f76 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -50,7 +50,6 @@ pub use handle::{
rsvg_handle_rust_get_pixbuf_sub,
rsvg_handle_rust_get_position_sub,
rsvg_handle_rust_has_sub,
- rsvg_handle_rust_is_at_start_for_setting_base_file,
rsvg_handle_rust_new,
rsvg_handle_rust_read_stream_sync,
rsvg_handle_rust_render_cairo_sub,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]