[librsvg: 6/9] AcquireError::CircularReference(n) now stores an RsvgNode, not a Fragment
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 6/9] AcquireError::CircularReference(n) now stores an RsvgNode, not a Fragment
- Date: Tue, 15 Oct 2019 16:21:24 +0000 (UTC)
commit 05b1c3fe745c4c6199f3db2366a4171213d3fb95
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Oct 15 09:59:13 2019 -0500
AcquireError::CircularReference(n) now stores an RsvgNode, not a Fragment
We'll add a way for <use> to add itself to the stack of acquired
nodes, even if it doesn't have a Fragment id associated to it.
This also removes impl Error for AcquiredError; it's not needed, and
it would complicate things because Error requires Debug, and we can't
impl Debug on RsvgError because of the orphan rule.
rsvg_internals/src/drawing_ctx.rs | 2 +-
rsvg_internals/src/error.rs | 21 +++++----------------
rsvg_internals/src/gradient.rs | 2 +-
rsvg_internals/src/paint_server.rs | 3 +--
rsvg_internals/src/pattern.rs | 2 +-
rsvg_internals/src/structure.rs | 5 ++---
6 files changed, 11 insertions(+), 24 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 589ed501..ecb33de9 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -1140,7 +1140,7 @@ impl AcquiredNodes {
if node_is_accessed_by_reference(&node) {
if self.node_stack.borrow().contains(&node) {
- Err(AcquireError::CircularReference(fragment.clone()))
+ Err(AcquireError::CircularReference(node.clone()))
} else {
self.node_stack.borrow_mut().push(&node);
Ok(AcquiredNode {
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index dff26a4e..05c90f99 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -11,6 +11,7 @@ use libc;
use markup5ever::LocalName;
use crate::allowed_url::Fragment;
+use crate::node::RsvgNode;
use crate::parsers::ParseError;
/// A simple error which refers to an attribute's value
@@ -123,25 +124,13 @@ impl From<cairo::Status> for RenderingError {
}
}
-#[derive(Debug)]
pub enum AcquireError {
LinkNotFound(Fragment),
InvalidLinkType(Fragment),
- CircularReference(Fragment),
+ CircularReference(RsvgNode),
MaxReferencesExceeded,
}
-impl error::Error for AcquireError {
- fn description(&self) -> &str {
- match *self {
- AcquireError::LinkNotFound(_) => "link not found",
- AcquireError::InvalidLinkType(_) => "link is to object of invalid type",
- AcquireError::CircularReference(_) => "circular reference in link",
- AcquireError::MaxReferencesExceeded => "maximum number of references exceeded",
- }
- }
-}
-
impl fmt::Display for AcquireError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
@@ -151,11 +140,11 @@ impl fmt::Display for AcquireError {
AcquireError::InvalidLinkType(ref frag) =>
write!(f, "link {} is to object of invalid type", frag),
- AcquireError::CircularReference(ref frag) =>
- write!(f, "circular reference in link {}", frag),
+ AcquireError::CircularReference(ref node) =>
+ write!(f, "circular reference in node {}", node),
AcquireError::MaxReferencesExceeded =>
- write!(f, "{}", self.description()),
+ write!(f, "maximum number of references exceeded"),
}
}
}
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index 6e87138f..b4803ffe 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -638,7 +638,7 @@ macro_rules! impl_paint_source {
let acquired_node = acquired.get();
if stack.contains(acquired_node) {
- return Err(AcquireError::CircularReference(fragment.clone()));
+ return Err(AcquireError::CircularReference(acquired_node.clone()));
}
let borrowed_node = acquired_node.borrow();
diff --git a/rsvg_internals/src/paint_server.rs b/rsvg_internals/src/paint_server.rs
index 357d3506..cfc76089 100644
--- a/rsvg_internals/src/paint_server.rs
+++ b/rsvg_internals/src/paint_server.rs
@@ -77,8 +77,7 @@ pub trait PaintSource {
resolved.set_as_paint_source(values, draw_ctx, opacity, bbox)
}
- Err(AcquireError::CircularReference(_)) => {
- // FIXME: add a fragment or node id to this:
+ Err(AcquireError::CircularReference(node)) => {
rsvg_log!("circular reference in paint server {}", node);
Err(RenderingError::CircularReference)
}
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index 8edf4fe7..dab166b7 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -180,7 +180,7 @@ impl PaintSource for NodePattern {
let acquired_node = acquired.get();
if stack.contains(acquired_node) {
- return Err(AcquireError::CircularReference(fragment.clone()));
+ return Err(AcquireError::CircularReference(acquired_node.clone()));
}
let borrowed_node = acquired_node.borrow();
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 49ea396d..773d1dff 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -316,9 +316,8 @@ impl NodeTrait for NodeUse {
let acquired = match draw_ctx.acquire_node(link, &[]) {
Ok(acquired) => acquired,
- Err(AcquireError::CircularReference(_)) => {
- // FIXME: add a fragment or node id to this:
- rsvg_log!("circular reference in <use> element {}", node);
+ Err(AcquireError::CircularReference(node)) => {
+ rsvg_log!("circular reference in element {}", node);
return Err(RenderingError::CircularReference);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]