[librsvg: 5/6] rsvg_io_acquire_data(): Port to Rust.
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/6] rsvg_io_acquire_data(): Port to Rust.
- Date: Sat, 24 Nov 2018 01:07:25 +0000 (UTC)
commit e5bb5f2795db45f510daa8a52e679820ccd802d6
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Nov 23 19:00:30 2018 -0600
rsvg_io_acquire_data(): Port to Rust.
This was the last function from rsvg-io, so rsvg-io.[ch] are now
gone. Yay!
Makefile.am | 2 -
doc/Makefile.am | 10 +----
librsvg/rsvg-handle.c | 19 ++++++---
librsvg/rsvg-io.c | 91 --------------------------------------------
librsvg/rsvg-io.h | 35 -----------------
librsvg/rsvg-pixbuf.c | 1 -
rsvg_internals/src/handle.rs | 6 +--
rsvg_internals/src/io.rs | 71 ++++++++++++++++++++++++++++++----
rsvg_internals/src/lib.rs | 7 +++-
9 files changed, 84 insertions(+), 158 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0b389041..b1f7fe0b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -29,8 +29,6 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_SOURCES = \
librsvg/rsvg-cairo.h \
librsvg/rsvg-css.h \
librsvg/rsvg-handle.c \
- librsvg/rsvg-io.c \
- librsvg/rsvg-io.h \
librsvg/rsvg-load.c \
librsvg/rsvg-load.h \
librsvg/rsvg-pixbuf.c \
diff --git a/doc/Makefile.am b/doc/Makefile.am
index fd4b2846..2f235807 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -71,17 +71,9 @@ EXTRA_HFILES =
IGNORE_HFILES = \
config.h \
rsvg-attributes.h \
- rsvg-cairo-clip.h \
- rsvg-compat.h \
rsvg-css.h \
- rsvg-filter.h \
- rsvg-io.h \
- rsvg-marker.h \
- rsvg-mask.h \
rsvg-private.h \
- rsvg-shapes.h \
- rsvg-size-callback.h \
- rsvg-styles.h
+ rsvg-size-callback.h
# Images to copy into HTML directory.
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index cd036a69..86ee8066 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -124,7 +124,6 @@
#include <limits.h>
#include <stdlib.h>
-#include "rsvg-io.h"
#include "rsvg-load.h"
#include "rsvg-private.h"
@@ -1661,6 +1660,14 @@ allow_load (GFile *base_gfile, const char *uri, GError **error)
return FALSE;
}
+/* Implemented in rsvg_internals/src/io.rs */
+G_GNUC_INTERNAL
+char * rsvg_io_acquire_data (const char *uri,
+ char **out_mime_type,
+ gsize *out_len,
+ GCancellable *cancellable,
+ GError **error);
+
char *
_rsvg_handle_acquire_data (RsvgHandle *handle,
const char *href,
@@ -1675,11 +1682,11 @@ _rsvg_handle_acquire_data (RsvgHandle *handle,
uri = rsvg_handle_resolve_uri (handle, href);
if (allow_load (priv->base_gfile, uri, error)) {
- data = _rsvg_io_acquire_data (uri,
- content_type,
- len,
- handle->priv->cancellable,
- error);
+ data = rsvg_io_acquire_data (uri,
+ content_type,
+ len,
+ handle->priv->cancellable,
+ error);
} else {
data = NULL;
}
diff --git a/librsvg/rsvg-pixbuf.c b/librsvg/rsvg-pixbuf.c
index 9f6a7473..dd78cff0 100644
--- a/librsvg/rsvg-pixbuf.c
+++ b/librsvg/rsvg-pixbuf.c
@@ -35,7 +35,6 @@
#include "config.h"
#include "rsvg-private.h"
-#include "rsvg-io.h"
#include "rsvg-size-callback.h"
#include <errno.h>
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 267c010d..d978fa4a 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -127,11 +127,7 @@ pub fn acquire_stream(handle: *mut RsvgHandle, href: &str) -> Result<InputStream
unsafe {
let mut error = ptr::null_mut();
- let stream = _rsvg_handle_acquire_stream(
- handle,
- href.to_glib_none().0,
- &mut error,
- );
+ let stream = _rsvg_handle_acquire_stream(handle, href.to_glib_none().0, &mut error);
if stream.is_null() {
Err(from_glib_full(error))
diff --git a/rsvg_internals/src/io.rs b/rsvg_internals/src/io.rs
index caa040f9..48d60528 100644
--- a/rsvg_internals/src/io.rs
+++ b/rsvg_internals/src/io.rs
@@ -48,6 +48,22 @@ fn decode_data_uri(uri: &str) -> Result<BinaryData, LoadingError> {
})
}
+fn binary_data_to_glib(
+ binary_data: &BinaryData,
+ out_mime_type: *mut *mut libc::c_char,
+ out_size: *mut usize,
+) -> *mut libc::c_char {
+ unsafe {
+ if !out_mime_type.is_null() {
+ *out_mime_type = binary_data.content_type.to_glib_full();
+ }
+
+ *out_size = binary_data.data.len();
+
+ ToGlibContainerFromSlice::to_glib_full_from_slice(&binary_data.data) as *mut libc::c_char
+ }
+}
+
#[no_mangle]
pub fn rsvg_decode_data_uri(
uri: *const libc::c_char,
@@ -62,18 +78,11 @@ pub fn rsvg_decode_data_uri(
match decode_data_uri(uri) {
Ok(binary_data) => {
- if !out_mime_type.is_null() {
- *out_mime_type = binary_data.content_type.to_glib_full();
- }
-
- *out_size = binary_data.data.len();
-
if !error.is_null() {
*error = ptr::null_mut();
}
- ToGlibContainerFromSlice::to_glib_full_from_slice(&binary_data.data)
- as *mut libc::c_char
+ binary_data_to_glib(&binary_data, out_mime_type, out_size)
}
Err(_) => {
@@ -180,3 +189,49 @@ pub unsafe fn rsvg_io_acquire_stream(
}
}
}
+
+fn acquire_data(uri: &str, cancellable: Option<Cancellable>) -> Result<BinaryData, LoadingError> {
+ if uri.starts_with("data:") {
+ Ok(decode_data_uri(uri)?)
+ } else {
+ let file = GFile::new_for_uri(uri);
+ let (contents, _etag) = file.load_contents(cancellable.as_ref())?;
+
+ let (content_type, _uncertain) = gio::content_type_guess(uri, &contents);
+ let mime_type = gio::content_type_get_mime_type(&content_type);
+
+ Ok(BinaryData {
+ data: contents,
+ content_type: mime_type,
+ })
+ }
+}
+
+#[no_mangle]
+pub unsafe fn rsvg_io_acquire_data(
+ uri: *const libc::c_char,
+ out_mime_type: *mut *mut libc::c_char,
+ out_size: *mut usize,
+ cancellable: *mut gio_sys::GCancellable,
+ error: *mut *mut glib_sys::GError,
+) -> *mut libc::c_char {
+ assert!(!uri.is_null());
+
+ let uri: String = from_glib_none(uri);
+ let cancellable = from_glib_borrow(cancellable);
+
+ match acquire_data(&uri, cancellable) {
+ Ok(binary_data) => {
+ if !error.is_null() {
+ *error = ptr::null_mut();
+ }
+
+ binary_data_to_glib(&binary_data, out_mime_type, out_size)
+ }
+
+ Err(_e) => {
+ set_gerror(error, 0, "Could not acquire data");
+ ptr::null_mut()
+ }
+ }
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 47249299..0dc5cf06 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -47,7 +47,12 @@ pub use drawing_ctx::{
pub use handle::rsvg_handle_load_css;
-pub use io::{rsvg_decode_data_uri, rsvg_get_input_stream_for_loading, rsvg_io_acquire_stream};
+pub use io::{
+ rsvg_decode_data_uri,
+ rsvg_get_input_stream_for_loading,
+ rsvg_io_acquire_data,
+ rsvg_io_acquire_stream,
+};
pub use node::rsvg_node_unref;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]