[librsvg: 13/14] handle: move the base_uri field to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 13/14] handle: move the base_uri field to rust
- Date: Sun, 6 Jan 2019 03:25:54 +0000 (UTC)
commit 0a695898ebeac7160bdb0b0be8a0a19fec735953
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jan 6 00:52:10 2019 +0100
handle: move the base_uri field to rust
In order to be able to return a const char pointer, we store the
base url also as a CString
librsvg/rsvg-handle.c | 19 +++----------------
rsvg_internals/src/handle.rs | 19 ++++++++++++++++++-
rsvg_internals/src/lib.rs | 1 +
3 files changed, 22 insertions(+), 17 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index e10bdc49..e4d1df95 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -149,6 +149,7 @@ extern double rsvg_handle_rust_get_dpi_y (RsvgHandleRust *raw_handle);
extern void rsvg_handle_rust_set_dpi_x (RsvgHandleRust *raw_handle, double dpi_x);
extern void rsvg_handle_rust_set_dpi_y (RsvgHandleRust *raw_handle, double dpi_y);
extern void rsvg_handle_rust_set_base_url (RsvgHandleRust *raw_handle, const char *uri);
+extern const char *rsvg_handle_rust_get_base_url (RsvgHandleRust *raw_handle);
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);
@@ -224,8 +225,6 @@ rsvg_size_closure_call (RsvgSizeClosure *closure, int *width, int *height)
extern void rsvg_handle_rust_set_size_closure (RsvgHandleRust *raw_handle, RsvgSizeClosure *closure);
struct RsvgHandlePrivate {
- gchar *base_uri; // Keep this here; since rsvg_handle_get_base_uri() returns a const char *
-
RsvgHandleRust *rust_handle;
};
@@ -260,7 +259,6 @@ rsvg_handle_dispose (GObject *instance)
{
RsvgHandle *self = (RsvgHandle *) instance;
- g_clear_pointer (&self->priv->base_uri, g_free);
g_clear_pointer (&self->priv->rust_handle, rsvg_handle_rust_free);
G_OBJECT_CLASS (rsvg_handle_parent_class)->dispose (instance);
@@ -864,7 +862,6 @@ rsvg_handle_set_base_gfile (RsvgHandle *handle,
{
RsvgHandlePrivate *priv;
char *uri;
- GFile *real_base_file;
g_return_if_fail (RSVG_IS_HANDLE (handle));
g_return_if_fail (G_IS_FILE (base_file));
@@ -878,17 +875,6 @@ rsvg_handle_set_base_gfile (RsvgHandle *handle,
uri = g_file_get_uri (base_file);
rsvg_handle_rust_set_base_url (priv->rust_handle, uri);
g_free (uri);
-
- /* Obtain the sanitized version */
-
- real_base_file = rsvg_handle_rust_get_base_gfile (priv->rust_handle);
- g_free (priv->base_uri);
-
- if (real_base_file) {
- priv->base_uri = g_file_get_uri (real_base_file);
- } else {
- priv->base_uri = NULL;
- }
}
/**
@@ -904,7 +890,8 @@ const char *
rsvg_handle_get_base_uri (RsvgHandle * handle)
{
g_return_val_if_fail (handle, NULL);
- return handle->priv->base_uri;
+
+ return rsvg_handle_rust_get_base_url (handle->priv->rust_handle);
}
/**
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 4dc3e5af..37538f29 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -1,4 +1,5 @@
use std::cell::{Cell, Ref, RefCell};
+use std::ffi::CString;
use std::mem;
use std::ptr;
use std::rc::Rc;
@@ -99,6 +100,7 @@ pub enum LoadState {
pub struct Handle {
dpi: Dpi,
base_url: RefCell<Option<Url>>,
+ base_url_cstring: RefCell<Option<CString>>, // needed because the C api returns *const char
svg: RefCell<Option<Svg>>,
load_options: Cell<LoadOptions>,
load_state: Cell<LoadState>,
@@ -113,6 +115,7 @@ impl Handle {
Handle {
dpi: Dpi::default(),
base_url: RefCell::new(None),
+ base_url_cstring: RefCell::new(None),
svg: RefCell::new(None),
load_options: Cell::new(LoadOptions::default()),
load_state: Cell::new(LoadState::Start),
@@ -775,8 +778,11 @@ pub unsafe extern "C" fn rsvg_handle_rust_set_base_url(
}
};
+ 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);
}
#[no_mangle]
@@ -787,11 +793,22 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_base_gfile(
match *handle.base_url.borrow() {
None => ptr::null_mut(),
-
Some(ref url) => GFile::new_for_uri(url.as_str()).to_glib_full(),
}
}
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_get_base_url(
+ raw_handle: *const Handle,
+) -> *const libc::c_char {
+ let handle = &*raw_handle;
+
+ match *handle.base_url_cstring.borrow() {
+ None => ptr::null(),
+ Some(ref url) => url.as_ptr(),
+ }
+}
+
#[no_mangle]
pub unsafe extern "C" fn rsvg_handle_rust_set_dpi_x(raw_handle: *const Handle, dpi_x: f64) {
let handle = &*(raw_handle as *const Handle);
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index e56d5d85..24262c4b 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -40,6 +40,7 @@ pub use handle::{
rsvg_handle_rust_close,
rsvg_handle_rust_free,
rsvg_handle_rust_get_base_gfile,
+ rsvg_handle_rust_get_base_url,
rsvg_handle_rust_get_dimensions,
rsvg_handle_rust_get_dimensions_sub,
rsvg_handle_rust_get_dpi_x,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]