Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "libxml"
version = "0.3.6"
edition = "2021"
edition = "2024"
authors = ["Andreas Franzén <andreas@devil.se>", "Deyan Ginev <deyan.ginev@gmail.com>","Jan Frederik Schaefer <j.schaefer@jacobs-university.de>"]
description = "A Rust wrapper for libxml2 - the XML C parser and toolkit developed for the Gnome project"
repository = "https://github.com/KWARC/rust-libxml"
Expand Down Expand Up @@ -33,10 +33,9 @@ pkg-config = "0.3.2"
pkg-config = "0.3.2"

[build-dependencies.bindgen]
version = "0.71"
version = "0.72"
features = [
"runtime",
"which-rustfmt",
]
default-features = false

Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl StructuredError {
/// This function copies data from the memory `error_ptr` but does not deallocate
/// the error. Depending on the context in which this function is used, you may
/// need to take additional steps to avoid a memory leak.
pub unsafe fn from_raw(error_ptr: *const bindings::xmlError) -> Self {
pub unsafe fn from_raw(error_ptr: *const bindings::xmlError) -> Self { unsafe {
let error = *error_ptr;
let message = StructuredError::ptr_to_string(error.message);
let level = XmlErrorLevel::from_raw(error.level);
Expand All @@ -92,7 +92,7 @@ impl StructuredError {
domain: error.domain,
code: error.code,
}
}
}}

/// Human-readable informative error message.
///
Expand Down
8 changes: 4 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,25 @@ fn xml_open(filename: &str) -> io::Result<*mut c_void> {
}

/// Read callback for an FS file.
unsafe extern "C" fn xml_read(context: *mut c_void, buffer: *mut c_char, len: c_int) -> c_int {
unsafe extern "C" fn xml_read(context: *mut c_void, buffer: *mut c_char, len: c_int) -> c_int { unsafe {
// Len is always positive, typically 40-4000 bytes.
let file = context as *mut fs::File;
let buf = slice::from_raw_parts_mut(buffer as *mut u8, len as usize);
match io::Read::read(&mut *file, buf) {
Ok(v) => v as c_int,
Err(_) => -1,
}
}
}}

type XmlReadCallback = unsafe extern "C" fn(*mut c_void, *mut c_char, c_int) -> c_int;

/// Close callback for an FS file.
unsafe extern "C" fn xml_close(context: *mut c_void) -> c_int {
unsafe extern "C" fn xml_close(context: *mut c_void) -> c_int { unsafe {
// Take rust ownership of the context and then drop it.
let file = context as *mut fs::File;
let _ = Box::from_raw(file);
0
}
}}

type XmlCloseCallback = unsafe extern "C" fn(*mut c_void) -> c_int;

Expand Down
12 changes: 6 additions & 6 deletions src/tree/document/c14n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Document {
}
}

unsafe fn c_obuf_into_output(c_obuf: xmlOutputBufferPtr) -> String {
unsafe fn c_obuf_into_output(c_obuf: xmlOutputBufferPtr) -> String { unsafe {
let ctx_ptr = (*c_obuf).context;
let output = Box::from_raw(ctx_ptr as *mut String);

Expand All @@ -64,9 +64,9 @@ unsafe fn c_obuf_into_output(c_obuf: xmlOutputBufferPtr) -> String {
xmlOutputBufferClose(c_obuf);

*output
}
}}

unsafe fn create_output_buffer() -> xmlOutputBufferPtr {
unsafe fn create_output_buffer() -> xmlOutputBufferPtr { unsafe {
let output = String::new();
let ctx_ptr = Box::into_raw(Box::new(output));
let encoder = std::ptr::null_mut();
Expand All @@ -78,7 +78,7 @@ unsafe fn create_output_buffer() -> xmlOutputBufferPtr {
(*buf).context = ctx_ptr as _;

buf
}
}}

unsafe extern "C" fn xml_close_io(_context: *mut raw::c_void) -> raw::c_int {
0
Expand All @@ -88,7 +88,7 @@ unsafe extern "C" fn xml_write_io(
io_ptr: *mut raw::c_void,
buffer: *const raw::c_char,
len: raw::c_int,
) -> raw::c_int {
) -> raw::c_int { unsafe {
if io_ptr.is_null() {
0
} else {
Expand All @@ -99,7 +99,7 @@ unsafe extern "C" fn xml_write_io(

len
}
}
}}

/// Create a [Vec] of null-terminated [*mut xmlChar] strings
fn to_xml_string_vec(vec: Vec<String>) -> Vec<*mut xmlChar> {
Expand Down
30 changes: 15 additions & 15 deletions src/tree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ impl Node {
Some(child) => {
let mut current_node = child;
while !current_node.is_element_node() {
if let Some(sibling) = current_node.get_next_sibling() {
match current_node.get_next_sibling() { Some(sibling) => {
current_node = sibling;
} else {
} _ => {
break;
}
}}
}
if current_node.is_element_node() {
Some(current_node)
Expand All @@ -243,11 +243,11 @@ impl Node {
Some(child) => {
let mut current_node = child;
while !current_node.is_element_node() {
if let Some(sibling) = current_node.get_prev_sibling() {
match current_node.get_prev_sibling() { Some(sibling) => {
current_node = sibling;
} else {
} _ => {
break;
}
}}
}
if current_node.is_element_node() {
Some(current_node)
Expand All @@ -265,11 +265,11 @@ impl Node {
Some(child) => {
let mut current_node = child;
while !current_node.is_element_node() {
if let Some(sibling) = current_node.get_next_sibling() {
match current_node.get_next_sibling() { Some(sibling) => {
current_node = sibling;
} else {
} _ => {
break;
}
}}
}
if current_node.is_element_node() {
Some(current_node)
Expand All @@ -287,11 +287,11 @@ impl Node {
Some(child) => {
let mut current_node = child;
while !current_node.is_element_node() {
if let Some(sibling) = current_node.get_prev_sibling() {
match current_node.get_prev_sibling() { Some(sibling) => {
current_node = sibling;
} else {
} _ => {
break;
}
}}
}
if current_node.is_element_node() {
Some(current_node)
Expand Down Expand Up @@ -1085,7 +1085,7 @@ impl Node {
// nothing to do here, already in place
Ok(old)
} else if self.get_type() == Some(NodeType::ElementNode) {
if let Some(old_parent) = old.get_parent() {
match old.get_parent() { Some(old_parent) => {
if &old_parent == self {
// unlink new to be available for insertion
new.unlink();
Expand All @@ -1100,12 +1100,12 @@ impl Node {
old_parent.get_name()
)))
}
} else {
} _ => {
Err(From::from(format!(
"Old node was not a child of {:?} parent. No registered parent exists.",
self.get_name()
)))
}
}}
} else {
Err(From::from(
"Can only call replace_child_node an a NodeType::Element type parent.",
Expand Down
12 changes: 6 additions & 6 deletions tests/tree_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ fn child_of_root_has_different_hash() {
let doc = doc_result.unwrap();
let root = doc.get_root_element().unwrap();
assert!(!root.is_text_node());
if let Some(child) = root.get_first_child() {
match root.get_first_child() { Some(child) => {
assert!(root != child);
} else {
} _ => {
assert!(false); //test failed - child doesn't exist
}
}}
// same check with last child
if let Some(child) = root.get_last_child() {
match root.get_last_child() { Some(child) => {
assert!(root != child);
} else {
} _ => {
assert!(false); //test failed - child doesn't exist
}
}}
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/xpath_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn xpath_find_string_values() {
assert!(doc_result.is_ok());
let doc = doc_result.unwrap();
let mut xpath = libxml::xpath::Context::new(&doc).unwrap();
if let Some(root) = doc.get_root_element() {
match doc.get_root_element() { Some(root) => {
let tests = root.get_child_elements();
let empty_test = &tests[0];
let ids_test = &tests[1];
Expand All @@ -211,9 +211,9 @@ fn xpath_find_string_values() {
assert_eq!(ids_values, expected_ids);
let node_ids_values = ids_test.findvalues(".//@xml:id");
assert_eq!(node_ids_values, expected_ids);
} else {
} _ => {
panic!("Document fails to obtain root!");
}
}}
}

/// Tests for checking xpath well-formedness
Expand Down
Loading