diff options
author | Federico Mena Quintero <federico@gnome.org> | 2019-01-09 16:56:44 -0600 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2019-01-10 12:27:32 -0600 |
commit | 7e34060f35ca5c449793ed3c2d0db0ef1832d21e (patch) | |
tree | 781bcb464b82ee04f3bd7394cf370aadf1fc3255 /rsvg_internals | |
parent | 0b082e0358ca7d213d3db68e6d77aae2445d46ba (diff) | |
download | librsvg-7e34060f35ca5c449793ed3c2d0db0ef1832d21e.tar.gz |
rsvg_handle_new_from_data(): Port the implementation to Rust
Diffstat (limited to 'rsvg_internals')
-rw-r--r-- | rsvg_internals/src/handle.rs | 34 | ||||
-rw-r--r-- | rsvg_internals/src/lib.rs | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs index 900645f7..6a053f25 100644 --- a/rsvg_internals/src/handle.rs +++ b/rsvg_internals/src/handle.rs @@ -1,3 +1,4 @@ +use std; use std::cell::{Cell, Ref, RefCell}; use std::ffi::CString; use std::mem; @@ -1239,3 +1240,36 @@ pub unsafe extern "C" fn rsvg_handle_rust_new_from_stream_sync( } } } + +#[no_mangle] +pub unsafe extern "C" fn rsvg_handle_rust_new_from_data( + data: *mut u8, + len: usize, + error: *mut *mut glib_sys::GError, +) -> *mut RsvgHandle { + // We create the MemoryInputStream without the gtk-rs binding because of this: + // + // - The binding doesn't provide _new_from_data(). All of the binding's ways to + // put data into a MemoryInputStream involve copying the data buffer. + // + // - We can't use glib::Bytes from the binding either, for the same reason. + // + // - For now, we are using the other C-visible constructor, so we need a raw pointer to the + // stream, anyway. + + assert!(len <= std::isize::MAX as usize); + let len = len as isize; + + let raw_stream = gio_sys::g_memory_input_stream_new_from_data(data, len, None); + + let ret = rsvg_handle_rust_new_from_stream_sync( + raw_stream as *mut _, + ptr::null_mut(), // base_file + 0, // flags + ptr::null_mut(), // cancellable + error, + ); + + gobject_sys::g_object_unref(raw_stream as *mut _); + ret +} diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs index e2ccf936..c1c2ff44 100644 --- a/rsvg_internals/src/lib.rs +++ b/rsvg_internals/src/lib.rs @@ -54,6 +54,7 @@ pub use handle::{ rsvg_handle_rust_get_position_sub, rsvg_handle_rust_has_sub, rsvg_handle_rust_new, + rsvg_handle_rust_new_from_data, rsvg_handle_rust_new_from_gfile_sync, rsvg_handle_rust_new_from_stream_sync, rsvg_handle_rust_read_stream_sync, |