[librsvg] Defs::get_extern_handle() - return a Result, not a raw pointer
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Defs::get_extern_handle() - return a Result, not a raw pointer
- Date: Tue, 27 Nov 2018 00:24:18 +0000 (UTC)
commit 1b0cd43596c0e071f7ffb2bc3585d92d378f8ad4
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Nov 26 14:07:05 2018 -0600
Defs::get_extern_handle() - return a Result, not a raw pointer
This is in preparation to moving all that code path to Rust
rsvg_internals/src/defs.rs | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index c13dff39..8bcf86fb 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -38,11 +38,9 @@ impl Defs {
Reference::PlainUri(_) => None,
Reference::FragmentId(fragment) => self.nodes.get(fragment),
Reference::UriWithFragmentId(uri, fragment) => {
- let extern_handle = self.get_extern_handle(handle, uri);
- if extern_handle.is_null() {
- None
- } else {
- handle::get_defs(extern_handle).nodes.get(fragment)
+ match self.get_extern_handle(handle, uri) {
+ Ok(extern_handle) => handle::get_defs(extern_handle).nodes.get(fragment),
+ Err(()) => None,
}
}
}
@@ -55,19 +53,23 @@ impl Defs {
&mut self,
handle: *const RsvgHandle,
possibly_relative_uri: &str,
- ) -> *const RsvgHandle {
- handle::resolve_uri(handle, possibly_relative_uri).map_or(ptr::null(), |uri| {
- match self.externs.entry(uri) {
- Entry::Occupied(e) => *(e.get()),
+ ) -> Result<*const RsvgHandle, ()> {
+ match handle::resolve_uri(handle, possibly_relative_uri) {
+ None => Err(()),
+
+ Some(uri) => match self.externs.entry(uri) {
+ Entry::Occupied(e) => Ok(*(e.get())),
Entry::Vacant(e) => {
let extern_handle = handle::load_extern(handle, e.key());
- if !extern_handle.is_null() {
+ if extern_handle.is_null() {
+ Err(())
+ } else {
e.insert(extern_handle);
+ Ok(extern_handle)
}
- extern_handle
}
- }
- })
+ },
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]