Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/objc2/src/__macros/msg_send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ pub use self::retained::*;
/// ```ignore
/// use objc2_foundation::{NSNumber, NSString, NSURLComponents};
///
/// let components = unsafe { NSURLComponents::new() };
/// unsafe { components.setPort(Some(&NSNumber::new_i32(8080))) };
/// unsafe { components.setHost(Some(&NSString::from_str("example.com"))) };
/// unsafe { components.setScheme(Some(&NSString::from_str("http"))) };
/// let string = unsafe { components.string() };
/// let components = NSURLComponents::new();
/// components.setPort(Some(&NSNumber::new_i32(8080)));
/// components.setHost(Some(&NSString::from_str("example.com")));
/// components.setScheme(Some(&NSString::from_str("http")));
/// let string = components.string();
///
/// assert_eq!(string.unwrap().to_string(), "http://example.com:8080");
/// ```
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2/src/topics/FRAMEWORKS_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `OpenGLES` / `objc2-open-gl-es`.
- `XCTest` / `objc2-xc-test`.
- `XCUIAutomation` / `objc2-xc-ui-automation`.
* Automatically marked a bunch of functions safe in:
- `Foundation` / `objc2-foundation`.

### Changed
* Updated SDK from Xcode 16.3 to 26.0.
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/topics/run_loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ In non-graphical applications, you get the thread's current `NSRunLoop`, and run
use objc2_foundation::{NSDate, NSDefaultRunLoopMode, NSRunLoop};

fn main() {
let run_loop = unsafe { NSRunLoop::currentRunLoop() };
let run_loop = NSRunLoop::currentRunLoop();

// Set up timers, sources, etc.

let mut date = unsafe { NSDate::now() };
let mut date = NSDate::now();
// Run for roughly 10 seconds
for i in 0..10 {
date = unsafe { date.dateByAddingTimeInterval(1.0) };
Expand Down
4 changes: 2 additions & 2 deletions crates/tests/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn merge_objc_symbols(exc: &NSException) -> Vec<String> {
// demangled symbols.
let mut demangled_symbols = vec![];

let nssymbols = unsafe { exc.callStackSymbols() };
let return_addrs = unsafe { exc.callStackReturnAddresses() };
let nssymbols = exc.callStackSymbols();
let return_addrs = exc.callStackReturnAddresses();

for (nssymbol, addr) in nssymbols.iter().zip(return_addrs) {
let addr = addr.as_usize() as *mut c_void;
Expand Down
11 changes: 11 additions & 0 deletions crates/tests/src/enumerator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use objc2_foundation::{NSEnumerator, NSObject};

// We mark `new` safe, but it actually panics.
#[test]
#[cfg_attr(not(feature = "catch-all"), ignore = "aborts the test")]
#[should_panic = "NSInvalidArgumentException"]
fn empty() {
let enumerator = NSEnumerator::<NSObject>::new();
// *** -[NSEnumerator nextObject]: method sent to an instance (0xcafebabe) of an abstract class. Create a concrete instance!
assert_eq!(enumerator.iter().count(), 0);
}
2 changes: 2 additions & 0 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ extern crate std;
mod backtrace;
#[cfg(test)]
mod block;
#[cfg(test)]
mod enumerator;
#[cfg(all(test, feature = "exception"))]
mod exception;
mod rc_test_object;
Expand Down
3 changes: 2 additions & 1 deletion examples/app/default_xcode_app/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ define_class!(
let mtm = self.mtm();
let view_controller = ViewController::new(mtm);

let app = unsafe { notification.object() }
let app = notification
.object()
.unwrap()
.downcast::<NSApplication>()
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion examples/app/hello_world_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ define_class!(
fn did_finish_launching(&self, notification: &NSNotification) {
let mtm = self.mtm();

let app = unsafe { notification.object() }
let app = notification
.object()
.unwrap()
.downcast::<NSApplication>()
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion examples/metal/default_xcode_game/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ define_class!(
let mtm = self.mtm();
let view_controller = GameViewController::new(mtm);

let app = unsafe { notification.object() }
let app = notification
.object()
.unwrap()
.downcast::<NSApplication>()
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/metal/default_xcode_game/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Renderer {

let vertex_buffers = unsafe { self.ivars().mesh.vertexBuffers() };
for (i, vertex_buffer) in vertex_buffers.into_iter().enumerate() {
if **vertex_buffer == **unsafe { NSNull::null() } {
if **vertex_buffer == **NSNull::null() {
eprintln!("got null vertex_buffer");
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/metal/triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ define_class!(

// compute the scene properties
let scene_properties_data = &SceneProperties {
time: unsafe { self.ivars().start_date.timeIntervalSinceNow() } as f32,
time: self.ivars().start_date.timeIntervalSinceNow() as f32,
};
// write the scene properties to the vertex shader argument buffer at index 0
let scene_properties_bytes = NonNull::from(scene_properties_data);
Expand Down Expand Up @@ -280,7 +280,7 @@ impl Delegate {
fn new(mtm: MainThreadMarker) -> Retained<Self> {
let this = Self::alloc(mtm);
let this = this.set_ivars(Ivars {
start_date: unsafe { NSDate::now() },
start_date: NSDate::now(),
command_queue: OnceCell::default(),
pipeline_state: OnceCell::default(),
#[cfg(target_os = "macos")]
Expand Down
6 changes: 3 additions & 3 deletions framework-crates/objc2-foundation/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ mod tests {
for case in cases {
let point_a = NSPoint::new(case.0, case.1);
let point_b = NSPoint::new(case.0, case.1);
let actual = unsafe { NSEqualPoints(point_a, point_b) };
let actual = NSEqualPoints(point_a, point_b);
assert_eq!(point_a == point_b, actual);

if case.0 >= 0.0 && case.1 >= 0.0 {
let size_a = NSSize::new(case.0, case.1);
let size_b = NSSize::new(case.0, case.1);
let actual = unsafe { NSEqualSizes(size_a, size_b) };
let actual = NSEqualSizes(size_a, size_b);
assert_eq!(size_a == size_b, actual);

let rect_a = NSRect::new(point_a, size_a);
let rect_b = NSRect::new(point_b, size_b);
let actual = unsafe { NSEqualRects(rect_a, rect_b) };
let actual = NSEqualRects(rect_a, rect_b);
assert_eq!(rect_a == rect_b, actual);
}
}
Expand Down
4 changes: 2 additions & 2 deletions framework-crates/objc2-foundation/src/tests/decimal_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ fn test_decimal_encoding() {
_mantissa: [0; 8],
};

let obj = unsafe { NSDecimalNumber::initWithDecimal(NSDecimalNumber::alloc(), decimal) };
assert_eq!(decimal, unsafe { obj.decimalValue() });
let obj = NSDecimalNumber::initWithDecimal(NSDecimalNumber::alloc(), decimal);
assert_eq!(decimal, obj.decimalValue());
}
1 change: 1 addition & 0 deletions framework-crates/objc2-foundation/src/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{NSLock, NSLocking};
#[test]
fn lock_unlock() {
let lock = NSLock::new();
// SAFETY: Unlocked from the same thread that locked.
unsafe {
lock.lock();
assert!(!lock.tryLock());
Expand Down
2 changes: 1 addition & 1 deletion framework-crates/objc2-foundation/src/tests/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ use crate::{NSMeasurement, NSUnitMass, NSUnitPower};

#[test]
fn create() {
let mass = unsafe { NSMeasurement::<NSUnitMass>::new() };
let mass = NSMeasurement::<NSUnitMass>::new();
let _power = unsafe { mass.cast_unchecked::<NSUnitPower>() };
}
2 changes: 1 addition & 1 deletion framework-crates/objc2-foundation/src/tests/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fn class_cluster_and_wait_method() {
let method = NSTask::class().instance_method(sel);
assert!(method.is_none(), "class does not have method");

let task = unsafe { NSTask::new() };
let task = NSTask::new();
assert!(task.respondsToSelector(sel), "object has method");
}
10 changes: 4 additions & 6 deletions framework-crates/objc2-foundation/src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const PATH_MAX: usize = 1024;

/// [`Path`] conversion.
impl NSURL {
// FIXME(breaking): Make this private.
pub fn from_path(
path: &Path,
is_directory: bool,
Expand Down Expand Up @@ -228,19 +229,16 @@ mod tests {
fn special_paths() {
use crate::{NSData, NSFileManager};

let manager = unsafe { NSFileManager::defaultManager() };
let manager = NSFileManager::defaultManager();

let path = Path::new(OsStr::from_bytes(b"\xf8"));
// Foundation is broken, needs a different encoding to work.
let url = NSURL::from_file_path("%F8").unwrap();

// Create, read and remove file, using different APIs.
fs::write(path, "").unwrap();
assert_eq!(
unsafe { NSData::dataWithContentsOfURL(&url) },
Some(NSData::new())
);
unsafe { manager.removeItemAtURL_error(&url).unwrap() };
assert_eq!(NSData::dataWithContentsOfURL(&url), Some(NSData::new()));
manager.removeItemAtURL_error(&url).unwrap();
}

// Useful when testing HFS+ and non-UTF-8:
Expand Down
Loading