Skip to content
Draft
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: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ jobs:
run: |
set -eux
if [ "${{ matrix.toolchain }}" = "1.65.0" ]; then
# Remove `-Dwarnings` at the MSRV since lints may be different
export RUSTFLAGS=""
# Remove `-Dwarnings` at the MSRV since lints may be different, and allow
# `improper_ctypes` since pointers to ZSTs got the warning prior to 1.72.
# FIXME(msrv): remove this flag when possible.
export RUSTFLAGS="-Aimproper_ctypes"
# Remove `ctest` which uses the 2024 edition
perl -i -ne 'print unless /"ctest(-test)?",/ || /"libc-test",/' Cargo.toml
fi
Expand Down
5 changes: 4 additions & 1 deletion ci/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from glob import iglob
from pathlib import Path


FMT_DIRS = ["src", "ci"]
IGNORE_FILES = [
# Too much special syntax that we don't want to format
Expand Down Expand Up @@ -87,6 +86,9 @@ def fmt_one(fpath: Path, check_only: bool):
# syntax. Replace it with a dummy name.
text = re.sub(r"enum #anon\b", r"enum _fmt_anon", text)

# `extern_ty!` can be formatted as an extern block.
text = re.sub(r"extern_ty!", r'extern "extern-ty-macro"', text)

# If enum variants are annotated with `pub`, rustfmt erases the visibility. To get
# around this we first match on all enums to extract their bodies, then look for `pub`
# visibility indicators. If found, these get stashed in a comment on the preceding
Expand Down Expand Up @@ -126,6 +128,7 @@ def enum_sub(m: re.Match) -> str:
text = re.sub(r"cfg_tmp!\(\[(.*?)\]\)", r"#[cfg(\1)]", text, flags=re.DOTALL)
text = re.sub(r"enum _fmt_anon", r"enum #anon", text)
text = re.sub(r"/\* FMT-VIS (.*) END-FMT-VIS \*/\n\s*", r"\1 ", text)
text = re.sub(r'extern "extern-ty-macro"', r"extern_ty!", text)

# And write the formatted file back
fpath.write_text(text)
Expand Down
10 changes: 5 additions & 5 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub type fsfilcnt_t = c_ulonglong;
pub type rlim_t = c_ulonglong;

extern_ty! {
pub enum timezone {}
pub enum DIR {}
pub enum fpos64_t {} // FIXME(fuchsia): fill this out with a struct
pub type timezone;
pub type DIR;
pub type fpos64_t; // FIXME(fuchsia): fill this out with a struct
}

// PUB_STRUCT
Expand Down Expand Up @@ -3192,8 +3192,8 @@ fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
extern "C" {}

extern_ty! {
pub enum FILE {}
pub enum fpos_t {} // FIXME(fuchsia): fill this out with a struct
pub type FILE;
pub type fpos_t; // FIXME(fuchsia): fill this out with a struct
}

extern "C" {
Expand Down
24 changes: 22 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,37 @@ macro_rules! s_no_extra_traits {
macro_rules! extern_ty {
($(
$(#[$attr:meta])*
pub enum $i:ident {}
pub type $i:ident;
)*) => ($(
$(#[$attr])*
/// This is an extern type ("opaque" or "incomplete" type in C).
///
/// <div class="warning">
/// This type's current representation allows inspecting some properties, such as via
/// <code>size_of</code>, and it is technically possible to construct the type within
/// <code>MaybeUninit</code>, However, this <strong>MUST NOT</strong> be relied upon
/// because a future version of <code>libc</code> may switch to a proper
/// <a href="https://rust-lang.github.io/rfcs/1861-extern-types.html">extern type</a>
/// representation when available.
/// </div>
// ^ unfortunately warning blocks currently don't render markdown so we need to
// use raw HTML.
//
// Representation based on the Nomicon:
// <https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs>.
//
// FIXME(1.0): the type is uninhabited so these traits are unreachable and could be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FIXME seems outdated now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right; we should still remove the traits but the reason needs updating (will fix)

// removed.
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
pub enum $i { }
#[repr(C)]
pub struct $i {
_data: (),
_marker: ::core::marker::PhantomData<(*mut u8, ::core::marker::PhantomPinned)>,
}
)*);
}

Expand Down
2 changes: 1 addition & 1 deletion src/new/qurt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub type fd_set = c_ulong;

// Standard C library types
extern_ty! {
pub enum FILE {}
pub type FILE;
}
pub type fpos_t = c_long;
pub type clock_t = c_long;
Expand Down
4 changes: 2 additions & 2 deletions src/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ pub const SIGUSR2: c_int = 31;
pub const SIGPWR: c_int = 32;

extern_ty! {
pub enum FILE {}
pub enum fpos_t {}
pub type FILE;
pub type fpos_t;
}

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/aix/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::prelude::*;

// Define lock_data_instrumented as an empty enum
extern_ty! {
pub enum lock_data_instrumented {}
pub type lock_data_instrumented;
}

s! {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub type attrgroup_t = u32;
pub type vol_capabilities_set_t = [u32; 4];

extern_ty! {
pub enum timezone {}
pub type timezone;
}

c_enum! {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub type vm_map_entry_t = *mut vm_map_entry;
pub type pmap = __c_anonymous_pmap;

extern_ty! {
pub enum sem {}
pub type sem;
}

c_enum! {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cfg_if! {
// link.h

extern_ty! {
pub enum timezone {}
pub type timezone;
}

impl siginfo_t {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/bsd/netbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub type sem_t = *mut sem;
pub type key_t = c_long;

extern_ty! {
pub enum timezone {}
pub enum sem {}
pub type timezone;
pub type sem;
}

s! {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ c_enum! {
}

extern_ty! {
pub enum _cpuset {}
pub type _cpuset;
}

cfg_if! {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/cygwin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub type suseconds_t = c_long;
pub type useconds_t = c_ulong;

extern_ty! {
pub enum timezone {}
pub type timezone;
}

pub type sigset_t = c_ulong;
Expand Down Expand Up @@ -71,7 +71,7 @@ pub type nfds_t = c_uint;
pub type sem_t = *mut sem;

extern_ty! {
pub enum sem {}
pub type sem;
}

pub type tcflag_t = c_uint;
Expand Down
2 changes: 1 addition & 1 deletion src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub type posix_spawnattr_t = *mut c_void;
pub type posix_spawn_file_actions_t = *mut c_void;

extern_ty! {
pub enum timezone {}
pub type timezone;
}

impl siginfo_t {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/hurd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ pub type nl_item = c_int;
pub type iconv_t = *mut c_void;

extern_ty! {
pub enum fpos64_t {} // FIXME(hurd): fill this out with a struct
pub enum timezone {}
pub type fpos64_t; // FIXME(hurd): fill this out with a struct
pub type timezone;
}

// structs
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub type statvfs64 = crate::statvfs;
pub type dirent64 = crate::dirent;

extern_ty! {
pub enum fpos64_t {} // FIXME(emscripten): fill this out with a struct
pub type fpos64_t; // FIXME(emscripten): fill this out with a struct
}

s! {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/linux_l4re_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub type iconv_t = *mut c_void;
cfg_if! {
if #[cfg(not(target_env = "gnu"))] {
extern_ty! {
pub enum fpos64_t {} // FIXME(linux): fill this out with a struct
pub type fpos64_t; // FIXME(linux): fill this out with a struct
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub type key_t = c_int;
pub type id_t = c_uint;

extern_ty! {
pub enum timezone {}
pub type timezone;
}

s! {
Expand Down
6 changes: 3 additions & 3 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cfg_if! {
}

extern_ty! {
pub enum DIR {}
pub type DIR;
}

#[cfg(not(target_os = "nuttx"))]
Expand Down Expand Up @@ -602,13 +602,13 @@ cfg_if! {
cfg_if! {
if #[cfg(not(all(target_os = "linux", target_env = "gnu")))] {
extern_ty! {
pub enum fpos_t {} // FIXME(unix): fill this out with a struct
pub type fpos_t; // FIXME(unix): fill this out with a struct
}
}
}

extern_ty! {
pub enum FILE {}
pub type FILE;
}

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/nto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub type sem_t = sync_t;
pub type nl_item = c_int;

extern_ty! {
pub enum timezone {}
pub type timezone;
}

s! {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub type uid_t = c_int;
pub type gid_t = c_int;

extern_ty! {
pub enum timezone {}
pub type timezone;
}

s! {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/solarish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub type posix_spawnattr_t = *mut c_void;
pub type posix_spawn_file_actions_t = *mut c_void;

extern_ty! {
pub enum timezone {}
pub enum ucred_t {}
pub type timezone;
pub type ucred_t;
}

s! {
Expand Down
8 changes: 4 additions & 4 deletions src/vxworks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::ptr::null_mut;
use crate::prelude::*;

extern_ty! {
pub enum DIR {}
pub type DIR;
}

pub type intmax_t = i64;
Expand Down Expand Up @@ -95,7 +95,7 @@ pub type sa_family_t = c_uchar;
pub type mqd_t = c_int;

extern_ty! {
pub enum _Vx_semaphore {}
pub type _Vx_semaphore;
}

impl siginfo_t {
Expand Down Expand Up @@ -1435,8 +1435,8 @@ pub const TIOCGWINSZ: c_int = 0x1740087468;
pub const TIOCSWINSZ: c_int = -0x7ff78b99;

extern_ty! {
pub enum FILE {}
pub enum fpos_t {} // FIXME(vxworks): fill this out with a struct
pub type FILE;
pub type fpos_t; // FIXME(vxworks): fill this out with a struct
}

f! {
Expand Down
14 changes: 5 additions & 9 deletions src/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@ s_no_extra_traits! {
}
}

#[allow(missing_copy_implementations)]
#[derive(Debug)]
pub enum FILE {}
#[allow(missing_copy_implementations)]
#[derive(Debug)]
pub enum DIR {}
#[allow(missing_copy_implementations)]
#[derive(Debug)]
pub enum __locale_struct {}
extern_ty! {
pub type FILE;
pub type DIR;
pub type __locale_struct;
}

s_paren! {
// in wasi-libc clockid_t is const struct __clockid* (where __clockid is an opaque struct),
Expand Down
6 changes: 3 additions & 3 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub type dev_t = u32;
pub type ino_t = u16;

extern_ty! {
pub enum timezone {}
pub type timezone;
}

pub type time64_t = i64;
Expand Down Expand Up @@ -246,8 +246,8 @@ pub const L_tmpnam: c_uint = 260;
pub const TMP_MAX: c_uint = 0x7fff_ffff;

extern_ty! {
pub enum FILE {}
pub enum fpos_t {} // FIXME(windows): fill this out with a struct
pub type FILE;
pub type fpos_t; // FIXME(windows): fill this out with a struct
}

// Special handling for all print and scan type functions because of https://github.com/rust-lang/libc/issues/2860
Expand Down
Loading