Commit Graph

129 Commits

Author SHA1 Message Date
Jeff Muizelaar 97ec75c14d Redo the interface of CFDictionary and CFMutableDictionary
This is a pretty big change to take advantge of the type parameters.
It simplifies things and makes them more safe.
2018-02-07 10:58:33 -05:00
Jeff Muizelaar 8e943b19b5 Move FromVoid and ItemRef to base
This will let us reuse them in dictionary.rs
2018-02-07 10:58:30 -05:00
Jeff Muizelaar 5616935b56 Give CFDictionary type parameters for keys and values
There's more to be done to clean up the interface now that we have
type parameters but this is a good place to start.
2018-02-02 16:56:37 -05:00
Jeff Muizelaar 6b526436c2 Unify the impl macros
Using some more macro magic we can avoid having to duplicate
our impl macro implementation for generic types. This will help
when we want a version for CFDictionary with two type parameters.
2018-02-02 16:18:23 -05:00
bors-servo fb8a43f29d Auto merge of #156 - waywardmonkeys:reduce-libc-usage, r=jdm
Reduce usage of libc crate.

Switch from using `libc` types to `::std::os::raw`. This is a breaking
change due to the differences in how `c_void` is defined.

`core-foundation-sys` no longer needs the `libc` dependency.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/156)
<!-- Reviewable:end -->
2018-02-02 16:11:19 -05:00
Jeff Muizelaar ec118b30e1 Add a ConcreteCFType trait
We'll use this to distinguish between generic and concrete CFTypes.
This lets us prevent downcast()ing to arbitrary generic types.
2018-02-01 13:04:28 -05:00
Bruce Mitchener 7e7d65bb4d Reduce usage of libc crate.
Switch from using `libc` types to `::std::os::raw`. This is a breaking
change due to the differences in how `c_void` is defined.

`core-foundation-sys` no longer needs the `libc` dependency.
2018-02-01 20:39:10 +07:00
Bruce Mitchener bf3a9c89bd Add missing license headers to src files. 2018-02-01 09:32:29 +07:00
Linus Färnstrand dc9392c19e Add possibility to iterate untyped CFArray 2018-01-27 10:50:06 +01:00
bors-servo ff67c15632 Auto merge of #153 - servo:updateversion, r=jdm
Bump version to 0.5.1.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/153)
<!-- Reviewable:end -->
2018-01-26 13:01:11 -06:00
Josh Matthews 5d7753a78a Bump version to 0.5.1. 2018-01-26 13:48:25 -05:00
Jeff Muizelaar c50094db9a Avoid reexporting CFRelease 2018-01-26 10:34:32 -05:00
Jeff Muizelaar c662076906 Lift getting the length of the array out.
This changes get() to return an Option<> and adds a get_unchecked() that doesn't do a bounds check.
This means our bounds check can be inlined into the caller instead of us having to CFArrayGetCount twice
for each element.
2018-01-25 11:49:01 -05:00
Jeff Muizelaar df7df6bb52 Add the ability to borrow values from the array.
This uses borrowed values from the array to avoid having to
Retain/Release during iteration. It also implements borrowing
for all TCFType.
2018-01-25 10:08:34 -05:00
Linus Färnstrand 7e87a9d8fa Bump version to 0.5.0 2018-01-24 08:57:50 +01:00
Linus Färnstrand ab08525293 Rename as_untyped -> to_untyped, add into_untyped 2018-01-24 08:57:50 +01:00
Linus Färnstrand c071ba7874 Clean up my own non-rustfmt style 2018-01-23 22:42:39 +01:00
Linus Färnstrand 70dd9c3a7e Remove deprecated methods 2018-01-23 22:41:37 +01:00
Linus Färnstrand aae7c708c8 Change ConcreteTypeRef to an associated value 2018-01-23 22:41:37 +01:00
Linus Färnstrand 238756492f Fix consistency in how run_loop variables are named 2018-01-21 17:21:38 +01:00
Linus Färnstrand 637552ea4a Pub export sys part of error 2018-01-21 17:09:43 +01:00
Linus Färnstrand 224d741ff2 Fix so macros are usable outside of crate 2018-01-21 17:09:43 +01:00
Linus Färnstrand 251be4b2d6 Move dictionary test to dictionary.rs 2018-01-21 16:39:43 +01:00
Linus Färnstrand 3aa97e2abe Move CFRunLoopSource method to runloop.rs 2018-01-21 16:33:07 +01:00
bors-servo 8834563793 Auto merge of #142 - faern:add-consuming-cheap-cast, r=jdm
Add consuming cheap cast

There are a lot of places where we increment and decrement the retain count when we would not have to. For example, a very common use-case with PropertyLists is to just directly cast them to their correct sub type and then throw the PropertyList away (because there is nothing you can do with the PropertyList instance directly.)

The reason we do this, I guess, is mostly because all `Drop` implementations force a retain count decrement. So we have to keep incrementing it to keep it correct. But if we add a flag to types that can be used to disable the decrement, then we can also get rid of the increment when we virtually just want to cast a pointer between two types.

This PR implements this by adding a boolean flag to all CF structs that is used by the `Drop` impl to determine if it should `CFRelease` the instance or not. Then this flag is modified in appropriate places where we cast to other types and consume ourselves.

I added some benchmarks locally. I did not want to commit them since benchmarking only works on nighty, and I did not feel like adding a feature flag for it etc. Anyhow, the following benchmarks:
```rust
#[bench]
fn bench_before(b: &mut Bencher) {
   let string = CFString::from_static_string("Bar");
    b.iter(|| unsafe {
        string.clone()
            .to_CFPropertyList()
            .downcast::<_, CFString>()
            .unwrap()
            .disable_release();
    })
}

#[bench]
fn bench_after(b: &mut Bencher) {
    let string = CFString::from_static_string("Bar");
    b.iter(|| unsafe {
        string.clone()
            .into_CFPropertyList()
            .downcast_into::<_, CFString>()
            .unwrap()
            .disable_release();
    })
}
```
Given the following results:
```
test propertylist::test::bench_after         ... bench:          16 ns/iter (+/- 3)
test propertylist::test::bench_before        ... bench:          73 ns/iter (+/- 14)
```
The final call to `disable_release()` in the benchmarks are to prevent the type coming out of the `unwrap()` from calling `CFRelease` on drop, and thus avoid measuring that. I want to try to measure only `{to,into}_CFPropertyList`, `downcast` and `downcast_into`. The `clone` is needed because the `into` version requires it and it would then not be fair to not have it on both.

I would say that speeding it up by a factor of ~4 can be well worth it? (Well, that 4 is of course no good measurement of anything, microbenchmarks etc. etc.. The benchmark mostly shows that a lot can be gained from avoiding some retain counting.)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/142)
<!-- Reviewable:end -->
2018-01-20 19:13:21 -06:00
bors-servo 2d35ed2d49 Auto merge of #84 - trlim:filedescriptor, r=jdm
Add bindings for `CFFileDescriptor`

This pull request adds implementation of `CFFileDescriptor` and `CFRunLoopSource` related API.

<!-- Reviewable:start -->

---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/84)

<!-- Reviewable:end -->
2018-01-20 17:17:36 -06:00
bors-servo a4cee535b6 Auto merge of #144 - Nemo157:publish-licenses, r=jdm
Include license files in packages

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/144)
<!-- Reviewable:end -->
2018-01-20 13:01:36 -06:00
Linus Färnstrand 3ec0d57863 Convert CFMutableDictionary to use declare_TCFType 2018-01-20 17:15:58 +01:00
Linus Färnstrand 8a52a343c6 Improve documentation and add #[inline] 2018-01-20 16:37:16 +01:00
Linus Färnstrand 3f4f6a0db2 Simplify CFArray test with new downcast method 2018-01-20 16:37:16 +01:00
Linus Färnstrand b13257441d Add cheap casting between CF types 2018-01-20 16:37:16 +01:00
Linus Färnstrand 4fc21d970b Add macro that declare CF types with Drop impl 2018-01-20 16:37:16 +01:00
bors-servo 3a8e10cb4f Auto merge of #135 - djg:dict_mut, r=jdm
Add CFMutableDictionary type.

Added CFMutableDictionary that presents the mutable dictionary
functions of CF. Tries to present a similar interface as CFDictionary.

Fixes issue #93.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/135)
<!-- Reviewable:end -->
2018-01-19 17:25:41 -06:00
Tae-il Lim 9c36257660 Improve tests and code readability 2018-01-18 11:34:04 +09:00
Tae-il Lim 5285fe0836 Change create methods to return Option<T> to handle NULL return value 2018-01-18 11:32:00 +09:00
Wim Looman 6bf580ee28 Include license files in packages 2018-01-17 20:52:01 +01:00
Tae-il Lim d6fe0651fe Add filedescriptor test 2018-01-15 17:22:13 +09:00
Tae-il Lim c5d0134e96 Add method to create CFRunLoopSource from CFFileDescriptor 2018-01-15 17:21:37 +09:00
Tae-il Lim 2a19e3f79e Safer handling of CFFileDescriptorContext 2018-01-15 17:20:07 +09:00
Tae-il Lim 530f732ce8 Implement CFFileDescriptor 2018-01-15 14:35:16 +09:00
Linus Färnstrand f80f28d3a6 Fix RunLoop test: Increase time tolerance and dont unwind to C 2018-01-14 02:03:33 +01:00
Dan Glastonbury 6a77e377ba Add CFMutableDictionary type.
Added CFMutableDictionary that presents the mutable dictionary
functions of CF. Tries to present a similar interface as CFDictionary.

Fixes issue #93.
2017-11-29 12:50:05 +10:00
Linus Färnstrand c33598dc99 Bump version to 0.4.6 2017-11-28 16:46:33 +01:00
Linus Färnstrand f0b8535e4e Fix bug in CFType::instance_of. It's not an instance of all other types 2017-11-28 16:46:33 +01:00
Linus Färnstrand 4e9cbd7387 Add test for as_untyped 2017-11-28 16:46:33 +01:00
Linus Färnstrand 31fcb64bf1 Fix bug in CFArray::to_untyped that made the retain count wrong 2017-11-28 16:19:31 +01:00
Linus Färnstrand f0766c35c2 Add conversion to and from bool for CFBoolean 2017-11-27 16:18:40 +01:00
Linus Färnstrand 3ef9e779b0 Implement From<_> for CFNumber 2017-11-27 15:10:40 +01:00
Anthony Ramine cc66c00ac3 Bump core-foundation-sys version to 0.4.5
This is needed to publish a new core-foundation-rs version.
2017-11-27 14:30:18 +01:00
bors-servo 654a7fdbc1 Auto merge of #133 - jrmuizel:bump-version, r=nox
Bump version for CFArray changes

This is needed for https://github.com/servo/core-graphics-rs/pull/104

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/133)
<!-- Reviewable:end -->
2017-11-27 07:05:50 -06:00