[librsvg] node.rs: New function rsvg_node_set_attribute_parse_error()



commit 80dbfe0bad0e24379058a4220ed240a94d101ae4
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Mar 16 08:04:28 2017 -0600

    node.rs: New function rsvg_node_set_attribute_parse_error()
    
    We will use this from the C code to set a node as being in error, for
    example, when failing to parse an attribute value.

 rsvg-private.h   |    4 ++++
 rust/src/lib.rs  |    1 +
 rust/src/node.rs |   25 +++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/rsvg-private.h b/rsvg-private.h
index a6680c7..ad44591 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -395,6 +395,10 @@ void rsvg_node_set_atts (RsvgNode *node, RsvgHandle *handle, RsvgPropertyBag *at
 G_GNUC_INTERNAL
 void rsvg_node_draw (RsvgNode *node, RsvgDrawingCtx *draw, int dominate);
 
+/* Implemented in rust/src/node.rs */
+G_GNUC_INTERNAL
+void rsvg_node_set_attribute_parse_error (RsvgNode *node, const char *attr_name, const char *description);
+
 /* Used to iterate among a node's children with rsvg_node_foreach_child().
  * If this caller-supplied function returns FALSE, iteration will stop.
  * Otherwise, iteration will continue to the next child node.
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 4983a63..4a8011c 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -55,6 +55,7 @@ pub use node::{
     rsvg_node_add_child,
     rsvg_node_set_atts,
     rsvg_node_draw,
+    rsvg_node_set_attribute_parse_error,
     rsvg_node_foreach_child,
 };
 
diff --git a/rust/src/node.rs b/rust/src/node.rs
index be53efb..8438146 100644
--- a/rust/src/node.rs
+++ b/rust/src/node.rs
@@ -1,4 +1,5 @@
 extern crate libc;
+extern crate glib;
 
 use std::rc::Rc;
 use std::rc::Weak;
@@ -17,6 +18,9 @@ use property_bag::RsvgPropertyBag;
 use state::RsvgState;
 
 use error::*;
+use parsers::ParseError;
+
+use self::glib::translate::*;
 
 /* A *const RsvgNode is just a pointer for the C code's benefit: it
  * points to an  Rc<Node>, which is our refcounted Rust representation
@@ -162,6 +166,10 @@ impl Node {
         }
     }
 
+    pub fn set_error (&self, error: NodeError) {
+        *self.result.borrow_mut () = Err (error);
+    }
+
     pub fn get_c_impl (&self) -> *const RsvgCNodeImpl {
         self.node_impl.get_c_impl ()
     }
@@ -310,6 +318,23 @@ pub extern fn rsvg_node_draw (raw_node: *const RsvgNode, draw_ctx: *const RsvgDr
     node.draw (node, draw_ctx, dominate);
 }
 
+#[no_mangle]
+pub extern fn rsvg_node_set_attribute_parse_error (raw_node:    *const RsvgNode,
+                                                   attr_name:   *const libc::c_char,
+                                                   description: *const libc::c_char)
+{
+    assert! (!raw_node.is_null ());
+    let node: &RsvgNode = unsafe { & *raw_node };
+
+    assert! (!attr_name.is_null ());
+    assert! (!description.is_null ());
+
+    unsafe {
+        node.set_error (NodeError::parse_error (&String::from_glib_none (attr_name),
+                                                ParseError::new (&String::from_glib_none (description))));
+    }
+}
+
 type NodeForeachChild = unsafe extern "C" fn (node: *const RsvgNode, data: *const libc::c_void) -> bool;
 
 #[no_mangle]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]