Skip to content

Commit

Permalink
Merge pull request #4090 from tgross35/backport-leek
Browse files Browse the repository at this point in the history
[0.2] Backports
  • Loading branch information
tgross35 authored Nov 18, 2024
2 parents 1c913e7 + 70e2542 commit 78d6dcb
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 31 deletions.
8 changes: 4 additions & 4 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4589,11 +4589,11 @@ fn test_linux(target: &str) {
true
}

// The `inotify_event` and `cmsghdr` types contain Flexible Array Member fields (the
// `name` and `data` fields respectively) which have unspecified calling convention.
// The roundtripping tests deliberately pass the structs by value to check "by value"
// layout consistency, but this would be UB for the these types.
// The following types contain Flexible Array Member fields which have unspecified calling
// convention. The roundtripping tests deliberately pass the structs by value to check "by
// value" layout consistency, but this would be UB for the these types.
"inotify_event" => true,
"fanotify_event_info_fid" => true,
"cmsghdr" => true,

// FIXME: the call ABI of max_align_t is incorrect on these platforms:
Expand Down
23 changes: 23 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1353,9 +1353,16 @@ IW_ENC_CAPA_CIPHER_TKIP
IW_ENC_CAPA_WPA
IW_ENC_CAPA_WPA2
IW_ESSID_MAX_SIZE
IW_EVENT_CAPA_K_0
IW_EVENT_CAPA_K_1
IW_EV_ADDR_PK_LEN
IW_EV_CHAR_PK_LEN
IW_EV_FREQ_PK_LEN
IW_EV_LCP_PK_LEN
IW_EV_PARAM_PK_LEN
IW_EV_POINT_PK_LEN
IW_EV_QUAL_PK_LEN
IW_EV_UINT_PK_LEN
IW_FREQ_AUTO
IW_FREQ_FIXED
IW_GENERIC_IE_MAX
Expand Down Expand Up @@ -3728,6 +3735,22 @@ ip_mreq_source
ip_mreqn
ipc_perm
itimerspec
iw_discarded
iw_encode_ext
iw_event
iw_freq
iw_missed
iw_param
iw_pmkid_cand
iw_pmksa
iw_point
iw_priv_args
iw_quality
iw_range
iw_scan_req
iw_statistics
iwreq
iwreq_data
j1939_filter
jrand48
key_t
Expand Down
4 changes: 4 additions & 0 deletions libc-test/semver/unix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ grantpt
group
hostent
hstrerror
htonl
htons
if_indextoname
if_nametoindex
in6_addr
Expand Down Expand Up @@ -658,6 +660,8 @@ munmap
nanosleep
nfds_t
nlink_t
ntohl
ntohs
off_t
open
opendir
Expand Down
15 changes: 15 additions & 0 deletions libc-test/test/primitive_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::any::TypeId;

macro_rules! ok {
($($t:ident)*) => {$(
assert!(TypeId::of::<libc::$t>() == TypeId::of::<ffi::$t>(),
"{} is wrong", stringify!($t));
)*}
}

#[test]
fn same() {
use std::ffi;
ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
c_longlong c_ulonglong c_float c_double);
}
30 changes: 5 additions & 25 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,11 @@ macro_rules! s {
__item! {
#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
#[allow(deprecated)]
$(#[$attr])*
pub struct $i { $($field)* }
}
#[allow(deprecated)]
impl ::Copy for $i {}
#[allow(deprecated)]
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);
}

Expand All @@ -106,13 +101,10 @@ macro_rules! s_paren {
)* ) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
$(#[$attr])*
pub struct $i ( $($field)* );
}
impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
)*);
}

Expand All @@ -130,28 +122,19 @@ macro_rules! s_no_extra_traits {
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
#[derive(Copy, Clone)]
$(#[$attr])*
pub union $i { $($field)* }
}

impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);

(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
#[derive(Copy, Clone)]
$(#[$attr])*
pub struct $i { $($field)* }
}
#[allow(deprecated)]
impl ::Copy for $i {}
#[allow(deprecated)]
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);
}

Expand All @@ -177,13 +160,10 @@ macro_rules! e {
)*) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
$(#[$attr])*
pub enum $i { $($field)* }
}
impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
)*);
}

Expand Down
Loading

0 comments on commit 78d6dcb

Please sign in to comment.