-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "test_out_parameters" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
path = "lib.rs" | ||
|
||
[dependencies] | ||
objc2 = { path = "../../../objc2", default-features = false } | ||
|
||
[features] | ||
default = ["apple", "std"] | ||
std = ["objc2/std"] | ||
# Runtime | ||
apple = ["objc2/apple"] | ||
gnustep-1-7 = ["objc2/gnustep-1-7"] | ||
gnustep-1-8 = ["gnustep-1-7", "objc2/gnustep-1-8"] | ||
gnustep-1-9 = ["gnustep-1-8", "objc2/gnustep-1-9"] | ||
gnustep-2-0 = ["gnustep-1-9", "objc2/gnustep-2-0"] | ||
gnustep-2-1 = ["gnustep-2-0", "objc2/gnustep-2-1"] | ||
|
||
# Hack | ||
assembly-features = [] |
82 changes: 82 additions & 0 deletions
82
test-assembly/crates/test_out_parameters/expected/apple-x86_64.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
.section __TEXT,__text,regular,pure_instructions | ||
.intel_syntax noprefix | ||
.globl _null | ||
.p2align 4, 0x90 | ||
_null: | ||
push rbp | ||
mov rbp, rsp | ||
push rbx | ||
push rax | ||
mov qword ptr [rbp - 16], 0 | ||
lea rdx, [rbp - 16] | ||
call _objc_msgSend | ||
mov rbx, rax | ||
mov rdi, qword ptr [rbp - 16] | ||
call _objc_retain | ||
mov rdx, rax | ||
mov rax, rbx | ||
add rsp, 8 | ||
pop rbx | ||
pop rbp | ||
ret | ||
|
||
.globl _nonnull | ||
.p2align 4, 0x90 | ||
_nonnull: | ||
push rbp | ||
mov rbp, rsp | ||
push r15 | ||
push r14 | ||
push rbx | ||
push rax | ||
mov rbx, rdx | ||
mov qword ptr [rbp - 32], rdx | ||
lea rdx, [rbp - 32] | ||
call _objc_msgSend | ||
mov r14, rax | ||
mov rdi, qword ptr [rbp - 32] | ||
call _objc_retain | ||
mov r15, rax | ||
mov rdi, rbx | ||
call _objc_release | ||
mov rax, r14 | ||
mov rdx, r15 | ||
add rsp, 8 | ||
pop rbx | ||
pop r14 | ||
pop r15 | ||
pop rbp | ||
ret | ||
|
||
.globl _generic | ||
.p2align 4, 0x90 | ||
_generic: | ||
push rbp | ||
mov rbp, rsp | ||
push r15 | ||
push r14 | ||
push rbx | ||
push rax | ||
mov rbx, rdx | ||
mov qword ptr [rbp - 32], rdx | ||
lea rdx, [rbp - 32] | ||
call _objc_msgSend | ||
mov r14, rax | ||
mov rdi, qword ptr [rbp - 32] | ||
call _objc_retain | ||
mov r15, rax | ||
test rbx, rbx | ||
je LBB2_2 | ||
mov rdi, rbx | ||
call _objc_release | ||
LBB2_2: | ||
mov rax, r14 | ||
mov rdx, r15 | ||
add rsp, 8 | ||
pop rbx | ||
pop r14 | ||
pop r15 | ||
pop rbp | ||
ret | ||
|
||
.subsections_via_symbols |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//! Test that Id::writeback does the correct thing. | ||
//! | ||
//! Note that without `panic = "abort"`, this generates a lot more code to | ||
//! ensure that if the message send panics, the `param` (whether it has been | ||
//! overwritten yet or not) is still released. | ||
use objc2::ffi::NSInteger; | ||
use objc2::rc::{Id, Owned}; | ||
use objc2::runtime::{Object, Sel}; | ||
use objc2::MessageReceiver; | ||
|
||
unsafe fn handle(obj: &Object, sel: Sel, param: &mut *mut Object) -> NSInteger { | ||
MessageReceiver::send_message(obj, sel, (param,)) | ||
} | ||
|
||
type Res = (NSInteger, Option<Id<Object, Owned>>); | ||
|
||
#[no_mangle] | ||
unsafe fn null(obj: &Object, sel: Sel) -> Res { | ||
let mut param = None; | ||
let res = Id::writeback(&mut param, |param| handle(obj, sel, param)); | ||
(res, param) | ||
} | ||
|
||
#[no_mangle] | ||
unsafe fn nonnull(obj: &Object, sel: Sel, param: Id<Object, Owned>) -> Res { | ||
let mut param = Some(param); | ||
let res = Id::writeback(&mut param, |param| handle(obj, sel, param)); | ||
(res, param) | ||
} | ||
|
||
#[no_mangle] | ||
unsafe fn generic(obj: &Object, sel: Sel, mut param: Option<Id<Object, Owned>>) -> Res { | ||
let res = Id::writeback(&mut param, |param| handle(obj, sel, param)); | ||
(res, param) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters