Skip to content

Commit

Permalink
Add explicit return types for msg_send! calls
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksijuvani committed Aug 7, 2019
1 parent cbf920c commit 032800f
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/argument-buffer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ fn main() {
println!("{:?}", sampler);

unsafe {
msg_send![pool, release];
let () = msg_send![pool, release];
}
}
2 changes: 1 addition & 1 deletion examples/bind/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ fn main() {
println!("Everything is bound");

unsafe {
msg_send![pool, release];
let () = msg_send![pool, release];
}
}
2 changes: 1 addition & 1 deletion examples/compute/compute-argument-buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ fn main() {

unsafe {
assert_eq!(465, *ptr);
msg_send![pool, release];
let () = msg_send![pool, release];
}
}
4 changes: 3 additions & 1 deletion examples/compute/embedded-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ fn main() {
println!("Function type: {:?}", kernel.function_type());
println!("OK");

unsafe { msg_send![pool, release] }
unsafe {
let () = msg_send![pool, release];
}
}
2 changes: 1 addition & 1 deletion examples/compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ fn main() {

unsafe {
assert_eq!(465, *ptr);
msg_send![pool, release];
let () = msg_send![pool, release];
}
}
2 changes: 1 addition & 1 deletion examples/reflection/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ fn main() {
};

unsafe {
msg_send![pool, release];
let () = msg_send![pool, release];
}
}
2 changes: 1 addition & 1 deletion examples/window/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn main() {
r += 0.01f32;
//let _: () = msg_send![command_queue.0, _submitAvailableCommandBuffers];
unsafe {
msg_send![pool, release];
let () = msg_send![pool, release];
pool = NSAutoreleasePool::new(cocoa::base::nil);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/capturemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ foreign_obj_type! {
impl CaptureScopeRef {
pub fn begin_scope(&self) {
unsafe {
msg_send![self, beginScope];
msg_send![self, beginScope]
}
}

pub fn end_scope(&self) {
unsafe {
msg_send![self, endScope];
msg_send![self, endScope]
}
}

Expand Down Expand Up @@ -75,25 +75,25 @@ impl CaptureManagerRef {

pub fn start_capture_with_device(&self, device: &DeviceRef) {
unsafe {
msg_send![self, startCaptureWithDevice: device];
msg_send![self, startCaptureWithDevice: device]
}
}

pub fn start_capture_with_command_queue(&self, command_queue: &CommandQueueRef) {
unsafe {
msg_send![self, startCaptureWithCommandQueue: command_queue];
msg_send![self, startCaptureWithCommandQueue: command_queue]
}
}

pub fn start_capture_with_scope(&self, scope: &CaptureScopeRef) {
unsafe {
msg_send![self, startCaptureWithScope: scope];
msg_send![self, startCaptureWithScope: scope]
}
}

pub fn stop_capture(&self) {
unsafe {
msg_send![self, stopCapture];
msg_send![self, stopCapture]
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commandbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl CommandBufferRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commandqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl CommandQueueRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ impl Device {
let ret = (0..count)
.map(|i| msg_send![array, objectAtIndex: i])
.collect();
msg_send![array, release];
let () = msg_send![array, release];
ret
}
}
Expand Down Expand Up @@ -1530,13 +1530,13 @@ impl DeviceRef {
let library: *mut MTLLibrary = msg_send![self, newLibraryWithSource:source
options:options
error:&mut err];
msg_send![source, release];
let () = msg_send![source, release];
if !err.is_null() {
let desc: *mut Object = msg_send![err, localizedDescription];
let compile_error: *const std::os::raw::c_char = msg_send![desc, UTF8String];
let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned();
if library.is_null() {
msg_send![err, release];
let () = msg_send![err, release];
return Err(message);
} else {
warn!("Shader warnings: {}", message);
Expand Down
4 changes: 2 additions & 2 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ impl CommandEncoderRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}

pub fn end_encoding(&self) {
unsafe {
msg_send![self, endEncoding];
msg_send![self, endEncoding]
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ impl HeapDescriptorRef {
}

pub fn set_size(&self, size: NSUInteger) {
unsafe {
msg_send![self, setSize: size];
}
unsafe { msg_send![self, setSize: size] }
}
}
28 changes: 12 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ use std::borrow::{Borrow, ToOwned};
use std::marker::PhantomData;
use std::mem;
use std::ops::Deref;
use std::os::raw::c_void;

use core_graphics::base::CGFloat;
use core_graphics::geometry::CGSize;
use foreign_types::ForeignType;
use objc::runtime::{Object, NO, YES};
use cocoa::foundation::NSUInteger;

fn nsstring_as_str(nsstr: &objc::runtime::Object) -> &str {
let bytes = unsafe {
let bytes: *const std::os::raw::c_char = msg_send![nsstr, UTF8String];
bytes as *const u8
};
let len = unsafe { msg_send![nsstr, length] };
let len: NSUInteger = unsafe { msg_send![nsstr, length] };
unsafe {
let bytes = std::slice::from_raw_parts(bytes, len);
let bytes = std::slice::from_raw_parts(bytes, len as usize);
std::str::from_utf8(bytes).unwrap()
}
}
Expand All @@ -43,13 +45,13 @@ fn nsstring_from_str(string: &str) -> *mut objc::runtime::Object {
const UTF8_ENCODING: usize = 4;

let cls = class!(NSString);
let bytes = string.as_ptr() as *const std::os::raw::c_void;
let bytes = string.as_ptr() as *const c_void;
unsafe {
let obj: *mut objc::runtime::Object = msg_send![cls, alloc];
let obj: *mut objc::runtime::Object = msg_send![obj, initWithBytes:bytes
length:string.len()
encoding:UTF8_ENCODING];
msg_send![obj, autorelease];
let _: *mut c_void = msg_send![obj, autorelease];
obj
}
}
Expand Down Expand Up @@ -119,7 +121,7 @@ macro_rules! try_objc {
let desc: *mut Object = msg_send![$err_name, localizedDescription];
let compile_error: *const std::os::raw::c_char = msg_send![desc, UTF8String];
let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned();
msg_send![$err_name, release];
let () = msg_send![$err_name, release];
return Err(message);
}
value
Expand Down Expand Up @@ -147,7 +149,7 @@ where
{
fn drop(&mut self) {
unsafe {
msg_send![self.0, release];
let () = msg_send![self.0, release];
}
}
}
Expand Down Expand Up @@ -318,9 +320,7 @@ impl CoreAnimationLayerRef {
}

pub fn set_presents_with_transaction(&self, transaction: bool) {
unsafe {
msg_send![self, setPresentsWithTransaction: transaction];
}
unsafe { msg_send![self, setPresentsWithTransaction: transaction] }
}

pub fn set_edge_antialiasing_mask(&self, mask: u64) {
Expand All @@ -332,19 +332,15 @@ impl CoreAnimationLayerRef {
}

pub fn remove_all_animations(&self) {
unsafe {
msg_send![self, removeAllAnimations];
}
unsafe { msg_send![self, removeAllAnimations] }
}

pub fn next_drawable(&self) -> Option<&CoreAnimationDrawableRef> {
unsafe { msg_send![self, nextDrawable] }
}

pub fn set_contents_scale(&self, scale: CGFloat) {
unsafe {
msg_send![self, setContentsScale: scale];
}
unsafe { msg_send![self, setContentsScale: scale] }
}
}

Expand Down Expand Up @@ -390,7 +386,7 @@ pub use vertexdescriptor::*;

#[inline]
unsafe fn obj_drop<T>(p: *mut T) {
msg_send![(p as *mut Object), release];
msg_send![(p as *mut Object), release]
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl LibraryRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl ComputePipelineDescriptorRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel]
let () = msg_send![self, setLabel: nslabel];
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ impl ComputePipelineStateRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl RenderPipelineDescriptorRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}

Expand Down Expand Up @@ -378,7 +378,7 @@ impl RenderPipelineStateRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/renderpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ impl RenderPassAttachmentDescriptorRef {
}

pub fn set_texture(&self, texture: Option<&TextureRef>) {
unsafe {
msg_send![self, setTexture: texture];
}
unsafe { msg_send![self, setTexture: texture] }
}

pub fn level(&self) -> NSUInteger {
Expand Down
2 changes: 1 addition & 1 deletion src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl ResourceRef {
pub fn set_label(&self, label: &str) {
unsafe {
let nslabel = crate::nsstring_from_str(label);
msg_send![self, setLabel: nslabel];
let () = msg_send![self, setLabel: nslabel];
}
}

Expand Down

0 comments on commit 032800f

Please sign in to comment.