Commit Graph

367 Commits

Author SHA1 Message Date
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
bors-servo 1bfa6f743b Auto merge of #100 - servo:cargo-workspace, r=jdm
Add Cargo workspace config.

<!-- 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/100)
<!-- Reviewable:end -->
2018-01-17 19:06:50 -06:00
bors-servo 9d73e041b9 Auto merge of #141 - faern:fix-timing-sensitive-test, r=jdm
Fix timing sensitive test

This problem was found when I tried to debug #132

But since that PR grew so large, and this fix was very unrelated to the work in that PR I split it out to a separate one.

<!-- 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/141)
<!-- Reviewable:end -->
2018-01-17 15:15:24 -06:00
Linus Färnstrand 3a471a66ba Don't capture output in travis tests 2018-01-14 02:03:33 +01: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
bors-servo 665fe0f661 Auto merge of #139 - faern:fix-to-untyped-array, r=jdm
Fix bug in CFArray::to_untyped that made the retain count wrong

The following code segfaults on the `0.4.5` release:
```rust
CFArray::<CFBoolean>::from_CFTypes(&[]).to_untyped().to_untyped().to_untyped()
```
Because `to_untyped` don't increment the retain count, but when the typed array it's created from goes out of scope that one will decrement it.

And since we need to wrap under the get rule (call `CFRetain`) anyway I did not see any reason to have it as a consuming `to_` method. It's more flexible as a borrowing `as_` method.

Since you probably don't want to cause API breakage I kept the old version but fixed the bug and added a deprecation notice on it.

<!-- 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/139)
<!-- Reviewable:end -->
2017-11-28 09:49:12 -06: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
bors-servo 1a49dbb55c Auto merge of #136 - faern:boolean-from-bool, r=jdm
Add conversion to and from bool for CFBoolean

Make it possible to convert back and fourth between Rust booleans and `CFBoolean`

<!-- 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/136)
<!-- Reviewable:end -->
2017-11-27 09:38:03 -06:00
Linus Färnstrand f0766c35c2 Add conversion to and from bool for CFBoolean 2017-11-27 16:18:40 +01:00
bors-servo 94d48c20b1 Auto merge of #137 - faern:impl-from-for-cfnumber, r=jdm
Implement From<_> for CFNumber

All the `from_` methods on `CFNumber` can be expressed with implementing the `From` trait and thus enable it to be used a bit more ergonomic in some cases. And feels more idiomatic IMO.

<!-- 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/137)
<!-- Reviewable:end -->
2017-11-27 08:51:43 -06:00
Linus Färnstrand 3ef9e779b0 Implement From<_> for CFNumber 2017-11-27 15:10:40 +01:00
bors-servo 490d24a639 Auto merge of #138 - nox:bump, r=nox
Bump core-foundation-sys version to 0.4.5

This is needed to publish a new core-foundation-rs version.

<!-- 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/138)
<!-- Reviewable:end -->
2017-11-27 07:31:44 -06: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
bors-servo 4a9328efcb Auto merge of #134 - jrmuizel:unsafe, r=nox
Mark FromVoid more appropriately as unsafe

<!-- 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/134)
<!-- Reviewable:end -->
2017-11-27 06:43:42 -06:00
Jeff Muizelaar 8514c48110 Mark FromVoid more appropriately as unsafe 2017-11-26 19:00:44 -05:00
Jeff Muizelaar eb4e452d56 Bump version for CFArray changes 2017-11-26 17:55:51 -05:00
bors-servo f9e854536e Auto merge of #127 - jrmuizel:cfarray-type, r=jdm
Add a type parameter to CFArray

This puts us on a path to greater type safety when using CFArrays

<!-- 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/127)
<!-- Reviewable:end -->
2017-11-25 14:41:42 -06:00
Jeff Muizelaar 0253ee24ba Add a type parameter to CFArray
This puts us on a path to greater type safety when using CFArrays
2017-11-25 13:02:04 -05:00
bors-servo 063ba16ace Auto merge of #131 - faern:implement-propertylist, r=jdm
Add CFPropertyList and methods for casting to subclasses

https://developer.apple.com/documentation/corefoundation/cfpropertylist-rif specifies the following types as valid subclasess of a property list:
CFData, CFString, CFArray, CFDictionary, CFDate, CFBoolean, and CFNumber.

So I add a trait, `CFPropertyListSubClass`, and implement it for the valid types. Then add the `CFPropertyList` type and make it work as much as possible as the other `TCFType`s. However, it can't implement that trait, since it can't implement the static method `type_id`.

The main point of adding this was to then get to the convenience methods `to_CFPropertyList` and `downcast` that allows safe casting between the subclasses and the superclass. This is handy in calls such as `SCDynamicStoreSetValue` and `SCDynamicStoreCopyValue` where the methods either accept or return a `CFPropertyListRef`. With this addition it becomes easy to write safe wrappers around those functions and make them accept proper, constrained types.

Disclaimer: I'm not yet super familiar with CF. So I can only hope this is safe and sound, but I think it is.

<!-- 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/131)
<!-- Reviewable:end -->
2017-11-24 10:22:57 -06:00
Linus Färnstrand cc1197c371 Change downcast to return Option<T> 2017-11-24 16:30:03 +01:00
Linus Färnstrand 343b0c9a9a Improve documentation with links 2017-11-24 15:48:28 +01:00
Linus Färnstrand 2b7d15941e Add proper error for CFPropertyList::downcast 2017-11-24 15:31:24 +01:00
Linus Färnstrand ac6cc9f5d9 Add CFPropertyList and methods for casting to subclasses 2017-11-24 15:11:29 +01:00
bors-servo 40165e7876 Auto merge of #129 - faern:higher-level-dictionary-find, r=jdm
Higher level dictionary find/contains_key

I'm not very familiar with Core Foundation yet, so tell me if this is not a very helpful addition.

Adding versions of find and contains_key that can take any `TCFType` and automatically converts it to the raw pointer of its corresponding ref type. It looks like dictionaries will mostly contain types implementing this trait, and thus these versions of the methods can make it a bit more ergonomic to use the dictionary. The best would of course be if we could return the correct type as well, but I guess that is not possible with the available information.

Better suggestions for the names are welcome :)

<!-- 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/129)
<!-- Reviewable:end -->
2017-11-23 08:20:47 -06:00
bors-servo a166cee7d1 Auto merge of #130 - faern:runloop-source-and-observer, r=jdm
Add runloop source and observer functionality

I had the need to add a source (from `SCDynamicStoreCreateRunLoopSource`). And since all the add/contains/remove operations were fairly trivial I did not see any reason to not complete them for timers, sources and observers at the same time.

Also adding the `CFRunLoopMode` type alias to make the signatures reflect the original API a bit more.

Lastly, removing underscore from `_info` since it's actually used.

<!-- 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/130)
<!-- Reviewable:end -->
2017-11-23 08:07:22 -06:00
Linus Färnstrand 7468b455c7 Add runloop source and observer functionality 2017-11-23 13:07:15 +01:00
Linus Färnstrand c445b6e938 Simplify CFDictionary::get with expect() 2017-11-22 20:21:25 +01:00
Linus Färnstrand 64d944780a Simplify and document CFDictionary::get 2017-11-22 16:31:50 +01:00
Linus Färnstrand a076397614 Add higher level methods to CFDictionary 2017-11-22 16:31:50 +01:00
bors-servo 36fad2dbda Auto merge of #128 - faern:impl-from-cfstring, r=nox
Implement From<&str> for CFString

I'm not sure if you have any strict policies on what types you usually accept as parameters to the safe wrappers. So I'm not sure if you want this or not. But my reasons are:

I create `system-configuration` and `system-configuration-sys` crates as bindings to that API. In the [`SCDynamicStore`] module a lot of the functions take a `CFStringRef` as argument. It would be more ergonomic if this safe wrapper type could deal with Rust strings directly, so I can do:
```rust
let store = SCDynamicStore::create("my-dynamic-store");
let dict = store.find("State:/Network/Global/IPv4");
```
But at the same time I don't want to make it harder to use for people who already sit on `CFString` objects. So with this new `From<&str>` impl my API can be used both with `&str` and `CFString` if I implement the methods as `<S: Into<CFString>>`.

[`SCDynamicStore`]: https://developer.apple.com/documentation/systemconfiguration/scdynamicstore?language=objc

<!-- 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/128)
<!-- Reviewable:end -->
2017-11-22 08:24:29 -06:00
Linus Färnstrand b8a4536eac Implement From<&str> for CFString 2017-11-22 14:57:31 +01:00
bors-servo 491d6f782e Auto merge of #126 - ratake:date, r=jdm
Add CFDate, CFTimeZone and make them work with chrono

<!-- 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/126)
<!-- Reviewable:end -->
2017-11-13 09:49:13 -06:00
ratake be2dd253be Make CFDate and CFTimeZone interoperable with the chrono crate 2017-11-12 17:43:31 -08:00
ratake 7b6fbdb1a1 Added support for CFTimeZone objects 2017-11-12 17:43:31 -08:00
ratake 79cd89bd5d Added support for CFDate objects 2017-11-12 17:43:31 -08:00
ratake e3fc4fe3e4 Implement Debug for all types 2017-11-12 17:41:29 -08:00
bors-servo fda0928c53 Auto merge of #124 - ratake:uuid-crate, r=jdm
Made CFUUID interoperable with the uuid crate

Behind the `with-uuid` feature

<!-- 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/124)
<!-- Reviewable:end -->
2017-11-08 07:58:55 -06:00
bors-servo fe0900d73c Auto merge of #123 - ratake:clone-ord-eq, r=jdm
Implement Clone + Eq for all types, Ord for CFNumber

<!-- 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/123)
<!-- Reviewable:end -->
2017-11-08 07:35:03 -06:00
bors-servo 223a0d3a0a Auto merge of #125 - ratake:exact-iterator, r=jdm
Implement ExactSizeIterator for CFArrayIterator

<!-- 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/125)
<!-- Reviewable:end -->
2017-11-08 07:18:08 -06:00
ratake 8759071ea7 Implement ExactSizeIterator for CFArrayIterator 2017-11-07 20:58:27 -08:00
ratake b81cfce569 Made CFUUID interoperable with the uuid crate 2017-11-07 20:49:25 -08:00
ratake 2e2e6af6d8 Implement Ord for CFNumber 2017-11-07 20:44:13 -08:00