Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move block crate into this repo #18

Merged
merged 127 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
b496627
Added WIP block module.
SSheldon Dec 6, 2014
1cece3b
Added empty objc_test_utils crate.
SSheldon Dec 6, 2014
42a8f8a
Added a block test.
SSheldon Dec 6, 2014
5b6ea39
Remove debug print.
SSheldon Dec 6, 2014
046bb79
Fixed warnings for the latest rust.
SSheldon Dec 11, 2014
ad4f35c
Renamed Block to ConcreteBlock.
SSheldon Dec 21, 2014
d6ea817
Added new Block struct.
SSheldon Dec 21, 2014
1822be4
Added BlockArguments trait.
SSheldon Dec 21, 2014
993f5dd
Implemented BlockArguments for empty tuple.
SSheldon Dec 21, 2014
78c4a00
Implemented Message and a copy method for Block.
SSheldon Dec 21, 2014
7b94de2
Refactor ConcreteBlock to have a base Block.
SSheldon Dec 21, 2014
732b197
Made creating ConcreteBlocks safer.
SSheldon Dec 21, 2014
27c5aef
Implemented BlockArguments up to 12-tuple with a macro.
SSheldon Dec 23, 2014
9b0c3b4
Implemented Deref to Block for ConcreteBlock.
SSheldon Dec 23, 2014
45cadbd
Added more block tests.
SSheldon Dec 23, 2014
78a4852
Made block module public and added documentation.
SSheldon Dec 23, 2014
34b5bb4
Added crashing test.
SSheldon Dec 23, 2014
0e03246
Fixed a nasty bug in block_context_copy.
SSheldon Dec 23, 2014
0c2c447
Added ConcreteBlock clone test.
SSheldon Dec 23, 2014
4e26f33
Rearranged some test code.
SSheldon Dec 23, 2014
5d2a103
Replace a usage of transmute in ConcreteBlock.
SSheldon Dec 23, 2014
3573f2e
Stop leaking descriptors by cloning and dropping them.
SSheldon Dec 24, 2014
942de97
Relax some ConcreteBlock type bounds.
SSheldon Dec 25, 2014
f3119f3
Move self in copy method and only impl it for ConcreteBlocks.
SSheldon Dec 28, 2014
186a4cc
Remove Clone bound from ConcreteBlock.
SSheldon Dec 28, 2014
d6670ac
BlockDescriptor isn't specific to ConcreteBlock.
SSheldon Dec 28, 2014
e250b92
Replace into_string for the latest rust.
SSheldon Dec 28, 2014
32001d6
Dried up some block code using Self.
SSheldon Dec 28, 2014
8bd035a
Changed ConcreteBlock to use a generic closure.
SSheldon Dec 28, 2014
03a04fb
Implement Fn trait for blocks.
SSheldon Dec 28, 2014
d3579e8
Simplified ConcreteBlock declaration.
SSheldon Dec 29, 2014
052e479
Add back a comment for ConcreteBlock's new method.
SSheldon Dec 30, 2014
be61ff1
Calling a Block requires a mut reference.
SSheldon Dec 31, 2014
eec21a1
Removed Fn implementation for ConcreteBlock.
SSheldon Dec 31, 2014
57daad9
Updated for the latest rust.
SSheldon Jan 6, 2015
68d2a5d
Fixed most issues for the latest rust.
SSheldon Jan 10, 2015
c798cd8
Add argument and return types back to ConcreteBlock.
SSheldon Jan 10, 2015
481d374
Brought back the msg_send! macro with a comma.
SSheldon Jan 10, 2015
9a552ff
Fixed core tests for the latest rust.
SSheldon Jan 10, 2015
0677664
Replaced int with i32 in test_utils.
SSheldon Jan 10, 2015
679a8f6
Silence the remaining unstable warnings.
SSheldon Jan 10, 2015
05c17ed
Made Message trait require an unsafe impl.
SSheldon Jan 10, 2015
5104479
Added documentation and tests for test_utils.
SSheldon Jan 10, 2015
e609a10
Bump test_utils crate to 0.0.1 and add package metadata.
SSheldon Jan 11, 2015
b1efff8
Added license which crates.io now requires.
SSheldon Jan 11, 2015
bcb87e9
Converted trait bounds in core to use where clauses.
SSheldon Jan 14, 2015
d61568b
Removed unnecessary allow(unstable) from test_utils.
SSheldon Jan 17, 2015
2f7bf9f
Update core for msg_send using the MessageArguments trait.
SSheldon Jan 18, 2015
093ea64
Made Message require EncodePtr.
SSheldon Jan 18, 2015
e2be6b7
msg_send! macro verifies messages unless ndebug is set.
SSheldon Jan 18, 2015
efda935
Updated Fn trait for latest rust.
SSheldon Jan 30, 2015
a159a1b
Take advantage of autoderef where possible.
SSheldon Feb 1, 2015
a17ef73
Replaced use of unstable from_str.
SSheldon Feb 7, 2015
847aed1
Added IntoConcreteBlock trait to remove unboxed_closures feature.
SSheldon Feb 7, 2015
25345a4
Improve block module documentation.
SSheldon Feb 7, 2015
7fc4d69
Actually call the block in the doc example.
SSheldon Feb 7, 2015
0622f6d
Removed unnecessary closure annotations.
SSheldon Feb 7, 2015
f4842a2
Enabled doctests for core.
SSheldon Feb 7, 2015
d621f0f
Removed some trait bounds on blocks.
SSheldon Feb 10, 2015
d17a48b
Stop allowing improper_ctypes.
SSheldon Feb 10, 2015
a7a54f3
Missing copy implementations doesn't warn anymore.
SSheldon Feb 10, 2015
6a8656a
Added failing Block test.
SSheldon Feb 11, 2015
99d285b
Added a static bound for ConcreteBlock's copy.
SSheldon Feb 11, 2015
7c28aff
Created a test_utils module.
SSheldon Feb 14, 2015
59d8e46
Make the return type for IntoConcreteBlock an associated type.
SSheldon Feb 14, 2015
2f8c87f
Improved declare and block documentation.
SSheldon Feb 22, 2015
580ff1d
Don't ignore examples in doc tests.
SSheldon Feb 22, 2015
2ac205a
Updated test_utils to gcc 0.3.
SSheldon Feb 24, 2015
ee154d7
Bump test_utils crate to 0.0.2.
SSheldon Feb 24, 2015
2d4266d
Added a BlockBase struct so Block is 0-sized.
SSheldon Mar 3, 2015
9ae5059
Replaced the EncodePtr trait with a macro.
SSheldon Feb 18, 2015
313c0a5
Moved encode_message_impls! macro into the encode module.
SSheldon Mar 8, 2015
9949d59
Added config for Cargo and gitignore.
SSheldon Apr 17, 2015
e20aba1
Update block to compile as its own crate.
SSheldon Apr 17, 2015
6a82e83
Update tests for new crate.
SSheldon Apr 17, 2015
7831e10
Added README.
SSheldon Apr 17, 2015
fe901fe
Added more metadata and bumped to version 0.0.1.
SSheldon Apr 17, 2015
b41dc67
Don't link Foundation for objc_test_utils.
SSheldon Apr 17, 2015
9c5dee5
Change extension on block_utils from .m to .c.
SSheldon Apr 17, 2015
05004aa
Remove objc dependency.
SSheldon Apr 18, 2015
c93b6a1
Added documentation link to Cargo metadata.
SSheldon Apr 20, 2015
895e712
Removed unnecessary links in test utils.
SSheldon Apr 27, 2015
7b0fbcd
Removed unnecessary intermediate variable.
SSheldon Apr 30, 2015
4426ca1
Added documentation link to Cargo metadata.
SSheldon Apr 20, 2015
a5111e0
Replace objc's Id with the standalone objc_id crate.
SSheldon May 2, 2015
0c8b7a9
Bumped to version 0.0.2.
SSheldon May 2, 2015
e2b770e
Merged updates from release 0.0.2.
SSheldon May 2, 2015
9c28f61
Made BlockArguments::call_block unsafe.
SSheldon May 17, 2015
8d6da41
Calling a block is unsafe and doesn't require &mut.
SSheldon May 17, 2015
c485b40
Replaced IdBlock with RcBlock.
SSheldon May 17, 2015
00631d5
Updated some documentation.
SSheldon May 17, 2015
fc918f4
Added RcBlock documentation.
SSheldon May 17, 2015
13cafce
Updated README.
SSheldon May 17, 2015
a4cba0b
Bumped to version 0.1.0.
SSheldon May 17, 2015
5fd52e8
Fix nightly warnings related to lifetimes
frewsxcv Sep 2, 2015
bd10ada
Bumped to version 0.1.1.
SSheldon Sep 3, 2015
a1c5ef6
Add a Class type to fix the improper_ctypes warning.
SSheldon Oct 6, 2015
0267d5e
Bumped to version 0.1.2.
SSheldon Oct 6, 2015
45b644f
Updated libc dependency to allow 0.2.
SSheldon Nov 7, 2015
d79b428
Bumped to version 0.1.3.
SSheldon Nov 7, 2015
d3ff93d
Removed libc dependency by using std::os::raw types.
SSheldon Nov 12, 2015
b120714
Bumped to version 0.1.4.
SSheldon Nov 12, 2015
12109dc
Use explicit casts to silence warnings. Fixes #3.
jdm Mar 29, 2016
88b38f6
Move safe code out of an unsafe block.
SSheldon Apr 4, 2016
dd2da22
Bumped to version 0.1.5.
SSheldon Apr 4, 2016
e1ebad9
Added travis config.
SSheldon May 8, 2016
8868a8b
Extracted test code to a test_utils module.
SSheldon May 8, 2016
b4cb376
Add rust-tests-ios support.
SSheldon May 8, 2016
e7b6650
Added scripts for running rust-test-ios on travis.
SSheldon May 8, 2016
a5767ce
Change travis config to run the scripts.
SSheldon May 8, 2016
1499799
Add support for Linux.
SSheldon May 8, 2016
4717879
Bumped to version 0.1.6.
SSheldon May 8, 2016
fb2fbf4
Remove libdispatch-dev package for travis.
SSheldon May 9, 2016
d14ade0
Update iOS stdlib to install over https.
SSheldon Jun 19, 2016
4fda032
Use rustup rather than installing iOS stdlibs manually
SSheldon Jun 9, 2017
642ea4a
Fix markdown warning.
waywardmonkeys Jan 26, 2018
e03b827
Merge `block` from https://github.com/SSheldon/rust-block
madsmtm Sep 2, 2021
8a4c403
Move `block` crate to subdirectory
madsmtm Sep 2, 2021
ce5a9bf
Run `cargo fmt`
madsmtm Sep 2, 2021
3868950
Move objc_test_utils stuff to match normal crate structure
madsmtm Sep 2, 2021
d8e1c60
Update test_utils to use `cc` rather than `gcc`.
waywardmonkeys Jan 26, 2018
b6438c7
Fix warnings
madsmtm Sep 2, 2021
3f580b4
Update objc_block to 2018 edition
madsmtm Sep 2, 2021
bbf3a4e
Implement RefEncode for Block and ConcreteBlock
madsmtm Sep 2, 2021
2e71917
Make objc_block closer to no_std
madsmtm Sep 2, 2021
4c453dd
Don't depend on objc in objc_encode
madsmtm Sep 2, 2021
50704af
Run CI on objc_foundation/block feature
madsmtm Sep 2, 2021
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
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- name: Install Packages
if: contains(matrix.platform.os, 'ubuntu')
run: sudo apt-get install gobjc clang make
run: sudo apt-get install gobjc clang make libblocksruntime-dev

- name: Install different Rust toolchain
# A default toolchain is already installed
Expand Down Expand Up @@ -120,12 +120,11 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
# TODO: `objc_foundation/block` feature doesn't work
args: --verbose --no-fail-fast --no-default-features

- name: Test w. exception and verify_message features
- name: Test with features
uses: actions-rs/cargo@v1
with:
command: test
# TODO: `objc_foundation/block` feature doesn't work
args: --verbose --no-fail-fast --no-default-features --features exception,verify_message
# Not using --all-features because some features are nightly-only
args: --verbose --no-fail-fast --features block,exception,verify_message
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[workspace]
members = [
"objc",
"objc_block",
"objc_encode",
"objc_exception",
"objc_foundation",
"objc_foundation_derive",
"objc_id",
"objc_test_utils",
]
exclude = ["objc/tests-ios"]
6 changes: 4 additions & 2 deletions objc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ The bindings can be used on Linux or *BSD utilizing the
*/

#![no_std]
#![cfg_attr(feature = "unstable_autoreleasesafe", feature(negative_impls, auto_traits))]

#![cfg_attr(
feature = "unstable_autoreleasesafe",
feature(negative_impls, auto_traits)
)]
#![warn(missing_docs)]
#![allow(clippy::missing_safety_doc)]
// Update in Cargo.toml as well.
Expand Down
10 changes: 8 additions & 2 deletions objc/src/rc/autorelease.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ffi::c_void;
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
use std::{cell::RefCell, vec::Vec, thread_local};
use std::{cell::RefCell, thread_local, vec::Vec};

use crate::runtime::{objc_autoreleasePoolPop, objc_autoreleasePoolPush};

Expand Down Expand Up @@ -81,6 +81,7 @@ impl AutoreleasePool {
all(debug_assertions, not(feature = "unstable_autoreleasesafe")),
inline
)]
#[allow(clippy::needless_lifetimes)]
pub unsafe fn ptr_as_ref<'p, T>(&'p self, ptr: *const T) -> &'p T {
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
POOLS.with(|c| {
Expand Down Expand Up @@ -110,6 +111,8 @@ impl AutoreleasePool {
all(debug_assertions, not(feature = "unstable_autoreleasesafe")),
inline
)]
#[allow(clippy::needless_lifetimes)]
#[allow(clippy::mut_from_ref)]
pub unsafe fn ptr_as_mut<'p, T>(&'p self, ptr: *mut T) -> &'p mut T {
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
POOLS.with(|c| {
Expand Down Expand Up @@ -265,7 +268,10 @@ impl !AutoreleaseSafe for AutoreleasePool {}
/// inner pool:
///
#[cfg_attr(feature = "unstable_autoreleasesafe", doc = "```rust,compile_fail")]
#[cfg_attr(not(feature = "unstable_autoreleasesafe"), doc = "```rust,should_panic")]
#[cfg_attr(
not(feature = "unstable_autoreleasesafe"),
doc = "```rust,should_panic"
)]
/// # use objc::{class, msg_send};
/// # use objc::rc::{autoreleasepool, AutoreleasePool};
/// # use objc::runtime::Object;
Expand Down
27 changes: 27 additions & 0 deletions objc_block/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "block"
version = "0.1.6"
authors = ["Steven Sheldon", "Mads Marquart <mads@marquart.dk>"]
edition = "2018"

description = "Interface for Apple's C language extension of blocks."
keywords = ["objective-c", "macos", "ios", "blocks"]
categories = [
"api-bindings",
"development-tools::ffi",
"os::macos-apis",
]
readme = "README.md"
repository = "https://github.com/madsmtm/objc"
documentation = "https://docs.rs/block/"
license = "MIT"

exclude = [
"tests-ios/**",
]

[dependencies]
objc-encode = { path = "../objc_encode", version = "1.1.0" }

[dev-dependencies]
objc_test_utils = { path = "../objc_test_utils", version = "0.0" }
49 changes: 49 additions & 0 deletions objc_block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# `block`

[![Latest version](https://badgen.net/crates/v/block)](https://crates.io/crates/block)
[![License](https://badgen.net/badge/license/MIT/blue)](../LICENSE.txt)
[![Documentation](https://docs.rs/block/badge.svg)](https://docs.rs/block/)
[![CI Status](https://github.com/madsmtm/objc/workflows/CI/badge.svg)](https://github.com/madsmtm/objc/actions)

Rust interface for Apple's C language extension of blocks.

For more information on the specifics of the block implementation, see
Clang's documentation: http://clang.llvm.org/docs/Block-ABI-Apple.html

## Invoking blocks

The `Block` struct is used for invoking blocks from Objective-C. For example,
consider this Objective-C function:

``` objc
int32_t sum(int32_t (^block)(int32_t, int32_t)) {
return block(5, 8);
}
```

We could write it in Rust as the following:

``` rust
unsafe fn sum(block: &Block<(i32, i32), i32>) -> i32 {
block.call((5, 8))
}
```

Note the extra parentheses in the `call` method, since the arguments must be
passed as a tuple.

## Creating blocks

Creating a block to pass to Objective-C can be done with the `ConcreteBlock`
struct. For example, to create a block that adds two `i32`s, we could write:

``` rust
let block = ConcreteBlock::new(|a: i32, b: i32| a + b);
let block = block.copy();
assert!(unsafe { block.call((5, 8)) } == 13);
```

It is important to copy your block to the heap (with the `copy` method) before
passing it to Objective-C; this is because our `ConcreteBlock` is only meant
to be copied once, and we can enforce this in Rust, but if Objective-C code
were to copy it twice we could have a double free.
Loading