Skip to content

Commit

Permalink
Remove raw_os_nonzero feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jan 29, 2024
1 parent fb4bca0 commit bf4de3a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 67 deletions.
64 changes: 14 additions & 50 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

use crate::fmt;
use crate::marker::PhantomData;
use crate::num::*;
use crate::ops::{Deref, DerefMut};

#[stable(feature = "core_c_str", since = "1.64.0")]
pub use self::c_str::{CStr, FromBytesUntilNulError, FromBytesWithNulError};

mod c_str;

macro_rules! type_alias_no_nz {
macro_rules! type_alias {
{
$Docfile:tt, $Alias:ident = $Real:ty;
$( $Cfg:tt )*
Expand All @@ -31,49 +30,24 @@ macro_rules! type_alias_no_nz {
}
}

// To verify that the NonZero types in this file's macro invocations correspond
//
// perl -n < library/std/src/os/raw/mod.rs -e 'next unless m/type_alias\!/; die "$_ ?" unless m/, (c_\w+) = (\w+), NonZero_(\w+) = NonZero(\w+)/; die "$_ ?" unless $3 eq $1 and $4 eq ucfirst $2'
//
// NB this does not check that the main c_* types are right.

macro_rules! type_alias {
{
$Docfile:tt, $Alias:ident = $Real:ty, $NZAlias:ident = $NZReal:ty;
$( $Cfg:tt )*
} => {
type_alias_no_nz! { $Docfile, $Alias = $Real; $( $Cfg )* }

#[doc = concat!("Type alias for `NonZero` version of [`", stringify!($Alias), "`]")]
#[unstable(feature = "raw_os_nonzero", issue = "82363")]
$( $Cfg )*
pub type $NZAlias = $NZReal;
}
}

type_alias! { "c_char.md", c_char = c_char_definition::c_char, NonZero_c_char = c_char_definition::NonZero_c_char;
#[doc(cfg(all()))] }
type_alias! { "c_char.md", c_char = c_char_definition::c_char; #[doc(cfg(all()))] }

type_alias! { "c_schar.md", c_schar = i8, NonZero_c_schar = NonZeroI8; }
type_alias! { "c_uchar.md", c_uchar = u8, NonZero_c_uchar = NonZeroU8; }
type_alias! { "c_short.md", c_short = i16, NonZero_c_short = NonZeroI16; }
type_alias! { "c_ushort.md", c_ushort = u16, NonZero_c_ushort = NonZeroU16; }
type_alias! { "c_schar.md", c_schar = i8; }
type_alias! { "c_uchar.md", c_uchar = u8; }
type_alias! { "c_short.md", c_short = i16; }
type_alias! { "c_ushort.md", c_ushort = u16; }

type_alias! { "c_int.md", c_int = c_int_definition::c_int, NonZero_c_int = c_int_definition::NonZero_c_int;
#[doc(cfg(all()))] }
type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint, NonZero_c_uint = c_int_definition::NonZero_c_uint;
#[doc(cfg(all()))] }
type_alias! { "c_int.md", c_int = c_int_definition::c_int; #[doc(cfg(all()))] }
type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint; #[doc(cfg(all()))] }

type_alias! { "c_long.md", c_long = c_long_definition::c_long, NonZero_c_long = c_long_definition::NonZero_c_long;
#[doc(cfg(all()))] }
type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong, NonZero_c_ulong = c_long_definition::NonZero_c_ulong;
#[doc(cfg(all()))] }
type_alias! { "c_long.md", c_long = c_long_definition::c_long; #[doc(cfg(all()))] }
type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong; #[doc(cfg(all()))] }

type_alias! { "c_longlong.md", c_longlong = i64, NonZero_c_longlong = NonZeroI64; }
type_alias! { "c_ulonglong.md", c_ulonglong = u64, NonZero_c_ulonglong = NonZeroU64; }
type_alias! { "c_longlong.md", c_longlong = i64; }
type_alias! { "c_ulonglong.md", c_ulonglong = u64; }

type_alias_no_nz! { "c_float.md", c_float = f32; }
type_alias_no_nz! { "c_double.md", c_double = f64; }
type_alias! { "c_float.md", c_float = f32; }
type_alias! { "c_double.md", c_double = f64; }

/// Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++).
///
Expand Down Expand Up @@ -152,11 +126,9 @@ mod c_char_definition {
target_os = "horizon"
))] {
pub type c_char = u8;
pub type NonZero_c_char = crate::num::NonZeroU8;
} else {
// On every other target, c_char is signed.
pub type c_char = i8;
pub type NonZero_c_char = crate::num::NonZeroI8;
}
}
}
Expand All @@ -165,14 +137,10 @@ mod c_int_definition {
cfg_if! {
if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
pub type c_int = i16;
pub type NonZero_c_int = crate::num::NonZeroI16;
pub type c_uint = u16;
pub type NonZero_c_uint = crate::num::NonZeroU16;
} else {
pub type c_int = i32;
pub type NonZero_c_int = crate::num::NonZeroI32;
pub type c_uint = u32;
pub type NonZero_c_uint = crate::num::NonZeroU32;
}
}
}
Expand All @@ -181,15 +149,11 @@ mod c_long_definition {
cfg_if! {
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
pub type c_long = i64;
pub type NonZero_c_long = crate::num::NonZeroI64;
pub type c_ulong = u64;
pub type NonZero_c_ulong = crate::num::NonZeroU64;
} else {
// The minimal size of `long` in the C standard is 32 bits
pub type c_long = i32;
pub type NonZero_c_long = crate::num::NonZeroI32;
pub type c_ulong = u32;
pub type NonZero_c_ulong = crate::num::NonZeroU32;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@
#![feature(portable_simd)]
#![feature(prelude_2024)]
#![feature(ptr_as_uninit)]
#![feature(raw_os_nonzero)]
#![feature(slice_internals)]
#![feature(slice_ptr_get)]
#![feature(slice_range)]
Expand Down
7 changes: 3 additions & 4 deletions library/std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::fmt;
use crate::io::{self, Error, ErrorKind};
use crate::mem;
use crate::num::NonZeroI32;
use crate::num::{NonZero, NonZeroI32};
use crate::sys;
use crate::sys::cvt;
use crate::sys::process::process_common::*;
use core::ffi::NonZero_c_int;

#[cfg(target_os = "linux")]
use crate::os::linux::process::PidFd;
Expand Down Expand Up @@ -935,7 +934,7 @@ impl ExitStatus {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
// true for a platform pretending to be Unix, the tests (our doctests, and also
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
match NonZero_c_int::try_from(self.0) {
match NonZero::try_from(self.0) {
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
/* was zero, couldn't convert */ Err(_) => Ok(()),
}
Expand Down Expand Up @@ -1092,7 +1091,7 @@ impl fmt::Display for ExitStatus {
}

#[derive(PartialEq, Eq, Clone, Copy)]
pub struct ExitStatusError(NonZero_c_int);
pub struct ExitStatusError(NonZero<c_int>);

impl Into<ExitStatus> for ExitStatusError {
fn into(self) -> ExitStatus {
Expand Down
5 changes: 2 additions & 3 deletions library/std/src/sys/pal/unix/process/process_unsupported.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::fmt;
use crate::io;
use crate::num::NonZeroI32;
use crate::num::{NonZero, NonZeroI32};
use crate::sys::pal::unix::unsupported::*;
use crate::sys::process::process_common::*;
use core::ffi::NonZero_c_int;

use libc::{c_int, pid_t};

Expand Down Expand Up @@ -59,7 +58,7 @@ mod wait_status;
pub use wait_status::ExitStatus;

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct ExitStatusError(NonZero_c_int);
pub struct ExitStatusError(NonZero<c_int>);

impl Into<ExitStatus> for ExitStatusError {
fn into(self) -> ExitStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Emulated wait status for non-Unix #[cfg(unix) platforms
//!
//! Separate module to facilitate testing against a real Unix implementation.
use core::ffi::NonZero_c_int;

use crate::ffi::c_int;
use crate::fmt;
use crate::num::NonZero;

use super::ExitStatusError;

Expand Down Expand Up @@ -50,7 +49,7 @@ impl ExitStatus {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
// true for a platform pretending to be Unix, the tests (our doctests, and also
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
match NonZero_c_int::try_from(self.wait_status) {
match NonZero::try_from(self.wait_status) {
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
/* was zero, couldn't convert */ Err(_) => Ok(()),
}
Expand Down
7 changes: 3 additions & 4 deletions library/std/src/sys/pal/unix/process/process_vxworks.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::fmt;
use crate::io::{self, Error, ErrorKind};
use crate::num::NonZeroI32;
use crate::num::{NonZero, NonZeroI32};
use crate::sys;
use crate::sys::cvt;
use crate::sys::process::process_common::*;
use crate::sys_common::thread;
use core::ffi::NonZero_c_int;
use libc::RTP_ID;
use libc::{self, c_char, c_int};

Expand Down Expand Up @@ -197,7 +196,7 @@ impl ExitStatus {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
// true for a platform pretending to be Unix, the tests (our doctests, and also
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
match NonZero_c_int::try_from(self.0) {
match NonZero::try_from(self.0) {
Ok(failure) => Err(ExitStatusError(failure)),
Err(_) => Ok(()),
}
Expand Down Expand Up @@ -249,7 +248,7 @@ impl fmt::Display for ExitStatus {
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct ExitStatusError(NonZero_c_int);
pub struct ExitStatusError(NonZero<c_int>);

impl Into<ExitStatus> for ExitStatusError {
fn into(self) -> ExitStatus {
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/pal/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

use crate::ffi::CStr;
use crate::mem;
use crate::num::NonZero;
pub use crate::os::raw::c_int;
use crate::os::raw::{c_char, c_long, c_longlong, c_uint, c_ulong, c_ushort, c_void};
use crate::os::windows::io::{AsRawHandle, BorrowedHandle};
use crate::ptr;
use core::ffi::NonZero_c_ulong;

mod windows_sys;
pub use windows_sys::*;

pub type DWORD = c_ulong;
pub type NonZeroDWORD = NonZero_c_ulong;
pub type NonZeroDWORD = NonZero<c_ulong>;
pub type LARGE_INTEGER = c_longlong;
#[cfg_attr(target_vendor = "uwp", allow(unused))]
pub type LONG = c_long;
Expand Down

0 comments on commit bf4de3a

Please sign in to comment.