-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #53910 - IsaacWoods:unify_cvoid, r=SimonSapin
Move std::os::raw::c_void into libcore and re-export in libstd Implements the first part of [RFC 2521](rust-lang/rfcs#2521). cc #53856
- Loading branch information
Showing
4 changed files
with
48 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![stable(feature = "", since = "1.30.0")] | ||
|
||
#![allow(non_camel_case_types)] | ||
|
||
//! Utilities related to FFI bindings. | ||
use ::fmt; | ||
|
||
/// Equivalent to C's `void` type when used as a [pointer]. | ||
/// | ||
/// In essence, `*const c_void` is equivalent to C's `const void*` | ||
/// and `*mut c_void` is equivalent to C's `void*`. That said, this is | ||
/// *not* the same as C's `void` return type, which is Rust's `()` type. | ||
/// | ||
/// Ideally, this type would be equivalent to [`!`], but currently it may | ||
/// be more ideal to use `c_void` for FFI purposes. | ||
/// | ||
/// [`!`]: ../../std/primitive.never.html | ||
/// [pointer]: ../../std/primitive.pointer.html | ||
// NB: For LLVM to recognize the void pointer type and by extension | ||
// functions like malloc(), we need to have it represented as i8* in | ||
// LLVM bitcode. The enum used here ensures this and prevents misuse | ||
// of the "raw" type by only having private variants.. We need two | ||
// variants, because the compiler complains about the repr attribute | ||
// otherwise. | ||
#[repr(u8)] | ||
#[stable(feature = "raw_os", since = "1.1.0")] | ||
pub enum c_void { | ||
#[unstable(feature = "c_void_variant", reason = "should not have to exist", | ||
issue = "0")] | ||
#[doc(hidden)] __variant1, | ||
#[unstable(feature = "c_void_variant", reason = "should not have to exist", | ||
issue = "0")] | ||
#[doc(hidden)] __variant2, | ||
} | ||
|
||
#[stable(feature = "std_debug", since = "1.16.0")] | ||
impl fmt::Debug for c_void { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.pad("c_void") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters