diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index 9475e2b4..070d5c4a 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -732,10 +732,6 @@ WMPropList* WMCreatePLArray(WMPropList *elem, ...); WMPropList* WMCreatePLString(const char *str); -WMPropList* WMCreatePLData(WMData *data); - -WMPropList* WMCreatePLDataWithBytes(const unsigned char *bytes, unsigned int length); - WMPropList* WMCreatePLArrayFromSlice(WMPropList *elems, unsigned int length); WMPropList* WMCreateEmptyPLArray(); @@ -780,8 +776,6 @@ int WMGetPropListItemCount(WMPropList *plist); Bool WMIsPLString(WMPropList *plist); -Bool WMIsPLData(WMPropList *plist); - Bool WMIsPLArray(WMPropList *plist); Bool WMIsPLDictionary(WMPropList *plist); diff --git a/wutil-rs/src/prop_list.rs b/wutil-rs/src/prop_list.rs index 3b98f022..0c303cca 100644 --- a/wutil-rs/src/prop_list.rs +++ b/wutil-rs/src/prop_list.rs @@ -49,8 +49,6 @@ pub enum Node { /// It would be better for this to be a `String`, but the C interface /// requires borrows of C-style strings. String(CString), - /// Binary data. - Data(Vec), /// Array of child `PropList`s. Array(Vec), /// `PropList`-keyed table of child `PropList`s. Keys should only have @@ -63,7 +61,6 @@ impl hash::Hash for Node { fn hash(&self, h: &mut H) { match self { Node::String(s) => s.hash(h), - Node::Data(d) => d.hash(h), Node::Array(a) => { for p in a { p.hash(h); @@ -313,7 +310,6 @@ impl PropList { pub fn deep_clone(&self) -> Self { match &*self.0.borrow() { Node::String(s) => PropList::new(Node::String(s.clone())), - Node::Data(d) => PropList::new(Node::Data(d.clone())), Node::Array(items) => { PropList::new(Node::Array(items.iter().map(|x| x.deep_clone()).collect())) } @@ -357,14 +353,14 @@ impl PropList { } pub mod ffi { - use crate::{data::Data, find_file::path_from_cstr, memory}; + use crate::{find_file::path_from_cstr, memory}; use super::{ merge_deep, merge_shallow, parser, subtract_deep, subtract_shallow, Node, PropList, }; use std::{ - collections::HashMap, ffi::{c_char, c_int, c_uchar, c_uint, CStr, CString, OsString}, ptr, str::FromStr + collections::HashMap, ffi::{c_char, c_int, c_uint, CStr, CString, OsString}, ptr, str::FromStr }; #[unsafe(no_mangle)] @@ -376,27 +372,6 @@ pub mod ffi { Box::leak(Box::new(PropList::new(Node::String(s.into())))) } - #[unsafe(no_mangle)] - pub unsafe extern "C" fn WMCreatePLData(data: *mut Data) -> *mut PropList { - if data.is_null() { - return ptr::null_mut(); - } - let data = unsafe { &*data }; - data.with_bytes(|b| Box::leak(Box::new(PropList::new(Node::Data(Vec::from(b)))))) - } - - #[unsafe(no_mangle)] - pub unsafe extern "C" fn WMCreatePLDataWithBytes( - bytes: *const c_uchar, - length: c_uint, - ) -> *mut PropList { - if bytes.is_null() { - return ptr::null_mut(); - } - let bytes = unsafe { &*ptr::slice_from_raw_parts(bytes.cast::(), length as usize) }; - Box::leak(Box::new(PropList::new(Node::Data(Vec::from(bytes))))) - } - #[unsafe(no_mangle)] pub unsafe extern "C" fn WMCreatePLArrayFromSlice( elems: *mut PropList, @@ -630,18 +605,6 @@ pub mod ffi { } } - #[unsafe(no_mangle)] - pub unsafe extern "C" fn WMIsPLData(plist: *mut PropList) -> c_int { - if plist.is_null() { - return 0; - } - let plist = unsafe { &*plist }; - match &*plist.0.borrow() { - Node::Data(_) => 1, - _ => 0, - } - } - #[unsafe(no_mangle)] pub unsafe extern "C" fn WMIsPLArray(plist: *mut PropList) -> c_int { if plist.is_null() { diff --git a/wutil-rs/src/prop_list/parser.rs b/wutil-rs/src/prop_list/parser.rs index 92d37998..de542047 100644 --- a/wutil-rs/src/prop_list/parser.rs +++ b/wutil-rs/src/prop_list/parser.rs @@ -20,7 +20,7 @@ use nom::{ character::complete::{char, multispace0, none_of, satisfy}, combinator::{cut, eof, fail, map, map_res, opt}, error::context, - multi::{fold_many0, many0, many1, many_m_n, separated_list0}, + multi::{fold_many0, many1, many_m_n, separated_list0}, sequence::{delimited, preceded, terminated}, AsChar, Finish, IResult, Input, Parser, }; @@ -32,7 +32,7 @@ fn read_dictionary_key>(input: I) -> IResult>(input: I) -> IResult>(input: I) -> IResult> { - map( - delimited( - multispace0, - ( - context( - "looking for first hex value", - satisfy(|c: char| c.is_ascii_hexdigit()), - ), - cut(context( - "looking for second hex value", - satisfy(|c: char| c.is_ascii_hexdigit()), - )), - ), - multispace0, - ), - |(upper, lower)| { - let s = &[upper as u8, lower as u8]; - // Safety: upper and lower are ASCII hexdigits, so they - // should fit into a str without validation and provide - // exactly 8 bits of value. - u8::from_str_radix(unsafe { str::from_utf8_unchecked(s) }, 16).unwrap() - }, - ) - .parse(input) -} - -fn read_data>(input: I) -> IResult> { - map( - delimited( - (multispace0, char('<')), - many0(read_data_byte), - cut(context( - "looking for data to end with '>'", - (multispace0, char('>')), - )), - ), - |bytes: Vec| PropList::new(Node::Data(bytes)), - ) - .parse(input) -} - fn unescape_character(c: char) -> char { match c { '\\' => '\\', @@ -300,7 +258,7 @@ fn read_string>(input: I) -> IResult>(input: I) -> IResult> { delimited( multispace0, - alt((read_array, read_data, read_dictionary, read_string)), + alt((read_array, read_dictionary, read_string)), multispace0, ) .parse(input) @@ -363,60 +321,6 @@ mod test { PropList::new(Node::String(CString::new(s.as_bytes()).unwrap())) } - #[test] - fn parse_data() { - let plist = from_str("").unwrap(); - assert_eq!( - plist, - PropList::new(Node::Data(vec![0xde, 0xad, 0xbe, 0xef])) - ); - } - - #[test] - fn error_unclosed_data() { - let e = from_str("': -': -, -^ - -"# - ); - } - - #[test] - fn error_incomplete_data_byte() { - let e = from_str("> { pub(crate) node: N, } -/// Quick and dirty single-branch lookup mapping `b` to a hex character. Only -/// valid for `b` in `[0, 15]`. -fn byte_char(b: u8) -> char { - match b { - 0 => '0', - 1 => '1', - 2 => '2', - 3 => '3', - 4 => '4', - 5 => '5', - 6 => '6', - 7 => '7', - 8 => '8', - 9 => '9', - 10 => 'a', - 11 => 'b', - 12 => 'c', - 13 => 'd', - 14 => 'e', - 15 => 'f', - _ => unreachable!(), - } -} - impl> Display { /// Writes whitespace to `f` for the current level of indentation. fn write_indent(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -83,32 +59,6 @@ impl> Display { } } -/// Writes a hexadecimal representation of `bytes` to `f`, splitting `bytes` up -/// into space-delimited 32-bit quartets for readability. -fn write_data_bytes(bytes: &[u8], f: &mut fmt::Formatter) -> fmt::Result { - fn write(b: u8, f: &mut fmt::Formatter) -> fmt::Result { - let upper = (b >> 3) as u8; - let lower = (b & 0x0F) as u8; - write!(f, "{}", byte_char(upper))?; - write!(f, "{}", byte_char(lower)) - } - - let mut chunks = bytes.chunks(4); - if let Some(first) = chunks.next() { - for b in first { - write(*b, f)?; - } - } - for seg in chunks { - f.write_char(' ')?; - for b in seg { - write(*b, f)?; - } - } - - Ok(()) -} - /// Writes `s` to `f`, backslash-escaping special characters as appropriate for /// a quoted property list string. fn write_escaped_string(s: &str, f: &mut fmt::Formatter) -> fmt::Result { @@ -218,11 +168,6 @@ impl> fmt::Display for Display { self.write_indent(f)?; f.write_char(')')?; } - Node::Data(bytes) => { - write!(f, "<")?; - write_data_bytes(bytes, f)?; - write!(f, ">")?; - } Node::Dictionary(items) if items.is_empty() => write!(f, "{{}}")?, Node::Dictionary(items) if self.inline != Inline::No => { // Try to fit everything in one line.