Test 64-bit NSNumbers
on macOS 10.15.5 Beta the property list tests fails, because dictionary serializes a 32-bit NSNumber, but property list deserializes it to a 64-bit NSNumber. Apparently, they make dictionaries not equal, even though numeric value is the same!
Here's a workaround that forces the NSNumber to be 64-bit.
feat: added bindings to NSUserDefaults
I have added bindings for [`NSUserDefaults`](https://developer.apple.com/documentation/foundation/nsuserdefaults). It is used in macOS for storing state, but it may also be used read/write state which is already set by the system. One example could be that an application would like to overwrite `CGFontRenderingFontSmoothingDisabled` for enabling sub-pixel antialiasing on > 10.14.
Let me know if I can improve anything.
Change CFMutableAttributedString::set_attribute argument type
Type of the argument `value` can be a reference as opposed to requiring the value's ownership.
Support to create CGContext from existing ptr
Add `CGContextRetain` and `CGContextRelease`
Add function to create CGContext from existing ::sys::CGContextRef pointer
Add missing APIs to CTLine
Added the following missing APIs to [CTLine](https://developer.apple.com/documentation/coretext/ctline):
- CTLineDraw
- CTLineGetImageBounds
- CTLineGetStringIndexForPosition
- CTLineGetOffsetForStringIndex
Added `CGContextSetTextPosition` to `CGContext`.
Added `CGTextFillStrokeClip` to `CGTextDrawingMode`.
Fix for link error - undefined CFMutableAttributedStringGetTypeID
## Intention
Fix for https://github.com/rust-lang/rust/issues/63047 and https://github.com/intellij-rust/intellij-rust/issues/4605
## How to reproduce
The following program fails to compile:
```rust
use core_foundation::attributed_string::{CFAttributedString, CFMutableAttributedString};
use core_foundation::base::TCFType;
fn main() {
dbg!(<CFAttributedString as TCFType>::type_id());
dbg!(<CFMutableAttributedString as TCFType>::type_id());
}
```
```
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-m64" "-L" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.198s3ihm7i58x886.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.29tmhebao6ewa0ll.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.2d9bu5z2mybg821y.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.47seajd45h5x4xvx.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.4m5r63z1bomeava7.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.dyb0rm2k46lhkz1.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.ux6g43y1awzd3xm.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.ysgemo5b5rzmi6m.rcgu.o" "-o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.25q0sul7ku3gti43.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps" "-L" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/libcore_foundation-3b681be94f15488f.rlib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/liblibc-e84db2977ac0591b.rlib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/libcore_foundation_sys-2e4eeadb22527df2.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-c9ffd87d7c2bccdf.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-b6d1e628327abbae.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-760b1a8bb4bcc351.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-1660704e36532385.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace-c11c21cbed796daf.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace_sys-6c38e3c045a3a71f.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-5bfb7cde712ed2a9.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-4540ebf06eb7e37e.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-0a35227c3d306cf2.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-c976a950e872076f.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-ef822b0e650993e5.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-172ea43efe468d24.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-4d87cbd247e9505f.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-3943751ba8f04dce.rlib" "-framework" "CoreFoundation" "-lSystem" "-lresolv" "-lc" "-lm"
= note: Undefined symbols for architecture x86_64:
"_CFMutableAttributedStringGetTypeID", referenced from:
_$LT$core_foundation..attributed_string..CFMutableAttributedString$u20$as$u20$core_foundation..base..TCFType$GT$::type_id::h9f6f71bdd347aca0 in foo-cef9f22f855ec251.198s3ihm7i58x886.rcgu.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
```
## Root cause
Core Foundation framework does not have `CFMutableAttributedStringGetTypeID()` function.
1. Documentation of [CFMutableAttributedString](https://developer.apple.com/documentation/corefoundation/cfmutableattributedstring-rqp) does not have function `CFMutableAttributedStringGetTypeID()` listed.
2. Documentation of [CFAttributedString](https://developer.apple.com/documentation/corefoundation/cfattributedstring-s1s) says that there is function `CFAttributedStringGetTypeID()` available (without word "Mutable").
3. Documentation of [CFAttributedStringGetTypeID()](https://developer.apple.com/documentation/corefoundation/1541715-cfattributedstringgettypeid) says the following:
> CFMutableAttributedString objects have the same type identifier as CFAttributedString objects.
4. As a double check - there is no `CFMutableAttributedStringGetTypeID()` function in C/C++ headers on MacOS, but `CFAttributedStringGetTypeID()` is available. C/C++ test program (similar to Rust above) does not compile as well.
So, `CFAttributedStringGetTypeID()` must be used instead of `CFMutableAttributedStringGetTypeID()`
## Solution
1. In `core-foundation-sys`: Remove `extern CFMutableAttributedStringGetTypeID()`
2. In `core-foundation`:
* Replace `CFMutableAttributedStringGetTypeID` with `CFAttributedStringGetTypeID`
* Add test (compilation fails before the fix and is OK after the fix)
Add binding for CTRunGetStringIndices
This PR adds a `CTRun::string_indices` method, which exposes CoreText's `CTRunGetStringIndices`/`CTRunGetStringIndicesPtr` API. The implementation is basically identical to `CTRun::glyphs` and `CTRun::positions`.
I added an assertion about the new method in the existing unit test.
Fix CFRunLoop types to avoid UB
A number of callback functions associated with the CFRunLoop types are
allowed to be NULL to evoke default behavior.
Prior to this commit the definition of those structs prevented passing
in null which meant resorting to transmute or other tricks to
effectively set null, but with recent compiler versions the compiler
emits `ud2` instructions and triggers a fault at runtime.
The correct resolution for this is to define these fields as `Option`al
callbacks and that is what this commit does.
I've used this approach successfully here in another project:
Refs: https://github.com/wez/wezterm/commit/398f333c32fb1ff4ccd9cc001a66ae22522eb60c
I've bumped up the version for the crate as part of this commit
because it effectively changes the API around these structs.
Fix deprecated usage of Rust features
This PR fixes some deprecated usage of Rust features. However, because of the use of `MaybeUninit` this PR will bump the minimum required Rust version to 1.36, which will need some discussion.
A number of callback functions associated with the CFRunLoop types are
allowed to be NULL to evoke default behavior.
Prior to this commit the definition of those structs prevented passing
in null which meant resorting to transmute or other tricks to
effectively set null, but with recent compiler versions the compiler
emits `ud2` instructions and triggers a fault at runtime.
The correct resolution for this is to define these fields as `Option`al
callbacks and that is what this commit does.
I've used this approach successfully here in another project:
Refs: https://github.com/wez/wezterm/commit/398f333c32fb1ff4ccd9cc001a66ae22522eb60c
I've bumped up the version for the crate as part of this commit
because it effectively changes the API around these structs.