|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +pub fn main() { |
| 10 | + std::process::exit(main_0()); |
| 11 | +} |
| 12 | +fn main_0() -> i32 { |
| 13 | + let fds: Value<Box<[i32]>> = Rc::new(RefCell::new( |
| 14 | + (0..2).map(|_| <i32>::default()).collect::<Box<[i32]>>(), |
| 15 | + )); |
| 16 | + assert!( |
| 17 | + (((match nix::unistd::pipe() { |
| 18 | + Ok((__r, __w)) => { |
| 19 | + let __fds = (fds.as_pointer() as Ptr<i32>).clone(); |
| 20 | + __fds.write(FdRegistry::register(__r)); |
| 21 | + __fds.offset(1).write(FdRegistry::register(__w)); |
| 22 | + 0 |
| 23 | + } |
| 24 | + Err(__e) => { |
| 25 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 26 | + -1 |
| 27 | + } |
| 28 | + } == 0) as i32) |
| 29 | + != 0) |
| 30 | + ); |
| 31 | + assert!( |
| 32 | + (((match FdRegistry::with_fd((*fds.borrow())[(1) as usize], |__fd| { |
| 33 | + Ptr::from_string_literal(b"x") |
| 34 | + .to_any() |
| 35 | + .reinterpret_cast::<u8>() |
| 36 | + .with_slice(1_usize, |__buf| nix::unistd::write(__fd, __buf)) |
| 37 | + }) { |
| 38 | + Ok(__n) => __n as isize, |
| 39 | + Err(__e) => { |
| 40 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 41 | + -1 |
| 42 | + } |
| 43 | + } == 1_isize) as i32) |
| 44 | + != 0) |
| 45 | + ); |
| 46 | + let pfd: Value<Box<[libcc2rs::Pollfd]>> = Rc::new(RefCell::new( |
| 47 | + (0..2) |
| 48 | + .map(|_| Default::default()) |
| 49 | + .collect::<Box<[libcc2rs::Pollfd]>>(), |
| 50 | + )); |
| 51 | + (*(*pfd.borrow())[(0) as usize].fd.borrow_mut()) = (*fds.borrow())[(0) as usize]; |
| 52 | + (*(*pfd.borrow())[(0) as usize].events.borrow_mut()) = 1_i16; |
| 53 | + (*(*pfd.borrow())[(0) as usize].revents.borrow_mut()) = 0_i16; |
| 54 | + (*(*pfd.borrow())[(1) as usize].fd.borrow_mut()) = -1_i32; |
| 55 | + (*(*pfd.borrow())[(1) as usize].events.borrow_mut()) = 1_i16; |
| 56 | + (*(*pfd.borrow())[(1) as usize].revents.borrow_mut()) = 42_i16; |
| 57 | + assert!( |
| 58 | + ((({ |
| 59 | + let __p = (pfd.as_pointer() as Ptr<libcc2rs::Pollfd>).clone(); |
| 60 | + let __timeout = match nix::poll::PollTimeout::try_from(0) { |
| 61 | + Ok(__t) => __t, |
| 62 | + Err(_) => panic!("poll: unsupported timeout {}", 0), |
| 63 | + }; |
| 64 | + let mut __idx = Vec::new(); |
| 65 | + let mut __wanted = Vec::new(); |
| 66 | + let mut __events = Vec::new(); |
| 67 | + for __i in 0..(2_u64 as usize) { |
| 68 | + let (__fd, __ev) = __p |
| 69 | + .offset(__i) |
| 70 | + .with(|__e| (*__e.fd.borrow(), *__e.events.borrow())); |
| 71 | + __p.offset(__i) |
| 72 | + .with_mut(|__e| *__e.revents.borrow_mut() = 0); |
| 73 | + if __fd >= 0 { |
| 74 | + __idx.push(__i); |
| 75 | + __wanted.push(__fd); |
| 76 | + __events.push(__ev); |
| 77 | + } |
| 78 | + } |
| 79 | + FdRegistry::with_fds(&__wanted, |__b| { |
| 80 | + let mut __pfds: Vec<nix::poll::PollFd> = __b |
| 81 | + .iter() |
| 82 | + .zip(&__events) |
| 83 | + .map(|(&__fd, &__ev)| { |
| 84 | + nix::poll::PollFd::new(__fd, nix::poll::PollFlags::from_bits_truncate(__ev)) |
| 85 | + }) |
| 86 | + .collect(); |
| 87 | + match nix::poll::poll(&mut __pfds, __timeout) { |
| 88 | + Ok(__count) => { |
| 89 | + for (__slot, &__i) in __pfds.iter().zip(&__idx) { |
| 90 | + let __rev = match __slot.revents() { |
| 91 | + Some(__r) => __r.bits(), |
| 92 | + None => 0, |
| 93 | + }; |
| 94 | + __p.offset(__i) |
| 95 | + .with_mut(|__e| *__e.revents.borrow_mut() = __rev); |
| 96 | + } |
| 97 | + __count |
| 98 | + } |
| 99 | + Err(__e) => { |
| 100 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 101 | + -1 |
| 102 | + } |
| 103 | + } |
| 104 | + }) |
| 105 | + } == 1) as i32) |
| 106 | + != 0) |
| 107 | + ); |
| 108 | + assert!( |
| 109 | + ((((((*(*pfd.borrow())[(0) as usize].revents.borrow()) as i32) & 1) != 0) as i32) != 0) |
| 110 | + ); |
| 111 | + assert!((((((*(*pfd.borrow())[(1) as usize].revents.borrow()) as i32) == 0) as i32) != 0)); |
| 112 | + let ch: Value<u8> = <Value<u8>>::default(); |
| 113 | + assert!( |
| 114 | + (((match FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { |
| 115 | + ((ch.as_pointer()) as Ptr<u8>) |
| 116 | + .to_any() |
| 117 | + .reinterpret_cast::<u8>() |
| 118 | + .with_slice_mut(1_usize, |__buf| nix::unistd::read(__fd, __buf)) |
| 119 | + }) { |
| 120 | + Ok(__n) => __n as isize, |
| 121 | + Err(__e) => { |
| 122 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 123 | + -1 |
| 124 | + } |
| 125 | + } == 1_isize) as i32) |
| 126 | + != 0) |
| 127 | + ); |
| 128 | + assert!((((FdRegistry::close((*fds.borrow())[(0) as usize]) == 0) as i32) != 0)); |
| 129 | + assert!((((FdRegistry::close((*fds.borrow())[(1) as usize]) == 0) as i32) != 0)); |
| 130 | + return 0; |
| 131 | +} |
0 commit comments