Skip to content

Commit 48fd7d7

Browse files
committed
Add ctypes
Fixes it first. Add versions for ctypes.rs Improve ctypes.rs
1 parent 4c39b34 commit 48fd7d7

File tree

2 files changed

+313
-0
lines changed

2 files changed

+313
-0
lines changed

library/core/src/ctypes.rs

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
//! Type aliases to C types like c_int for use with bindgen
2+
//!
3+
//! # MSRV
4+
//!
5+
//! This crate is guaranteed to compile on stable Rust 1.30.0 and up. It *might* compile with older
6+
//! versions but that may change in any new patch release.
7+
8+
#![allow(non_camel_case_types)]
9+
#![deny(warnings)]
10+
11+
// AD = Architecture dependent
12+
#[stable(feature = "core_primitive", since = "1.43.0")]
13+
pub use ad::*;
14+
// OD = OS dependent
15+
#[stable(feature = "core_primitive", since = "1.43.0")]
16+
pub use od::*;
17+
// OD IOVEC = OS dependent iovec
18+
#[stable(feature = "core_primitive", since = "1.43.0")]
19+
pub use od_iovec::*;
20+
// OD wchar = OS dependent wchar_t
21+
#[stable(feature = "core_primitive", since = "1.43.0")]
22+
pub use od_wchar::*;
23+
// OD wint = OS dependent wint_t
24+
#[stable(feature = "core_primitive", since = "1.43.0")]
25+
pub use od_wint::*;
26+
// PWD = Pointer Width Dependent
27+
#[stable(feature = "core_primitive", since = "1.43.0")]
28+
pub use pwd::*;
29+
30+
//===================================================================
31+
// c_char, c_int, c_uint
32+
//===================================================================
33+
34+
#[cfg(any(target_arch = "aarch64",
35+
target_arch = "arm",
36+
target_arch = "asmjs",
37+
target_arch = "wasm32",
38+
target_arch = "wasm64",
39+
target_arch = "powerpc",
40+
target_arch = "powerpc64",
41+
target_arch = "s390x",
42+
target_arch = "riscv32",
43+
target_arch = "riscv64"))]
44+
mod ad {
45+
use super::c_uchar;
46+
#[stable(feature = "rust1", since = "1.0.0")]
47+
pub type c_char = c_uchar;
48+
49+
#[stable(feature = "rust1", since = "1.0.0")]
50+
pub type c_int = i32;
51+
#[stable(feature = "rust1", since = "1.0.0")]
52+
pub type c_uint = u32;
53+
}
54+
55+
#[cfg(any(target_arch = "mips",
56+
target_arch = "mips64",
57+
target_arch = "sparc64",
58+
target_arch = "x86",
59+
target_arch = "x86_64",
60+
target_arch = "nvptx",
61+
target_arch = "nvptx64",
62+
target_arch = "xtensa"))]
63+
mod ad {
64+
use super::c_schar;
65+
#[stable(feature = "rust1", since = "1.0.0")]
66+
pub type c_char = c_schar;
67+
68+
#[stable(feature = "rust1", since = "1.0.0")]
69+
pub type c_int = i32;
70+
#[stable(feature = "rust1", since = "1.0.0")]
71+
pub type c_uint = u32;
72+
}
73+
74+
#[cfg(target_arch = "msp430")]
75+
mod ad {
76+
use super::c_uchar;
77+
#[stable(feature = "rust1", since = "1.0.0")]
78+
pub type c_char = c_uchar;
79+
80+
#[stable(feature = "rust1", since = "1.0.0")]
81+
pub type c_int = i16;
82+
#[stable(feature = "rust1", since = "1.0.0")]
83+
pub type c_uint = u16;
84+
}
85+
86+
//===================================================================
87+
// c_long, c_ulong
88+
//===================================================================
89+
90+
// NOTE c_{,u}long definitions come from libc v0.2.3
91+
#[cfg(not(
92+
any(target_os = "windows",
93+
target_os = "redox",
94+
target_os = "solaris")))]
95+
mod od {
96+
#[cfg(any(target_pointer_width = "16",
97+
target_pointer_width = "32"))]
98+
#[stable(feature = "rust1", since = "1.0.0")]
99+
pub type c_long = i32;
100+
#[cfg(any(target_pointer_width = "16",
101+
target_pointer_width = "32"))]
102+
#[stable(feature = "rust1", since = "1.0.0")]
103+
pub type c_ulong = u32;
104+
105+
#[cfg(target_pointer_width = "64")]
106+
#[stable(feature = "rust1", since = "1.0.0")]
107+
pub type c_long = i64;
108+
#[cfg(target_pointer_width = "64")]
109+
#[stable(feature = "rust1", since = "1.0.0")]
110+
pub type c_ulong = u64;
111+
}
112+
113+
#[cfg(any(target_os = "windows"))]
114+
#[stable(feature = "rust1", since = "1.0.0")]
115+
mod od {
116+
#[stable(feature = "rust1", since = "1.0.0")]
117+
pub type c_long = i32;
118+
#[stable(feature = "rust1", since = "1.0.0")]
119+
pub type c_ulong = u32;
120+
}
121+
122+
#[cfg(any(target_os = "redox",
123+
target_os = "solaris"))]
124+
#[stable(feature = "rust1", since = "1.0.0")]
125+
mod od {
126+
#[stable(feature = "rust1", since = "1.0.0")]
127+
pub type c_long = i64;
128+
#[stable(feature = "rust1", since = "1.0.0")]
129+
pub type c_ulong = u64;
130+
}
131+
132+
//===================================================================
133+
// int8_t to c_void, all platform are the same
134+
//===================================================================
135+
136+
#[stable(feature = "rust1", since = "1.0.0")]
137+
pub type int8_t = i8;
138+
#[stable(feature = "rust1", since = "1.0.0")]
139+
pub type int16_t = i16;
140+
#[stable(feature = "rust1", since = "1.0.0")]
141+
pub type int32_t = i32;
142+
#[stable(feature = "rust1", since = "1.0.0")]
143+
pub type int64_t = i64;
144+
145+
#[stable(feature = "rust1", since = "1.0.0")]
146+
pub type uint8_t = u8;
147+
#[stable(feature = "rust1", since = "1.0.0")]
148+
pub type uint16_t = u16;
149+
#[stable(feature = "rust1", since = "1.0.0")]
150+
pub type uint32_t = u32;
151+
#[stable(feature = "rust1", since = "1.0.0")]
152+
pub type uint64_t = u64;
153+
154+
#[stable(feature = "rust1", since = "1.0.0")]
155+
pub type c_schar = i8;
156+
#[stable(feature = "rust1", since = "1.0.0")]
157+
pub type c_short = i16;
158+
#[stable(feature = "rust1", since = "1.0.0")]
159+
pub type c_longlong = i64;
160+
161+
#[stable(feature = "rust1", since = "1.0.0")]
162+
pub type c_uchar = u8;
163+
#[stable(feature = "rust1", since = "1.0.0")]
164+
pub type c_ushort = u16;
165+
#[stable(feature = "rust1", since = "1.0.0")]
166+
pub type c_ulonglong = u64;
167+
168+
#[stable(feature = "rust1", since = "1.0.0")]
169+
pub type c_float = f32;
170+
#[stable(feature = "rust1", since = "1.0.0")]
171+
pub type c_double = f64;
172+
173+
#[stable(feature = "rust1", since = "1.0.0")]
174+
pub type intmax_t = i64;
175+
#[stable(feature = "rust1", since = "1.0.0")]
176+
pub type uintmax_t = u64;
177+
178+
#[stable(feature = "rust1", since = "1.0.0")]
179+
pub type size_t = usize;
180+
#[stable(feature = "rust1", since = "1.0.0")]
181+
pub type ptrdiff_t = isize;
182+
#[stable(feature = "rust1", since = "1.0.0")]
183+
pub type intptr_t = isize;
184+
#[stable(feature = "rust1", since = "1.0.0")]
185+
pub type uintptr_t = usize;
186+
#[stable(feature = "rust1", since = "1.0.0")]
187+
pub type ssize_t = isize;
188+
189+
#[stable(feature = "core_primitive", since = "1.43.0")]
190+
pub type va_list<'a,'b> = super::ffi::VaList<'a, 'b>;
191+
192+
#[stable(feature = "rust1", since = "1.0.0")]
193+
pub type c_void = crate::ffi::c_void;
194+
195+
//===================================================================
196+
// struct iovec, iov_len_t
197+
//===================================================================
198+
199+
// iovec is special to move part of std::io component into core, other
200+
// struct type doesn't have such limitation.
201+
// Add iov_len_t for easily do cast, becase windows are different
202+
203+
#[cfg(not(any(
204+
target_os = "windows")))]
205+
mod od_iovec {
206+
use super::size_t;
207+
#[stable(feature = "rust1", since = "1.0.0")]
208+
use super::c_void;
209+
#[stable(feature = "rust1", since = "1.0.0")]
210+
pub type iov_len_t = size_t;
211+
/// Refer to https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/uio.h.html
212+
/// Refer to https://github.com/bminor/glibc/blob/master/misc/bits/types/struct_iovec.h
213+
#[repr(C)]
214+
#[derive(Copy, Clone,Debug)]
215+
#[stable(feature = "rust1", since = "1.0.0")]
216+
pub struct iovec {
217+
#[stable(feature = "rust1", since = "1.0.0")]
218+
pub iov_base: *mut c_void,
219+
#[stable(feature = "rust1", since = "1.0.0")]
220+
pub iov_len: iov_len_t,
221+
}
222+
}
223+
224+
#[cfg(any(target_os = "windows"))]
225+
mod od_iovec {
226+
use super::c_ulong;
227+
use super::c_void;
228+
/// Refer to https://docs.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-wsabuf
229+
#[stable(feature = "rust1", since = "1.0.0")]
230+
pub type iov_len_t = c_ulong;
231+
#[repr(C)]
232+
#[derive(Copy, Clone,Debug)]
233+
#[stable(feature = "rust1", since = "1.0.0")]
234+
pub struct iovec {
235+
#[stable(feature = "rust1", since = "1.0.0")]
236+
pub iov_len: iov_len_t,
237+
#[stable(feature = "rust1", since = "1.0.0")]
238+
pub iov_base: *mut c_void,
239+
}
240+
}
241+
242+
//===================================================================
243+
// wchar_t
244+
//===================================================================
245+
#[cfg(not(
246+
any(target_os = "windows",
247+
target_os = "vxworks")))]
248+
mod od_wchar {
249+
use super::int32_t;
250+
#[stable(feature = "rust1", since = "1.0.0")]
251+
pub type wchar_t = int32_t;
252+
}
253+
254+
#[cfg(any(target_os = "windows",
255+
target_os = "vxworks"))]
256+
mod od_wchar {
257+
use super::uint16_t;
258+
#[stable(feature = "rust1", since = "1.0.0")]
259+
pub type wchar_t = uint16_t;
260+
}
261+
262+
//===================================================================
263+
// wint_t
264+
//===================================================================
265+
#[cfg(not(
266+
any(target_os = "windows",
267+
target_os = "vxworks")))]
268+
mod od_wint {
269+
use super::uint32_t;
270+
#[stable(feature = "rust1", since = "1.0.0")]
271+
pub type wint_t = uint32_t;
272+
#[stable(feature = "rust1", since = "1.0.0")]
273+
pub const WEOF: wint_t = 0xFFFF_FFFFu32;
274+
}
275+
276+
#[cfg(any(target_os = "windows"))]
277+
mod od_wint {
278+
use super::uint16_t;
279+
#[stable(feature = "rust1", since = "1.0.0")]
280+
pub type wint_t = uint16_t;
281+
#[stable(feature = "rust1", since = "1.0.0")]
282+
pub const WEOF: wint_t = 0xFFFFu16;
283+
}
284+
285+
#[cfg(any(target_os = "vxworks"))]
286+
mod od_wint {
287+
use super::int32_t;
288+
#[stable(feature = "rust1", since = "1.0.0")]
289+
pub type wint_t = int32_t;
290+
#[stable(feature = "rust1", since = "1.0.0")]
291+
pub const WEOF: wint_t = -1i32;
292+
}
293+
294+
//===================================================================
295+
// wctype_t TODO: This is os dependent
296+
//===================================================================
297+
#[stable(feature = "rust1", since = "1.0.0")]
298+
pub type wctype_t = i64;
299+
300+
//===================================================================
301+
// pwd not used yet
302+
//===================================================================
303+
304+
#[cfg(target_pointer_width = "32")]
305+
mod pwd {}
306+
307+
#[cfg(target_pointer_width = "64")]
308+
mod pwd {}
309+

library/core/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ pub mod task;
270270
#[allow(missing_docs)]
271271
pub mod alloc;
272272

273+
#[stable(feature = "core_primitive", since = "1.43.0")]
274+
#[allow(missing_docs)]
275+
pub mod ctypes;
276+
273277
// note: does not need to be public
274278
mod bool;
275279
mod tuple;

0 commit comments

Comments
 (0)