Skip to content
Open
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
2 changes: 1 addition & 1 deletion xdr-codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ unstable = []

[dependencies]
byteorder = "1.0"
error-chain = "0.10"
error-chain = "0.12"

[dev-dependencies]
quickcheck = "0.4"
4 changes: 2 additions & 2 deletions xdrgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ env_logger = "0.4"
nom = { version="3.1", features=["verbose-errors"] }
quote = "0.3"
clap = "2.24"
lazy_static = "0.2"
bitflags = "0.9"
lazy_static = "1.4"
bitflags = "1.2"

[dependencies.xdr-codec]
path = "../xdr-codec"
Expand Down
30 changes: 15 additions & 15 deletions xdrgen/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ impl ToTokens for Derives {

let mut der = Vec::new();

if self.contains(COPY) {
if self.contains(Derives::COPY) {
der.push(quote!(Copy))
}
if self.contains(CLONE) {
if self.contains(Derives::CLONE) {
der.push(quote!(Clone))
}
if self.contains(DEBUG) {
if self.contains(Derives::DEBUG) {
der.push(quote!(Debug))
}
if self.contains(EQ) {
if self.contains(Derives::EQ) {
der.push(quote!(Eq))
}
if self.contains(PARTIALEQ) {
if self.contains(Derives::PARTIALEQ) {
der.push(quote!(PartialEq))
}

Expand All @@ -73,7 +73,7 @@ lazy_static! {
"while", "yield",
];

kws.into_iter().map(|x| *x).collect()
kws.iter().map(|x| *x).collect()
};
}

Expand Down Expand Up @@ -222,7 +222,7 @@ impl Type {
use self::Type::*;
let mut memoset = HashMap::new();

let mut memo = match memo {
let memo = match memo {
None => &mut memoset,
Some(m) => m,
};
Expand All @@ -238,7 +238,7 @@ impl Type {
&Array(ref ty, ref len) => {
let ty = ty.as_ref();
let set = match ty {
&Opaque | &String => EQ | PARTIALEQ | COPY | CLONE | DEBUG,
&Opaque | &String => Derives::EQ | Derives::PARTIALEQ | Derives::COPY | Derives::CLONE | Derives::DEBUG,
ref ty => ty.derivable(symtab, Some(memo)),
};
match len.as_i64(symtab) {
Expand All @@ -248,10 +248,10 @@ impl Type {
}
&Flex(ref ty, ..) => {
let set = ty.derivable(symtab, Some(memo));
set & !COPY // no Copy, everything else OK
set & !Derives::COPY // no Copy, everything else OK
}
&Enum(_) => EQ | PARTIALEQ | COPY | CLONE | DEBUG,
&Option(ref ty) => ty.derivable(symtab, Some(memo)),
&Enum(_) => Derives::EQ | Derives::PARTIALEQ | Derives::COPY | Derives::CLONE | Derives::DEBUG,
&Option(ref ty) => ty.derivable(symtab, Some(memo)) & !Derives::COPY,
&Struct(ref fields) => {
fields.iter().fold(Derives::all(), |a, f| {
a & f.derivable(symtab, memo)
Expand All @@ -277,10 +277,10 @@ impl Type {
}
}

&Float | &Double => PARTIALEQ | COPY | CLONE | DEBUG,
&Float | &Double => Derives::PARTIALEQ | Derives::COPY | Derives::CLONE | Derives::DEBUG,
ty if ty.is_prim(symtab) => Derives::all(),

_ => Derives::all() & !COPY,
_ => Derives::all() & !Derives::COPY,
};

memo.insert(self.clone(), set);
Expand Down Expand Up @@ -348,7 +348,7 @@ impl Type {
match ty {
&Opaque | &String => {
quote!({
let mut buf: [u8; #value as usize] = unsafe { ::std::mem::uninitialized() };
let mut buf: [u8; #value as usize] = unsafe { ::std::mem::MaybeUninit::uninit().assume_init() };
let sz = xdr_codec::unpack_opaque_array(input, &mut buf[..], #value as usize)?;
(buf, sz)
})
Expand Down Expand Up @@ -383,7 +383,7 @@ impl Type {
fn uninit_ptr_dropper<T>(p: &mut T) {
unsafe { ::std::ptr::drop_in_place(p) }
}
let mut buf: [#ty; #value as usize] = unsafe { ::std::mem::uninitialized() };
let mut buf: [#ty; #value as usize] = unsafe { ::std::mem::MaybeUninit::uninit().assume_init() };
let res = ::std::panic::catch_unwind(
::std::panic::AssertUnwindSafe(||
xdr_codec::unpack_array_with(
Expand Down
18 changes: 9 additions & 9 deletions xdrgen/src/spec/xdr_nom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use nom::IResult::*;
use std::str;

use super::{Decl, Defn, EnumDefn, Type, UnionCase, Value};
use super::{CLONE, COPY, DEBUG, EQ, PARTIALEQ};
use super::{Derives};

#[inline]
fn ignore<T>(_: T) -> () {
Expand Down Expand Up @@ -87,14 +87,14 @@ named!(definition<Defn>,

fn is_hexdigit(ch: u8) -> bool {
match ch as char {
'0'...'9' | 'A'...'F' | 'a'...'f' => true,
'0'..='9' | 'A'..='F' | 'a'..='f' => true,
_ => false,
}
}

fn is_octdigit(ch: u8) -> bool {
match ch as char {
'0'...'7' => true,
'0'..='7' => true,
_ => false,
}
}
Expand Down Expand Up @@ -188,8 +188,8 @@ fn token(input: &[u8]) -> IResult<&[u8], &[u8]> {

for (idx, item) in input.iter().enumerate() {
match *item as char {
'a'...'z' | 'A'...'Z' | '_' => continue,
'0'...'9' if idx > 0 => continue,
'a'..='z' | 'A'..='Z' | '_' => continue,
'0'..='9' if idx > 0 => continue,
_ => {
if idx > 0 {
return Done(&input[idx..], &input[0..idx]);
Expand Down Expand Up @@ -569,13 +569,13 @@ named!(type_spec<Type>,
do_parse!(kw_unsigned >> kw_int >> (Type::UInt)) |
do_parse!(kw_unsigned >> kw_long >> (Type::UInt)) | // backwards compat with rpcgen
do_parse!(kw_unsigned >> kw_char >> // backwards compat with rpcgen
(Type::ident_with_derives("u8", COPY | CLONE | EQ | PARTIALEQ | DEBUG))) |
(Type::ident_with_derives("u8", Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG))) |
do_parse!(kw_unsigned >> kw_short >> (Type::UInt)) | // backwards compat with rpcgen
do_parse!(kw_unsigned >> kw_hyper >> (Type::UHyper)) |
kw_unsigned => { |_| Type::UInt } | // backwards compat with rpcgen
kw_long => { |_| Type::Int } | // backwards compat with rpcgen
kw_char => { // backwards compat with rpcgen
|_| Type::ident_with_derives("i8", COPY | CLONE | EQ | PARTIALEQ | DEBUG)
|_| Type::ident_with_derives("i8", Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG)
} |
kw_short => { |_| Type::Int } | // backwards compat with rpcgen
kw_int => { |_| Type::Int } |
Expand Down Expand Up @@ -604,7 +604,7 @@ fn test_type() {
assert_eq!(type_spec(&b"unsigned hyper "[..]), Done(&b" "[..], Type::UHyper));

assert_eq!(type_spec(&b"unsigned char "[..]), Done(&b" "[..],
Type::Ident("u8".into(), Some(COPY | CLONE | EQ | PARTIALEQ | DEBUG))));
Type::Ident("u8".into(), Some(Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG))));
assert_eq!(type_spec(&b"unsigned short "[..]), Done(&b" "[..], Type::UInt));

assert_eq!(type_spec(&b" hyper "[..]), Done(&b" "[..], Type::Hyper));
Expand All @@ -613,7 +613,7 @@ fn test_type() {
assert_eq!(type_spec(&b"// thing\n bool "[..]), Done(&b" "[..], Type::Bool));

assert_eq!(type_spec(&b"char "[..]), Done(&b" "[..],
Type::Ident("i8".into(), Some(COPY | CLONE | EQ | PARTIALEQ | DEBUG))));
Type::Ident("i8".into(), Some(Derives::COPY | Derives::CLONE | Derives::EQ | Derives::PARTIALEQ | Derives::DEBUG))));

assert_eq!(type_spec(&b"short "[..]), Done(&b" "[..], Type::Int));

Expand Down