[librsvg] Start draining RsvgHandlePrivate into a Rust struct
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Start draining RsvgHandlePrivate into a Rust struct
- Date: Tue, 27 Nov 2018 00:24:02 +0000 (UTC)
commit f20724acf0ee4fda3ed78e58fcd159c8935af43c
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Nov 26 12:25:23 2018 -0600
Start draining RsvgHandlePrivate into a Rust struct
librsvg/rsvg-handle.c | 10 ++++++++++
librsvg/rsvg-private.h | 16 ++++++++++++++++
rsvg_internals/src/handle.rs | 24 ++++++++++++++++++++++++
rsvg_internals/src/lib.rs | 2 +-
4 files changed, 51 insertions(+), 1 deletion(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 86ee8066..eab2d59b 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -173,6 +173,8 @@ rsvg_handle_init (RsvgHandle * self)
self->priv->font_config_for_testing = NULL;
self->priv->font_map_for_testing = NULL;
#endif
+
+ self->priv->rust_handle = rsvg_handle_rust_new();
}
static void
@@ -199,6 +201,8 @@ rsvg_handle_dispose (GObject *instance)
g_clear_object (&self->priv->cancellable);
+ g_clear_pointer (&self->priv->rust_handle, rsvg_handle_rust_free);
+
G_OBJECT_CLASS (rsvg_handle_parent_class)->dispose (instance);
}
@@ -986,6 +990,12 @@ rsvg_handle_get_defs (RsvgHandle *handle)
return handle->priv->defs;
}
+RsvgHandleRust *
+rsvg_handle_get_rust (RsvgHandle *handle)
+{
+ return handle->priv->rust_handle;
+}
+
RsvgCssStyles *
rsvg_handle_get_css_styles (RsvgHandle *handle)
{
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index f8ff9186..b79e3f53 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -85,6 +85,9 @@ typedef struct RsvgTree RsvgTree;
typedef struct RsvgCssStyles RsvgCssStyles;
+/* Defined in rsvg_internals/src/handle.rs */
+typedef struct RsvgHandleRust RsvgHandleRust;
+
struct RsvgHandlePrivate {
RsvgHandleFlags flags;
@@ -118,6 +121,8 @@ struct RsvgHandlePrivate {
FcConfig *font_config_for_testing;
PangoFontMap *font_map_for_testing;
#endif
+
+ RsvgHandleRust *rust_handle;
};
/* Implemented in rust/src/node.rs */
@@ -245,6 +250,9 @@ RsvgNode *rsvg_defs_lookup (const RsvgDefs * defs, RsvgHandle *handle, const cha
G_GNUC_INTERNAL
RsvgDefs *rsvg_handle_get_defs (RsvgHandle *handle);
+G_GNUC_INTERNAL
+RsvgHandleRust *rsvg_handle_get_rust (RsvgHandle *handle);
+
G_GNUC_INTERNAL
RsvgCssStyles *rsvg_handle_get_css_styles (RsvgHandle *handle);
@@ -256,6 +264,14 @@ G_GNUC_INTERNAL
char *rsvg_handle_resolve_uri (RsvgHandle *handle,
const char *uri);
+/* Implemented in rsvg_internals/src/handle.rs */
+G_GNUC_INTERNAL
+RsvgHandleRust *rsvg_handle_rust_new (void);
+
+/* Implemented in rsvg_internals/src/handle.rs */
+G_GNUC_INTERNAL
+void rsvg_handle_rust_free (RsvgHandleRust *raw_handle);
+
G_GNUC_INTERNAL
RsvgHandle *rsvg_handle_load_extern (RsvgHandle *handle,
const char *uri);
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index d978fa4a..ed53bc79 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -18,6 +18,10 @@ use util::utf8_cstr;
pub enum RsvgHandle {}
+pub enum RsvgHandleRust {}
+
+struct Handle {}
+
#[allow(improper_ctypes)]
extern "C" {
fn rsvg_handle_get_defs(handle: *const RsvgHandle) -> *const RsvgDefs;
@@ -54,6 +58,8 @@ extern "C" {
handle: *mut RsvgHandle,
href: *const libc::c_char,
) -> glib_sys::gboolean;
+
+ fn rsvg_handle_get_rust(handle: *const RsvgHandle) -> *mut RsvgHandleRust;
}
pub fn get_defs<'a>(handle: *const RsvgHandle) -> &'a mut Defs {
@@ -243,3 +249,21 @@ pub unsafe extern "C" fn rsvg_handle_load_css(handle: *mut RsvgHandle, href: *co
let href = utf8_cstr(href);
load_css(handle, href);
}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_new() -> *mut RsvgHandleRust {
+ Box::into_raw(Box::new(Handle {})) as *mut RsvgHandleRust
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_free(raw_handle: *mut RsvgHandleRust) {
+ assert!(!raw_handle.is_null());
+
+ Box::from_raw(raw_handle as *mut Handle);
+}
+
+fn get_rust_handle(handle: *const RsvgHandle) -> *mut Handle {
+ unsafe {
+ rsvg_handle_get_rust(handle) as *mut Handle
+ }
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 0c7a888b..56a80575 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -46,7 +46,7 @@ pub use drawing_ctx::{
rsvg_drawing_ctx_new,
};
-pub use handle::rsvg_handle_load_css;
+pub use handle::{rsvg_handle_load_css, rsvg_handle_rust_free, rsvg_handle_rust_new};
pub use io::{
rsvg_decode_data_uri,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]