[librsvg] LoadState: move the RsvgHandlePrivate.hstate field to Rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] LoadState: move the RsvgHandlePrivate.hstate field to Rust
- Date: Tue, 18 Dec 2018 00:32:34 +0000 (UTC)
commit 8c117a4e4438405140892dbda08158833678cd57
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Dec 17 18:23:49 2018 -0600
LoadState: move the RsvgHandlePrivate.hstate field to Rust
librsvg/rsvg-handle.c | 38 +++++++++++++++++++++-----------------
librsvg/rsvg-private.h | 2 --
rsvg_internals/src/handle.rs | 28 ++++++++++++++++++++++++++++
rsvg_internals/src/lib.rs | 2 ++
4 files changed, 51 insertions(+), 19 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 1832c131..e15e9aa6 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -143,6 +143,8 @@ extern gboolean rsvg_handle_rust_node_is_root(RsvgHandleRust *raw_handle, RsvgNo
extern void rsvg_handle_rust_steal_result (RsvgHandleRust *raw_handle, RsvgXmlState *xml);
extern guint rsvg_handle_rust_get_flags (RsvgHandleRust *raw_handle);
extern void rsvg_handle_rust_set_flags (RsvgHandleRust *raw_handle, guint flags);
+extern void rsvg_handle_rust_set_load_state (RsvgHandleRust *raw_handle, RsvgHandleState state);
+extern RsvgHandleState rsvg_handle_rust_get_load_state (RsvgHandleRust *raw_handle);
/* Implemented in rsvg_internals/src/xml.rs */
extern void rsvg_xml_state_free (RsvgXmlState *xml);
@@ -203,8 +205,6 @@ rsvg_handle_init (RsvgHandle * self)
{
self->priv = rsvg_handle_get_instance_private (self);
- self->priv->hstate = RSVG_HANDLE_STATE_START;
-
self->priv->in_loop = FALSE;
self->priv->is_testing = FALSE;
@@ -674,23 +674,26 @@ gboolean
rsvg_handle_write (RsvgHandle *handle, const guchar *buf, gsize count, GError **error)
{
RsvgHandlePrivate *priv;
+ RsvgHandleState lstate;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
rsvg_return_val_if_fail (handle, FALSE, error);
priv = handle->priv;
- g_return_val_if_fail (priv->hstate == RSVG_HANDLE_STATE_START
- || priv->hstate == RSVG_HANDLE_STATE_LOADING,
+ lstate = rsvg_handle_rust_get_load_state (priv->rust_handle);
+
+ g_return_val_if_fail (lstate == RSVG_HANDLE_STATE_START
+ || lstate == RSVG_HANDLE_STATE_LOADING,
FALSE);
- if (priv->hstate == RSVG_HANDLE_STATE_START) {
- priv->hstate = RSVG_HANDLE_STATE_LOADING;
+ if (lstate == RSVG_HANDLE_STATE_START) {
+ rsvg_handle_rust_set_load_state (priv->rust_handle, RSVG_HANDLE_STATE_LOADING);
priv->load = rsvg_load_new (rsvg_xml_state_new (handle),
rsvg_handle_rust_get_flags (priv->rust_handle));
}
- g_assert (priv->hstate == RSVG_HANDLE_STATE_LOADING);
+ g_assert (rsvg_handle_rust_get_load_state (priv->rust_handle) == RSVG_HANDLE_STATE_LOADING);
rsvg_load_write (priv->load, buf, count);
@@ -710,9 +713,9 @@ finish_load (RsvgHandle *handle, RsvgXmlState *xml, gboolean was_successful, GEr
}
if (was_successful) {
- handle->priv->hstate = RSVG_HANDLE_STATE_CLOSED_OK;
+ rsvg_handle_rust_set_load_state (handle->priv->rust_handle, RSVG_HANDLE_STATE_CLOSED_OK);
} else {
- handle->priv->hstate = RSVG_HANDLE_STATE_CLOSED_ERROR;
+ rsvg_handle_rust_set_load_state (handle->priv->rust_handle, RSVG_HANDLE_STATE_CLOSED_ERROR);
}
return was_successful;
@@ -745,10 +748,10 @@ rsvg_handle_close (RsvgHandle *handle, GError **error)
priv = handle->priv;
- switch (priv->hstate) {
+ switch (rsvg_handle_rust_get_load_state (priv->rust_handle)) {
case RSVG_HANDLE_STATE_START:
g_set_error (error, RSVG_ERROR, RSVG_ERROR_FAILED, _("no data passed to parser"));
- priv->hstate = RSVG_HANDLE_STATE_CLOSED_ERROR;
+ rsvg_handle_rust_set_load_state (priv->rust_handle, RSVG_HANDLE_STATE_CLOSED_ERROR);
result = FALSE;
break;
@@ -773,8 +776,8 @@ rsvg_handle_close (RsvgHandle *handle, GError **error)
g_assert_not_reached ();
}
- g_assert (priv->hstate == RSVG_HANDLE_STATE_CLOSED_OK
- || priv->hstate == RSVG_HANDLE_STATE_CLOSED_ERROR);
+ g_assert (rsvg_handle_rust_get_load_state (priv->rust_handle) == RSVG_HANDLE_STATE_CLOSED_OK
+ || rsvg_handle_rust_get_load_state (priv->rust_handle) == RSVG_HANDLE_STATE_CLOSED_ERROR);
return result;
}
@@ -816,9 +819,10 @@ rsvg_handle_read_stream_sync (RsvgHandle *handle,
priv = handle->priv;
- g_return_val_if_fail (priv->hstate == RSVG_HANDLE_STATE_START, FALSE);
+ g_return_val_if_fail (rsvg_handle_rust_get_load_state (priv->rust_handle) == RSVG_HANDLE_STATE_START,
+ FALSE);
- priv->hstate = RSVG_HANDLE_STATE_LOADING;
+ rsvg_handle_rust_set_load_state (priv->rust_handle, RSVG_HANDLE_STATE_LOADING);
xml = rsvg_xml_state_new (handle);
read_successfully = rsvg_xml_state_load_from_possibly_compressed_stream (
@@ -890,7 +894,7 @@ get_base_uri_from_filename (const gchar * filename)
static gboolean
is_at_start_for_setting_base_file (RsvgHandle *handle)
{
- if (handle->priv->hstate == RSVG_HANDLE_STATE_START) {
+ 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");
@@ -1070,7 +1074,7 @@ rsvg_handle_create_drawing_ctx(RsvgHandle *handle,
static gboolean
is_loaded (RsvgHandle *handle)
{
- switch (handle->priv->hstate) {
+ switch (rsvg_handle_rust_get_load_state (handle->priv->rust_handle)) {
case RSVG_HANDLE_STATE_START:
g_warning ("RsvgHandle has not been loaded");
return FALSE;
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 57046e1e..9d9ed259 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -89,8 +89,6 @@ typedef struct RsvgLoad RsvgLoad;
typedef struct RsvgHandleRust RsvgHandleRust;
struct RsvgHandlePrivate {
- RsvgHandleState hstate;
-
RsvgLoad *load;
RsvgSizeFunc size_func;
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index a14dfdfa..c6af775a 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -44,11 +44,21 @@ pub struct LoadOptions {
pub keep_image_data: bool,
}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub enum LoadState {
+ Start,
+ Loading,
+ ClosedOk,
+ ClosedError,
+}
+
pub struct Handle {
dpi: Dpi,
base_url: RefCell<Option<Url>>,
svg: RefCell<Option<Svg>>,
load_options: Cell<LoadOptions>,
+ load_state: Cell<LoadState>,
}
impl Handle {
@@ -58,6 +68,7 @@ impl Handle {
base_url: RefCell::new(None),
svg: RefCell::new(None),
load_options: Cell::new(LoadOptions::default()),
+ load_state: Cell::new(LoadState::Start),
}
}
}
@@ -570,3 +581,20 @@ pub unsafe extern "C" fn rsvg_handle_rust_set_flags(raw_handle: *const Handle, f
rhandle.load_options.set(LoadOptions::from_flags(flags));
}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_get_load_state(raw_handle: *const Handle) -> LoadState {
+ let rhandle = &*raw_handle;
+
+ rhandle.load_state.get()
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_set_load_state(
+ raw_handle: *const Handle,
+ load_state: LoadState,
+) {
+ let rhandle = &*raw_handle;
+
+ rhandle.load_state.set(load_state)
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index a7950025..f29483b9 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -53,6 +53,7 @@ pub use handle::{
rsvg_handle_rust_get_dpi_x,
rsvg_handle_rust_get_dpi_y,
rsvg_handle_rust_get_flags,
+ rsvg_handle_rust_get_load_state,
rsvg_handle_rust_get_root,
rsvg_handle_rust_new,
rsvg_handle_rust_node_is_root,
@@ -60,6 +61,7 @@ pub use handle::{
rsvg_handle_rust_set_dpi_x,
rsvg_handle_rust_set_dpi_y,
rsvg_handle_rust_set_flags,
+ rsvg_handle_rust_set_load_state,
rsvg_handle_rust_steal_result,
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]