Skip to content

[0.2] Require rust >= 1.24 and drop libc_const_size_of conditional #4056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2024
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
12 changes: 0 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"libc_cfg_target_vendor",
"libc_const_extern_fn",
"libc_const_extern_fn_unstable",
"libc_const_size_of",
"libc_core_cvoid",
"libc_deny_warnings",
"libc_int128",
Expand All @@ -28,7 +27,6 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"libc_ptr_addr_of",
"libc_thread_local",
"libc_underscore_const_names",
"libc_union",
"libc_ctest",
];

Expand Down Expand Up @@ -98,16 +96,6 @@ fn main() {
set_cfg("libc_deny_warnings");
}

// Rust >= 1.19 supports unions:
if rustc_minor_ver >= 19 || rustc_dep_of_std {
set_cfg("libc_union");
}

// Rust >= 1.24 supports const mem::size_of:
if rustc_minor_ver >= 24 || rustc_dep_of_std {
set_cfg("libc_const_size_of");
}

// Rust >= 1.25 supports repr(align):
if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature {
set_cfg("libc_align");
Expand Down
2 changes: 0 additions & 2 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ fn do_ctest() {
fn ctest_cfg() -> ctest::TestGenerator {
let mut cfg = ctest::TestGenerator::new();
let libc_cfgs = [
"libc_union",
"libc_const_size_of",
"libc_align",
"libc_core_cvoid",
"libc_packedN",
Expand Down
20 changes: 8 additions & 12 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,15 @@ macro_rules! s_no_extra_traits {
s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* });
)*);
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
cfg_if! {
if #[cfg(libc_union)] {
__item! {
#[repr(C)]
$(#[$attr])*
pub union $i { $($field)* }
}
__item! {
#[repr(C)]
$(#[$attr])*
pub union $i { $($field)* }
}

impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
}
impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
Expand Down
54 changes: 15 additions & 39 deletions src/unix/aix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,17 @@ s! {
}

s_no_extra_traits! {
#[cfg(libc_union)]
pub union __sigaction_sa_union {
pub __su_handler: extern fn(c: ::c_int),
pub __su_sigaction: extern fn(c: ::c_int, info: *mut siginfo_t, ptr: *mut ::c_void),
}

pub struct sigaction {
#[cfg(libc_union)]
pub sa_union: __sigaction_sa_union,
pub sa_mask: sigset_t,
pub sa_flags: ::c_int,
}

#[cfg(libc_union)]
pub union __poll_ctl_ext_u {
pub addr: *mut ::c_void,
pub data32: u32,
Expand All @@ -559,15 +556,13 @@ s_no_extra_traits! {
pub command: u8,
pub events: ::c_short,
pub fd: ::c_int,
#[cfg(libc_union)]
pub u: __poll_ctl_ext_u,
pub reversed64: [u64; 6],
}
}

cfg_if! {
if #[cfg(feature = "extra_traits")] {
#[cfg(libc_union)]
impl PartialEq for __sigaction_sa_union {
fn eq(&self, other: &__sigaction_sa_union) -> bool {
unsafe {
Expand All @@ -576,9 +571,7 @@ cfg_if! {
}
}
}
#[cfg(libc_union)]
impl Eq for __sigaction_sa_union {}
#[cfg(libc_union)]
impl ::fmt::Debug for __sigaction_sa_union {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("__sigaction_sa_union")
Expand All @@ -587,7 +580,6 @@ cfg_if! {
.finish()
}
}
#[cfg(libc_union)]
impl ::hash::Hash for __sigaction_sa_union {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand All @@ -599,36 +591,29 @@ cfg_if! {

impl PartialEq for sigaction {
fn eq(&self, other: &sigaction) -> bool {
#[cfg(libc_union)]
let union_eq = self.sa_union == other.sa_union;
#[cfg(not(libc_union))]
let union_eq = true;
self.sa_mask == other.sa_mask
&& self.sa_flags == other.sa_flags
&& union_eq
&& self.sa_union == other.sa_union
}
}
impl Eq for sigaction {}
impl ::fmt::Debug for sigaction {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
let mut struct_formatter = f.debug_struct("sigaction");
#[cfg(libc_union)]
struct_formatter.field("sa_union", &self.sa_union);
struct_formatter.field("sa_mask", &self.sa_mask);
struct_formatter.field("sa_flags", &self.sa_flags);
struct_formatter.finish()
f.debug_struct("sigaction")
.field("sa_union", &self.sa_union)
.field("sa_mask", &self.sa_mask)
.field("sa_flags", &self.sa_flags)
.finish()
}
}
impl ::hash::Hash for sigaction {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
#[cfg(libc_union)]
self.sa_union.hash(state);
self.sa_mask.hash(state);
self.sa_flags.hash(state);
}
}

#[cfg(libc_union)]
impl PartialEq for __poll_ctl_ext_u {
fn eq(&self, other: &__poll_ctl_ext_u) -> bool {
unsafe {
Expand All @@ -638,9 +623,7 @@ cfg_if! {
}
}
}
#[cfg(libc_union)]
impl Eq for __poll_ctl_ext_u {}
#[cfg(libc_union)]
impl ::fmt::Debug for __poll_ctl_ext_u {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("__poll_ctl_ext_u")
Expand All @@ -650,7 +633,6 @@ cfg_if! {
.finish()
}
}
#[cfg(libc_union)]
impl ::hash::Hash for __poll_ctl_ext_u {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand All @@ -663,30 +645,25 @@ cfg_if! {

impl PartialEq for poll_ctl_ext {
fn eq(&self, other: &poll_ctl_ext) -> bool {
#[cfg(libc_union)]
let union_eq = self.u == other.u;
#[cfg(not(libc_union))]
let union_eq = true;
self.version == other.version
&& self.command == other.command
&& self.events == other.events
&& self.fd == other.fd
&& self.reversed64 == other.reversed64
&& union_eq
&& self.u == other.u
}
}
impl Eq for poll_ctl_ext {}
impl ::fmt::Debug for poll_ctl_ext {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
let mut struct_formatter = f.debug_struct("poll_ctl_ext");
struct_formatter.field("version", &self.version);
struct_formatter.field("command", &self.command);
struct_formatter.field("events", &self.events);
struct_formatter.field("fd", &self.fd);
#[cfg(libc_union)]
struct_formatter.field("u", &self.u);
struct_formatter.field("reversed64", &self.reversed64);
struct_formatter.finish()
f.debug_struct("poll_ctl_ext")
.field("version", &self.version)
.field("command", &self.command)
.field("events", &self.events)
.field("fd", &self.fd)
.field("u", &self.u)
.field("reversed64", &self.reversed64)
.finish()
}
}
impl ::hash::Hash for poll_ctl_ext {
Expand All @@ -695,7 +672,6 @@ cfg_if! {
self.command.hash(state);
self.events.hash(state);
self.fd.hash(state);
#[cfg(libc_union)]
self.u.hash(state);
self.reversed64.hash(state);
}
Expand Down
Loading