Skip to content

Commit

Permalink
Fix the sockopt_impl matcher rule order.
Browse files Browse the repository at this point in the history
Rules for generic types were located above rules for specific types, so the
rules for specific types never got matched.  This caused the
sys::socket::sockopt::test::can_get_listen_on_tcp_socket test to fail on
FreeBSD.  The solution is to put all of the generic rules at the bottom.
  • Loading branch information
asomers authored and fiveop committed Aug 10, 2016
1 parent bae5a37 commit 36789c7
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ macro_rules! getsockopt_impl {

// Helper to generate the sockopt accessors
macro_rules! sockopt_impl {
(GetOnly, $name:ident, $level:path, $flag:path, $ty:ty) => {
sockopt_impl!(GetOnly, $name, $level, $flag, $ty, GetStruct<$ty>);
};

(GetOnly, $name:ident, $level:path, $flag:path, bool) => {
sockopt_impl!(GetOnly, $name, $level, $flag, bool, GetBool);
};
Expand All @@ -65,17 +61,6 @@ macro_rules! sockopt_impl {
sockopt_impl!(GetOnly, $name, $level, $flag, usize, GetUsize);
};

(GetOnly, $name:ident, $level:path, $flag:path, $ty:ty, $getter:ty) => {
#[derive(Copy, Clone, Debug)]
pub struct $name;

getsockopt_impl!($name, $level, $flag, $ty, $getter);
};

(SetOnly, $name:ident, $level:path, $flag:path, $ty:ty) => {
sockopt_impl!(SetOnly, $name, $level, $flag, $ty, SetStruct<$ty>);
};

(SetOnly, $name:ident, $level:path, $flag:path, bool) => {
sockopt_impl!(SetOnly, $name, $level, $flag, bool, SetBool);
};
Expand All @@ -88,31 +73,50 @@ macro_rules! sockopt_impl {
sockopt_impl!(SetOnly, $name, $level, $flag, usize, SetUsize);
};

(SetOnly, $name:ident, $level:path, $flag:path, $ty:ty, $setter:ty) => {
#[derive(Copy, Clone, Debug)]
pub struct $name;
(Both, $name:ident, $level:path, $flag:path, bool) => {
sockopt_impl!(Both, $name, $level, $flag, bool, GetBool, SetBool);
};

setsockopt_impl!($name, $level, $flag, $ty, $setter);
(Both, $name:ident, $level:path, $flag:path, u8) => {
sockopt_impl!(Both, $name, $level, $flag, u8, GetU8, SetU8);
};

(Both, $name:ident, $level:path, $flag:path, $ty:ty, $getter:ty, $setter:ty) => {
(Both, $name:ident, $level:path, $flag:path, usize) => {
sockopt_impl!(Both, $name, $level, $flag, usize, GetUsize, SetUsize);
};

/*
* Matchers with generic getter types must be placed at the end, so
* they'll only match _after_ specialized matchers fail
*/
(GetOnly, $name:ident, $level:path, $flag:path, $ty:ty) => {
sockopt_impl!(GetOnly, $name, $level, $flag, $ty, GetStruct<$ty>);
};

(GetOnly, $name:ident, $level:path, $flag:path, $ty:ty, $getter:ty) => {
#[derive(Copy, Clone, Debug)]
pub struct $name;

setsockopt_impl!($name, $level, $flag, $ty, $setter);
getsockopt_impl!($name, $level, $flag, $ty, $getter);
};

(Both, $name:ident, $level:path, $flag:path, bool) => {
sockopt_impl!(Both, $name, $level, $flag, bool, GetBool, SetBool);
(SetOnly, $name:ident, $level:path, $flag:path, $ty:ty) => {
sockopt_impl!(SetOnly, $name, $level, $flag, $ty, SetStruct<$ty>);
};

(Both, $name:ident, $level:path, $flag:path, u8) => {
sockopt_impl!(Both, $name, $level, $flag, u8, GetU8, SetU8);
(SetOnly, $name:ident, $level:path, $flag:path, $ty:ty, $setter:ty) => {
#[derive(Copy, Clone, Debug)]
pub struct $name;

setsockopt_impl!($name, $level, $flag, $ty, $setter);
};

(Both, $name:ident, $level:path, $flag:path, usize) => {
sockopt_impl!(Both, $name, $level, $flag, usize, GetUsize, SetUsize);
(Both, $name:ident, $level:path, $flag:path, $ty:ty, $getter:ty, $setter:ty) => {
#[derive(Copy, Clone, Debug)]
pub struct $name;

setsockopt_impl!($name, $level, $flag, $ty, $setter);
getsockopt_impl!($name, $level, $flag, $ty, $getter);
};

(Both, $name:ident, $level:path, $flag:path, $ty:ty) => {
Expand Down

0 comments on commit 36789c7

Please sign in to comment.