Commit Graph

1545 Commits

Author SHA1 Message Date
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
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
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 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
Linus Färnstrand b0132d3dab Upgrade to newer core-foundation and bump version 2018-01-12 22:18:34 +01:00
Linus Färnstrand a9be9abd81 Depend on newer core-graphics and bump version 2018-01-12 01:06:21 +01:00
Linus Färnstrand a01f58ab3b Bump version to 0.13.0 2018-01-12 00:29:00 +01:00
Linus Färnstrand e92e0780de Update core-foundation to 0.5.0 2017-11-29 19:01:44 +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 00f3454a63 Auto merge of #109 - jrmuizel:bump, r=jdm
Bump 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-graphics-rs/109)
<!-- Reviewable:end -->
2017-11-27 13:43:24 -06:00
Jeff Muizelaar 68c63984ca Bump version 2017-11-27 11:36:44 -05:00
bors-servo d456e69343 Auto merge of #104 - jrmuizel:font-tag, r=jdm
Add functions to get font tag information

This depends on https://github.com/servo/core-foundation-rs/pull/127 for CFArray<u32>. I'm just putting it up for reference right now.

<!-- 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-graphics-rs/104)
<!-- Reviewable:end -->
2017-11-27 09:45:38 -06: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
Jeff Muizelaar 66bb295237 Add functions to get font tag information 2017-11-27 09:57:52 -05: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