Remove a bunch of unused functions

There is a single place left where we rsvg_node_unref() by hand in the
C code!  Woohoo!
parent 9e20b1ce
......@@ -51,13 +51,7 @@ typedef struct RsvgXmlState RsvgXmlState;
/* Implemented in rsvg_internals/src/xml.rs */
extern RsvgXmlState *rsvg_xml_state_new ();
extern void rsvg_xml_state_free (RsvgXmlState *xml);
extern void rsvg_xml_state_set_root (RsvgXmlState *xml, RsvgNode *root);
extern RsvgTree *rsvg_xml_state_steal_tree(RsvgXmlState *xml);
extern RsvgNode *rsvg_xml_state_get_current_node(RsvgXmlState *xml);
extern void rsvg_xml_state_set_current_node(RsvgXmlState *xml, RsvgNode *node);
extern void rsvg_xml_state_push_element_name(RsvgXmlState *xml, const char *name);
extern void rsvg_xml_state_pop_element_name(RsvgXmlState *xml);
extern gboolean rsvg_xml_state_topmost_element_name_is(RsvgXmlState *xml, const char *name);
extern void rsvg_xml_state_free_element_name_stack(RsvgXmlState *xml);
extern void rsvg_xml_state_standard_element_start(RsvgXmlState *xml, RsvgHandle *handle, const char *name, RsvgPropertyBag atts);
extern void rsvg_xml_state_standard_element_end(RsvgXmlState *xml, RsvgHandle *handle, const char *name);
......
......@@ -120,52 +120,17 @@ struct RsvgHandlePrivate {
#endif
};
/* Implemented in rust/src/node.rs */
/* Call this as newref = rsvg_node_ref (node); You don't own the node anymore, just the newref! */
G_GNUC_INTERNAL
RsvgNode *rsvg_node_ref (RsvgNode *node) G_GNUC_WARN_UNUSED_RESULT;
/* Implemented in rust/src/node.rs */
/* Call this as node = rsvg_node_unref (node); Then node will be NULL and you don't own it anymore! */
G_GNUC_INTERNAL
RsvgNode *rsvg_node_unref (RsvgNode *node) G_GNUC_WARN_UNUSED_RESULT;
/* Implemented in rust/src/node.rs
*
* Returns a new strong reference to the parent (or NULL); use rsvg_node_unref()
* when you are done.
*/
G_GNUC_INTERNAL
RsvgNode *rsvg_node_get_parent (RsvgNode *node) G_GNUC_WARN_UNUSED_RESULT;
/* Implemented in rust/src/node.rs */
G_GNUC_INTERNAL
void rsvg_node_add_child (RsvgNode *node, RsvgNode *child);
/* Implemented in rust/src/node.rs */
G_GNUC_INTERNAL
void rsvg_node_set_overridden_properties (RsvgNode *node);
typedef struct RsvgNodeChildrenIter *RsvgNodeChildrenIter;
/* Implemented in rust/src/node.rs */
G_GNUC_INTERNAL
RsvgNodeChildrenIter *rsvg_node_children_iter_begin (RsvgNode *node);
/* Implemented in rust/src/node.rs */
G_GNUC_INTERNAL
gboolean rsvg_node_children_iter_next (RsvgNodeChildrenIter *iter,
RsvgNode **out_child);
/* Implemented in rust/src/node.rs */
G_GNUC_INTERNAL
gboolean rsvg_node_children_iter_next_back (RsvgNodeChildrenIter *iter,
RsvgNode **out_child);
/* Implemented in rust/src/node.rs */
G_GNUC_INTERNAL
void rsvg_node_children_iter_end (RsvgNodeChildrenIter *iter);
/* Implemented in rsvg_internals/src/tree.rs */
G_GNUC_INTERNAL
void rsvg_tree_free (RsvgTree *tree);
......
......@@ -44,16 +44,7 @@ pub use drawing_ctx::{
rsvg_drawing_ctx_new,
};
pub use node::{
rsvg_node_add_child,
rsvg_node_children_iter_begin,
rsvg_node_children_iter_end,
rsvg_node_children_iter_next,
rsvg_node_find_last_chars_child,
rsvg_node_get_parent,
rsvg_node_ref,
rsvg_node_unref,
};
pub use node::rsvg_node_unref;
pub use tree::{
rsvg_tree_cascade,
......@@ -77,16 +68,10 @@ pub use xml::{
rsvg_xml_state_add_characters,
rsvg_xml_state_free,
rsvg_xml_state_free_element_name_stack,
rsvg_xml_state_get_current_node,
rsvg_xml_state_new,
rsvg_xml_state_pop_element_name,
rsvg_xml_state_push_element_name,
rsvg_xml_state_set_current_node,
rsvg_xml_state_set_root,
rsvg_xml_state_standard_element_end,
rsvg_xml_state_standard_element_start,
rsvg_xml_state_steal_tree,
rsvg_xml_state_topmost_element_name_is,
};
#[macro_use]
......
......@@ -645,33 +645,6 @@ impl Node {
}
}
pub fn node_ptr_to_weak(raw_parent: *const RsvgNode) -> Option<Weak<Node>> {
if raw_parent.is_null() {
None
} else {
let p: &RsvgNode = unsafe { &*raw_parent };
Some(Rc::downgrade(&p.clone()))
}
}
pub fn boxed_node_new(
node_type: NodeType,
raw_parent: *const RsvgNode,
element_name: &str,
id: Option<&str>,
class: Option<&str>,
node_impl: Box<NodeTrait>,
) -> *mut RsvgNode {
box_node(Rc::new(Node::new(
node_type,
node_ptr_to_weak(raw_parent),
element_name,
id,
class,
node_impl,
)))
}
pub fn node_new(
node_type: NodeType,
parent: Option<&RsvgNode>,
......@@ -749,26 +722,6 @@ pub fn box_node(node: RsvgNode) -> *mut RsvgNode {
Box::into_raw(Box::new(node))
}
#[no_mangle]
pub extern "C" fn rsvg_node_get_parent(raw_node: *const RsvgNode) -> *const RsvgNode {
assert!(!raw_node.is_null());
let node: &RsvgNode = unsafe { &*raw_node };
match node.get_parent() {
None => ptr::null(),
Some(node) => box_node(node),
}
}
#[no_mangle]
pub extern "C" fn rsvg_node_ref(raw_node: *mut RsvgNode) -> *mut RsvgNode {
assert!(!raw_node.is_null());
let node: &RsvgNode = unsafe { &*raw_node };
box_node(node.clone())
}
#[no_mangle]
pub extern "C" fn rsvg_node_unref(raw_node: *mut RsvgNode) -> *mut RsvgNode {
if !raw_node.is_null() {
......@@ -779,81 +732,10 @@ pub extern "C" fn rsvg_node_unref(raw_node: *mut RsvgNode) -> *mut RsvgNode {
ptr::null_mut()
}
#[no_mangle]
pub extern "C" fn rsvg_node_add_child(raw_node: *mut RsvgNode, raw_child: *const RsvgNode) {
assert!(!raw_node.is_null());
assert!(!raw_child.is_null());
let node: &mut RsvgNode = unsafe { &mut *raw_node };
let child: &RsvgNode = unsafe { &*raw_child };
node.add_child(child);
}
#[no_mangle]
pub extern "C" fn rsvg_node_find_last_chars_child(
raw_node: *const RsvgNode,
out_accept_chars: *mut glib_sys::gboolean,
) -> *mut RsvgNode {
assert!(!raw_node.is_null());
let node: &RsvgNode = unsafe { &*raw_node };
let accept_chars = node.accept_chars();
assert!(!out_accept_chars.is_null());
unsafe {
*out_accept_chars = accept_chars.to_glib();
}
if accept_chars {
if let Some(chars) = node.find_last_chars_child() {
return box_node(chars);
}
}
ptr::null_mut()
}
#[no_mangle]
pub extern "C" fn rsvg_node_children_iter_begin(raw_node: *const RsvgNode) -> *mut Children {
assert!(!raw_node.is_null());
let node: &RsvgNode = unsafe { &*raw_node };
Box::into_raw(Box::new(node.children()))
}
#[no_mangle]
pub extern "C" fn rsvg_node_children_iter_end(iter: *mut Children) {
assert!(!iter.is_null());
unsafe { Box::from_raw(iter) };
}
#[no_mangle]
pub extern "C" fn rsvg_node_children_iter_next(
iter: *mut Children,
out_child: *mut *mut RsvgNode,
) -> glib_sys::gboolean {
assert!(!iter.is_null());
let iter = unsafe { &mut *iter };
if let Some(child) = iter.next() {
unsafe {
*out_child = box_node(child);
}
true.to_glib()
} else {
unsafe {
*out_child = ptr::null_mut();
}
false.to_glib()
}
}
#[cfg(test)]
mod tests {
use super::*;
use handle::RsvgHandle;
use std::mem;
use std::rc::Rc;
struct TestNodeImpl {}
......@@ -864,6 +746,13 @@ mod tests {
}
}
fn rsvg_node_ref(raw_node: *mut RsvgNode) -> *mut RsvgNode {
assert!(!raw_node.is_null());
let node: &RsvgNode = unsafe { &*raw_node };
box_node(node.clone())
}
#[test]
fn node_refs_and_unrefs() {
let node = Rc::new(Node::new(
......@@ -1000,45 +889,4 @@ mod tests {
assert!(children.next().is_none());
assert!(children.next_back().is_none());
}
#[test]
fn node_children_iterator_c() {
let node = Rc::new(Node::new(
NodeType::Path,
None,
"path",
None,
None,
Box::new(TestNodeImpl {}),
));
let child = Rc::new(Node::new(
NodeType::Path,
Some(Rc::downgrade(&node)),
"path",
None,
None,
Box::new(TestNodeImpl {}),
));
let second_child = Rc::new(Node::new(
NodeType::Path,
Some(Rc::downgrade(&node)),
"path",
None,
None,
Box::new(TestNodeImpl {}),
));
node.add_child(&child);
node.add_child(&second_child);
let iter = rsvg_node_children_iter_begin(&node);
let mut c = unsafe { mem::uninitialized() };
let result: bool = from_glib(rsvg_node_children_iter_next(iter, &mut c));
assert_eq!(result, true);
assert!(Rc::ptr_eq(unsafe { &*c }, &child));
rsvg_node_unref(c);
}
}
......@@ -4,12 +4,9 @@ use std::ptr;
use std::rc::Rc;
use std::str;
use glib::translate::*;
use glib_sys;
use handle::{self, RsvgHandle};
use load::rsvg_load_new_node;
use node::{box_node, node_new, Node, NodeType, RsvgNode};
use node::{node_new, Node, NodeType};
use property_bag::PropertyBag;
use structure::NodeSvg;
use text::NodeChars;
......@@ -49,10 +46,6 @@ impl XmlState {
self.tree.take()
}
pub fn get_current_node(&self) -> Option<Rc<Node>> {
self.current_node.clone()
}
pub fn set_current_node(&mut self, node: Option<Rc<Node>>) {
self.current_node = node;
}
......@@ -184,17 +177,6 @@ pub extern "C" fn rsvg_xml_state_free(xml: *mut RsvgXmlState) {
}
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_set_root(xml: *mut RsvgXmlState, root: *const RsvgNode) {
assert!(!xml.is_null());
let xml = unsafe { &mut *(xml as *mut XmlState) };
assert!(!root.is_null());
let root = unsafe { &*root };
xml.set_root(root);
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_steal_tree(xml: *mut RsvgXmlState) -> *mut RsvgTree {
assert!(!xml.is_null());
......@@ -207,72 +189,6 @@ pub extern "C" fn rsvg_xml_state_steal_tree(xml: *mut RsvgXmlState) -> *mut Rsvg
}
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_get_current_node(xml: *const RsvgXmlState) -> *mut RsvgNode {
assert!(!xml.is_null());
let xml = unsafe { &*(xml as *const XmlState) };
if let Some(ref node) = xml.get_current_node() {
box_node(node.clone())
} else {
ptr::null_mut()
}
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_set_current_node(
xml: *mut RsvgXmlState,
raw_node: *const RsvgNode,
) {
assert!(!xml.is_null());
let xml = unsafe { &mut *(xml as *mut XmlState) };
let node = if raw_node.is_null() {
None
} else {
let n = unsafe { &*raw_node };
Some(n.clone())
};
xml.set_current_node(node);
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_push_element_name(
xml: *mut RsvgXmlState,
name: *const libc::c_char,
) {
assert!(!xml.is_null());
let xml = unsafe { &mut *(xml as *mut XmlState) };
assert!(!name.is_null());
let name = unsafe { utf8_cstr(name) };
xml.push_element_name(name);
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_pop_element_name(xml: *mut RsvgXmlState) {
assert!(!xml.is_null());
let xml = unsafe { &mut *(xml as *mut XmlState) };
xml.pop_element_name();
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_topmost_element_name_is(
xml: *mut RsvgXmlState,
name: *const libc::c_char,
) -> glib_sys::gboolean {
assert!(!xml.is_null());
let xml = unsafe { &mut *(xml as *mut XmlState) };
assert!(!name.is_null());
let name = unsafe { utf8_cstr(name) };
xml.topmost_element_name_is(name).to_glib()
}
#[no_mangle]
pub extern "C" fn rsvg_xml_state_free_element_name_stack(xml: *mut RsvgXmlState) {
assert!(!xml.is_null());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment