[librsvg] handle: move is_at_start_for_setting_base_file to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] handle: move is_at_start_for_setting_base_file to rust
- Date: Sat, 29 Dec 2018 18:06:34 +0000 (UTC)
commit 28d66efd5fcc1e6ae997183323e9381c53a67a28
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Dec 29 12:47:04 2018 +0100
handle: move is_at_start_for_setting_base_file to rust
This also removes the need to expose get_load_state to C
librsvg/rsvg-handle.c | 25 +++----------------------
rsvg_internals/src/handle.rs | 17 +++++++++++++----
rsvg_internals/src/lib.rs | 2 +-
3 files changed, 17 insertions(+), 27 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index eee914f3..86bb6cd5 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -136,14 +136,6 @@ typedef struct RsvgHandleRust RsvgHandleRust;
/* Implemented in rsvg_internals/src/xml.rs */
typedef struct RsvgXmlState RsvgXmlState;
-/* Reading state for an RsvgHandle */
-typedef enum {
- RSVG_HANDLE_STATE_START,
- RSVG_HANDLE_STATE_LOADING,
- RSVG_HANDLE_STATE_CLOSED_OK,
- RSVG_HANDLE_STATE_CLOSED_ERROR
-} RsvgHandleState;
-
/* Implemented in rsvg_internals/src/xml.rs */
extern void rsvg_xml_state_error(RsvgXmlState *xml, const char *msg);
@@ -161,7 +153,7 @@ extern void rsvg_handle_rust_set_base_url (RsvgHandleRust *raw_handle, const cha
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 RsvgHandleState rsvg_handle_rust_get_load_state (RsvgHandleRust *raw_handle);
+extern gboolean rsvg_handle_rust_is_at_start_for_setting_base_file (RsvgHandle *handle);
extern gboolean rsvg_handle_rust_is_loaded (RsvgHandle *handle);
extern gboolean rsvg_handle_rust_read_stream_sync (RsvgHandle *handle,
GInputStream *stream,
@@ -800,17 +792,6 @@ get_base_uri_from_filename (const gchar * filename)
return base_uri;
}
-static gboolean
-is_at_start_for_setting_base_file (RsvgHandle *handle)
-{
- if (rsvg_handle_rust_get_load_state (handle->priv->rust_handle) == RSVG_HANDLE_STATE_START) {
- return TRUE;
- } else {
- g_warning ("Please set the base file or URI before loading any data into RsvgHandle");
- return FALSE;
- }
-}
-
/**
* rsvg_handle_set_base_uri:
* @handle: A #RsvgHandle
@@ -829,7 +810,7 @@ rsvg_handle_set_base_uri (RsvgHandle * handle, const char *base_uri)
g_return_if_fail (RSVG_IS_HANDLE (handle));
- if (!is_at_start_for_setting_base_file (handle)) {
+ if (!rsvg_handle_rust_is_at_start_for_setting_base_file (handle)) {
return;
}
@@ -870,7 +851,7 @@ rsvg_handle_set_base_gfile (RsvgHandle *handle,
g_return_if_fail (RSVG_IS_HANDLE (handle));
g_return_if_fail (G_IS_FILE (base_file));
- if (!is_at_start_for_setting_base_file (handle)) {
+ if (!rsvg_handle_rust_is_at_start_for_setting_base_file (handle)) {
return;
}
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 12d25224..4095c1b2 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -64,7 +64,6 @@ pub struct LoadOptions {
pub keep_image_data: bool,
}
-#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub enum LoadState {
Start,
@@ -815,10 +814,20 @@ pub unsafe extern "C" fn rsvg_handle_rust_set_flags(raw_handle: *const Handle, f
}
#[no_mangle]
-pub unsafe extern "C" fn rsvg_handle_rust_get_load_state(raw_handle: *const Handle) -> LoadState {
- let rhandle = &*raw_handle;
+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);
- rhandle.load_state.get()
+ 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()
+ }
+ }
}
#[no_mangle]
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 33901690..af092b02 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -44,9 +44,9 @@ pub use handle::{
rsvg_handle_rust_get_dpi_y,
rsvg_handle_rust_get_flags,
rsvg_handle_rust_get_geometry_sub,
- rsvg_handle_rust_get_load_state,
rsvg_handle_rust_get_pixbuf_sub,
rsvg_handle_rust_has_sub,
+ rsvg_handle_rust_is_at_start_for_setting_base_file,
rsvg_handle_rust_is_loaded,
rsvg_handle_rust_new,
rsvg_handle_rust_read_stream_sync,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]