Skip to content

Commit ec058b3

Browse files
committed
Slightly improve no_std support
See also #305
1 parent 883c832 commit ec058b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+76
-71
lines changed

crates/block2/src/abi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//! [ABI]: https://clang.llvm.org/docs/Block-ABI-Apple.html
66
#![allow(unused)]
77

8+
use core::ffi::{c_char, c_int, c_ulong, c_void};
89
use core::fmt;
9-
use core::{ffi::c_void, mem::MaybeUninit};
10-
use std::os::raw::{c_char, c_int, c_ulong};
10+
use core::mem::MaybeUninit;
1111

1212
use alloc::format;
1313

crates/block2/src/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use core::ffi::CStr;
12
use core::fmt::{Debug, DebugStruct, Error, Formatter};
23
use core::ptr;
3-
use std::ffi::CStr;
44

55
use crate::abi::{BlockDescriptorPtr, BlockFlags, BlockHeader};
66
use crate::ffi;

crates/block2/src/ffi.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! # Raw bindings to `Block.h`
22
33
use core::cell::UnsafeCell;
4+
use core::ffi::c_int;
45
use core::ffi::c_void;
56
use core::marker::{PhantomData, PhantomPinned};
6-
use std::os::raw::c_int;
77

88
#[cfg(not(feature = "unstable-c-unwind"))]
99
#[doc(hidden)]
@@ -122,9 +122,9 @@ extern_c_unwind! {
122122
pub mod private {
123123
use super::*;
124124
#[cfg(any(doc, target_vendor = "apple", feature = "gnustep-1-7"))]
125-
use std::os::raw::c_char;
125+
use core::ffi::c_char;
126126
#[cfg(any(doc, target_vendor = "apple", feature = "compiler-rt"))]
127-
use std::os::raw::c_ulong;
127+
use core::ffi::c_ulong;
128128

129129
extern_c_unwind! {
130130
pub static _NSConcreteMallocBlock: Class;
@@ -186,7 +186,6 @@ pub mod private {
186186
mod tests {
187187
use super::*;
188188
use core::ptr;
189-
use std::println;
190189

191190
#[test]
192191
fn smoke() {
@@ -196,7 +195,9 @@ mod tests {
196195

197196
#[test]
198197
#[allow(unused_unsafe)]
198+
#[cfg(feature = "std")]
199199
fn test_linkable() {
200+
use std::println;
200201
println!("{:?}", unsafe { ptr::addr_of!(_NSConcreteGlobalBlock) });
201202
println!("{:?}", unsafe { ptr::addr_of!(_NSConcreteStackBlock) });
202203
println!("{:?}", unsafe {

crates/block2/src/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use core::ffi::c_ulong;
12
use core::fmt;
23
use core::marker::PhantomData;
34
use core::mem;
45
use core::mem::MaybeUninit;
56
use core::ops::Deref;
67
use core::ptr::{self, NonNull};
7-
use std::os::raw::c_ulong;
88

99
use crate::abi::{BlockDescriptor, BlockDescriptorPtr, BlockFlags, BlockHeader};
1010
use crate::debug::debug_block_header;

crates/block2/src/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use core::ffi::c_ulong;
12
use core::ffi::c_void;
23
use core::fmt;
34
use core::marker::PhantomData;
45
use core::mem::{self, MaybeUninit};
56
use core::ops::Deref;
67
use core::panic::{RefUnwindSafe, UnwindSafe};
78
use core::ptr::{self, NonNull};
8-
use std::os::raw::c_ulong;
99

1010
use objc2::encode::{EncodeArguments, EncodeReturn, Encoding, RefEncode};
1111

crates/objc2/benches/autorelease.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::ffi::c_void;
2-
use std::mem::ManuallyDrop;
2+
use core::mem::ManuallyDrop;
33

44
use objc2::rc::{autoreleasepool, Retained};
55
use objc2::runtime::{AnyClass, NSObject, Sel};

crates/objc2/src/__framework_prelude.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
// Note: While this is not public, it is still a breaking change to remove
44
// entries in here, since framework crates rely on it.
55

6-
pub use core::ffi::c_void;
7-
pub use core::marker::PhantomData;
8-
pub use core::ptr::NonNull;
9-
pub use std::os::raw::{
6+
pub use core::ffi::{
107
c_char, c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint,
11-
c_ulong, c_ulonglong, c_ushort,
8+
c_ulong, c_ulonglong, c_ushort, c_void,
129
};
10+
pub use core::marker::PhantomData;
11+
pub use core::ptr::NonNull;
1312

1413
pub use crate::encode::{Encode, Encoding, RefEncode};
1514
pub use crate::ffi::{NSInteger, NSIntegerMax, NSUInteger, NSUIntegerMax};

crates/objc2/src/__macro_helpers/cache.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use core::ffi::{c_char, c_void, CStr};
12
use core::ptr;
23
use core::str;
34
use core::sync::atomic::{AtomicPtr, Ordering};
4-
use std::ffi::CStr;
5-
use std::os::raw::{c_char, c_void};
65

76
use crate::ffi;
87
use crate::runtime::{AnyClass, Sel};

crates/objc2/src/__macro_helpers/declared_ivars.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,6 @@ pub(crate) unsafe fn get_initialized_ivar_ptr<T: DeclaredClass>(
422422
mod tests {
423423
use alloc::vec::Vec;
424424
use core::cell::Cell;
425-
use std::println;
426-
use std::sync::Mutex;
427425

428426
use super::*;
429427
use crate::rc::{Allocated, PartialInit, RcTestObject, Retained, ThreadTestData};
@@ -459,7 +457,10 @@ mod tests {
459457
}
460458

461459
#[test]
460+
#[cfg(feature = "std")]
462461
fn test_dealloc_and_dealloc_subclasses() {
462+
use std::sync::Mutex;
463+
463464
#[derive(Debug, PartialEq)]
464465
enum Operation {
465466
DropIvar,
@@ -674,7 +675,8 @@ mod tests {
674675
assert!(IvarZst::class().instance_variable(ivar_name).is_none());
675676

676677
let obj = unsafe { init(IvarZst::alloc()) };
677-
println!("{:?}", obj.ivars().get());
678+
#[cfg(feature = "std")]
679+
std::println!("{:?}", obj.ivars().get());
678680
obj.ivars().set(Ivar);
679681
}
680682

@@ -838,7 +840,8 @@ mod tests {
838840

839841
// Accessing superclass ivars is valid
840842
// SAFETY: Cell not accessed while ivar is borrowed
841-
println!("{:?}", unsafe { &*(**obj).ivars().as_ptr() });
843+
#[cfg(feature = "std")]
844+
std::println!("{:?}", unsafe { &*(**obj).ivars().as_ptr() });
842845

843846
drop(obj);
844847
expected.release += 1;
@@ -865,7 +868,8 @@ mod tests {
865868
);
866869

867870
let obj = unsafe { init_only_superclasses(InvalidAccess::alloc()) };
868-
println!("{:?}", obj.ivars());
871+
#[cfg(feature = "std")]
872+
std::println!("{:?}", obj.ivars());
869873
}
870874

871875
#[test]

crates/objc2/src/ffi/class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(non_camel_case_types)]
2-
use std::os::raw::{c_char, c_int, c_uint};
2+
use core::ffi::{c_char, c_int, c_uint};
33

44
use crate::runtime::{AnyClass, AnyProtocol, Bool, Imp, Method, Sel};
55
#[cfg(any(doc, not(feature = "unstable-objfw")))]

crates/objc2/src/ffi/constants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(non_camel_case_types)]
33

44
#[cfg(any(doc, target_vendor = "apple"))]
5-
use std::os::raw::c_int;
5+
use core::ffi::c_int;
66

77
use crate::runtime::{AnyClass, AnyObject};
88

crates/objc2/src/ffi/exception.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::runtime::AnyObject;
2020
type objc_exception_matcher = unsafe extern "C" fn(
2121
catch_type: *mut crate::runtime::AnyClass,
2222
exception: *mut AnyObject,
23-
) -> std::os::raw::c_int;
23+
) -> core::ffi::c_int;
2424

2525
/// Remember that this is non-null!
2626
#[cfg(any(
@@ -107,7 +107,7 @@ extern_c! {
107107
// present when building libobjc2.
108108
//
109109
// #[cfg(any(doc, feature = "gnustep-1-7"))]
110-
// pub fn objc_set_apple_compatible_objcxx_exceptions(newValue: std::os::raw::c_int) -> std::os::raw::c_int;
110+
// pub fn objc_set_apple_compatible_objcxx_exceptions(newValue: core::ffi::c_int) -> core::ffi::c_int;
111111

112112
#[cold]
113113
#[cfg(any(doc, all(target_vendor = "apple", not(all(target_os = "macos", target_arch = "x86")))))]

crates/objc2/src/ffi/method.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::os::raw::c_char;
1+
use core::ffi::c_char;
22
#[cfg(any(doc, not(feature = "unstable-objfw")))]
3-
use std::os::raw::c_uint;
3+
use core::ffi::c_uint;
44

55
use crate::runtime::{Imp, Method, Sel};
66

crates/objc2/src/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub(crate) type OpaqueData = UnsafeCell<PhantomData<(*const UnsafeCell<()>, Phan
314314
#[cfg(test)]
315315
mod tests {
316316
use super::*;
317-
use std::ffi::CStr;
317+
use core::ffi::CStr;
318318

319319
#[test]
320320
fn smoke() {

crates/objc2/src/ffi/object.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use core::ffi::c_char;
12
#[cfg(any(doc, not(feature = "unstable-objfw")))]
23
use core::ffi::c_void;
3-
use std::os::raw::c_char;
44

55
#[cfg(any(doc, not(feature = "unstable-objfw")))]
66
use crate::runtime::Ivar;

crates/objc2/src/ffi/property.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::os::raw::c_char;
1+
use core::ffi::c_char;
22
#[cfg(any(doc, not(feature = "unstable-objfw")))]
3-
use std::os::raw::c_uint;
3+
use core::ffi::c_uint;
44

55
use crate::ffi::OpaqueData;
66

crates/objc2/src/ffi/protocol.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::os::raw::c_char;
1+
use core::ffi::c_char;
22
#[cfg(any(doc, not(feature = "unstable-objfw")))]
3-
use std::os::raw::c_uint;
3+
use core::ffi::c_uint;
44

55
#[cfg(any(doc, not(feature = "unstable-objfw")))]
66
use crate::ffi::{objc_method_description, objc_property, objc_property_attribute_t};

crates/objc2/src/ffi/selector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os::raw::c_char;
1+
use core::ffi::c_char;
22

33
use crate::runtime::{Bool, Sel};
44

crates/objc2/src/ffi/various.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use core::ffi::c_void;
21
#[cfg(any(doc, not(feature = "unstable-objfw")))]
3-
use std::os::raw::c_char;
4-
use std::os::raw::c_int;
2+
use core::ffi::c_char;
3+
use core::ffi::c_int;
54
#[cfg(any(doc, target_vendor = "apple"))]
6-
use std::os::raw::c_uint;
5+
use core::ffi::c_uint;
6+
use core::ffi::c_void;
77

88
use crate::runtime::AnyObject;
99
use crate::runtime::Imp;

crates/objc2/src/macros/declare_class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
/// instance variables and methods, and implements the `NSCopying` protocol.
204204
///
205205
/// ```
206-
/// use std::os::raw::c_int;
206+
/// use std::ffi::c_int;
207207
///
208208
/// # use objc2::runtime::{NSObject, NSObjectProtocol, NSZone};
209209
/// # #[cfg(available_in_foundation)]

crates/objc2/src/macros/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ macro_rules! __class_inner {
702702
/// The recommended way of using this macro is by defining a wrapper function:
703703
///
704704
/// ```
705-
/// # use std::os::raw::{c_int, c_char};
705+
/// # use std::ffi::{c_int, c_char};
706706
/// # use objc2::msg_send;
707707
/// # use objc2::runtime::NSObject;
708708
/// unsafe fn do_something(obj: &NSObject, arg: c_int) -> *const c_char {

crates/objc2/src/main_thread_marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn is_main_thread() -> bool {
2020
// crate.
2121
#[cfg_attr(not(feature = "std"), link(name = "c", kind = "dylib"))]
2222
extern "C" {
23-
fn pthread_main_np() -> std::os::raw::c_int;
23+
fn pthread_main_np() -> core::ffi::c_int;
2424
}
2525

2626
// SAFETY: Can be called from any thread.

crates/objc2/src/runtime/__nsstring.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use core::ffi::c_char;
12
use core::slice;
23
use core::str;
3-
use std::os::raw::c_char;
44

55
use crate::ffi::NSUInteger;
66
use crate::msg_send;

crates/objc2/src/runtime/bool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mod inner {
5454
mod inner {
5555
// windows && !32bit-MinGW
5656
#[cfg(all(windows, not(all(target_pointer_width = "64", target_env = "gnu"))))]
57-
pub(crate) type BOOL = std::os::raw::c_int;
57+
pub(crate) type BOOL = core::ffi::c_int;
5858

5959
// The inverse
6060
#[cfg(not(all(windows, not(all(target_pointer_width = "64", target_env = "gnu")))))]

crates/objc2/src/runtime/declare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! # Dynamically creating classes and protocols.
2+
use alloc::ffi::CString;
23
use alloc::format;
34
use alloc::string::ToString;
45
use core::mem;
56
use core::mem::ManuallyDrop;
67
use core::ptr;
78
use core::ptr::NonNull;
8-
use std::ffi::CString;
99

1010
use crate::encode::{Encode, EncodeArguments, EncodeReturn, Encoding};
1111
use crate::ffi;

crates/objc2/src/runtime/malloc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! A minimal alternative to crates like `malloc_buf`, `mbox` and `malloced`.
2+
use core::ffi::c_char;
3+
use core::ffi::CStr;
24
use core::fmt;
35
use core::marker::PhantomData;
46
use core::ops::Deref;
57
use core::ptr::{self, NonNull};
68
use core::str;
79
use core::str::Utf8Error;
8-
use std::ffi::CStr;
9-
use std::os::raw::c_char;
1010

1111
use crate::ffi;
1212

crates/objc2/src/runtime/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
//! ```
1515
#![allow(clippy::missing_panics_doc)]
1616

17+
use alloc::ffi::CString;
1718
use alloc::vec::Vec;
19+
use core::ffi::c_char;
20+
use core::ffi::c_uint;
21+
use core::ffi::{c_void, CStr};
1822
use core::fmt;
1923
use core::hash;
2024
use core::panic::{RefUnwindSafe, UnwindSafe};
2125
use core::ptr::{self, NonNull};
2226
use core::str;
23-
use std::ffi::{c_void, CStr, CString};
24-
use std::os::raw::c_char;
25-
use std::os::raw::c_uint;
2627

2728
// Note: While this is not public, it is still a breaking change to remove,
2829
// since `objc2-foundation` relies on it.

crates/objc2/src/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use core::ffi::c_char;
12
use core::ops::Deref;
2-
use std::os::raw::c_char;
33
use std::sync::Once;
44

55
use crate::encode::{Encode, Encoding, RefEncode};

crates/tests/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
feature(repr_simd)
88
)]
99

10-
use std::os::raw::c_void;
10+
use core::ffi::c_void;
1111

1212
use block2::Block;
1313
extern crate alloc;

crates/tests/src/test_encode_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#![allow(non_snake_case)]
2+
use core::ffi::CStr;
3+
use core::ffi::*;
24
use core::fmt::Display;
35
use core::sync::atomic::{AtomicI32, AtomicPtr};
46
use objc2::ffi::{NSInteger, NSUInteger};
57
use objc2::runtime::{AnyClass, AnyObject, Bool, Sel};
68
use objc2::{Encode, Encoding};
79
use paste::paste;
8-
use std::ffi::CStr;
9-
use std::os::raw::*;
1010
use std::string::ToString;
1111

1212
use super::*;

crates/tests/src/test_object.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::missing_safety_doc)]
2+
use core::ffi::c_int;
23
use core::mem::{size_of, ManuallyDrop};
3-
use std::os::raw::c_int;
44

55
use objc2::encode::{Encoding, RefEncode};
66
use objc2::rc::{autoreleasepool, AutoreleasePool, Retained};

0 commit comments

Comments
 (0)