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
6 changes: 6 additions & 0 deletions cpp2rust/compat/arpa/inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
#undef htonl
#undef htons

#ifdef __cplusplus
extern "C" {
#endif
uint32_t cpp2rust_ntohl(uint32_t x);
uint16_t cpp2rust_ntohs(uint16_t x);
uint32_t cpp2rust_htonl(uint32_t x);
uint16_t cpp2rust_htons(uint16_t x);
#ifdef __cplusplus
}
#endif

#define ntohl(x) cpp2rust_ntohl(x)
#define ntohs(x) cpp2rust_ntohs(x)
Expand Down
6 changes: 6 additions & 0 deletions cpp2rust/compat/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#undef errno

#ifdef __cplusplus
extern "C" {
#endif
int *cpp2rust_errno(void);
#ifdef __cplusplus
}
#endif

#define errno (*cpp2rust_errno())
6 changes: 6 additions & 0 deletions cpp2rust/compat/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
#undef FD_ISSET
#undef FD_ZERO

#ifdef __cplusplus
extern "C" {
#endif
void cpp2rust_fd_set(int fd, fd_set *set);
void cpp2rust_fd_clr(int fd, fd_set *set);
int cpp2rust_fd_isset(int fd, const fd_set *set);
void cpp2rust_fd_zero(fd_set *set);
#ifdef __cplusplus
}
#endif

#define FD_SET(fd, set) cpp2rust_fd_set(fd, set)
#define FD_CLR(fd, set) cpp2rust_fd_clr(fd, set)
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/out/refcount/size_t_ssize_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ fn main_0() -> i32 {
((sizes.as_pointer() as Ptr<usize>).to_end()).reinterpret_cast::<usize>();
assert!((((sizes_end).clone() - (sizes.as_pointer() as Ptr::<usize>)) as i64 == 4_i64));
assert!((((sizes_end.offset(-((1) as isize))).read()) == 4_usize));
let set: Value<CFdSet> = Rc::new(RefCell::new(Default::default()));
(set.as_pointer()).with_mut(|__s| __s.zero());
(set.as_pointer()).with_mut(|__s| __s.set(3));
assert!(
(if (set.as_pointer()).with(|__s| __s.isset(3)) {
1
} else {
0
} != 0)
);
libcc2rs::cpp2rust_errno().write(42);
assert!(((libcc2rs::cpp2rust_errno().read()) == 42));
assert!((u32::from_be(u32::to_be(7_u32)) == 7_u32));
return 0;
}
pub fn __cpp2rust_init_globals() {}
7 changes: 7 additions & 0 deletions tests/unit/out/unsafe/size_t_ssize_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ unsafe fn main_0() -> i32 {
== (4_i64))
);
assert!(((*(sizes_end.offset(-((1) as isize)))) == (4_usize)));
let mut set: ::libc::fd_set = std::mem::zeroed::<::libc::fd_set>();
libc::FD_ZERO((&mut set as *mut ::libc::fd_set));
libc::FD_SET(3, (&mut set as *mut ::libc::fd_set));
assert!((libc::FD_ISSET(3, (&mut set as *mut ::libc::fd_set).cast_const()) as i32 != 0));
(*libcc2rs::cpp2rust_errno_unsafe()) = 42;
assert!(((*libcc2rs::cpp2rust_errno_unsafe()) == (42)));
assert!(((u32::from_be(u32::to_be(7_u32))) == (7_u32)));
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
13 changes: 13 additions & 0 deletions tests/unit/size_t_ssize_t.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <algorithm>
#include <arpa/inet.h>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <errno.h>
#include <iterator>
#include <sys/select.h>
#include <sys/types.h>
#include <utility>

Expand Down Expand Up @@ -113,5 +116,15 @@ int main() {
const size_t *sizes_end = std::end(sizes);
assert(sizes_end - sizes == 4);
assert(*(sizes_end - 1) == 4);

fd_set set;
FD_ZERO(&set);
FD_SET(3, &set);
assert(FD_ISSET(3, &set));

errno = 42;
assert(errno == 42);

assert(ntohl(htonl(7)) == 7);
return 0;
}
Loading