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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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")))]

0 commit comments

Comments
 (0)