Skip to content

Add a type parameter to CFArray #127

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

Merged
merged 1 commit into from
Nov 25, 2017
Merged

Conversation

jrmuizel
Copy link
Collaborator

@jrmuizel jrmuizel commented Nov 17, 2017

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


This change is Reviewable

@glennw
Copy link
Member

glennw commented Nov 17, 2017

r? @pcwalton or @jdm

impl Drop for CFArray {
/// A trait describing how to convert from the stored *const c_void to the desired T
pub trait FromVoid<T> {
fn from_void(x: *const c_void) -> T;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type parameter seems redundant when we could just use Self instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

This puts us on a path to greater type safety when using CFArrays
@jdm
Copy link
Member

jdm commented Nov 25, 2017

@bors-servo: r+

@bors-servo
Copy link
Contributor

📌 Commit 0253ee2 has been approved by jdm

@bors-servo
Copy link
Contributor

⌛ Testing commit 0253ee2 with merge f9e8545...

bors-servo pushed a commit that referenced this pull request Nov 25, 2017
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 -->
@bors-servo
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: jdm
Pushing f9e8545 to master...

impl Drop for CFArray {
/// A trait describing how to convert from the stored *const c_void to the desired T
pub trait FromVoid {
fn from_void(x: *const c_void) -> Self;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be unsafe.


impl FromVoid for CFType {
fn from_void(x: *const c_void) -> CFType {
unsafe { TCFType::wrap_under_get_rule(mem::transmute(x)) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unsound, one can pass 0xdeadbeef as *const c_void or any other arbitrary and trigger UB.

@jrmuizel
Copy link
Collaborator Author

Does #134 address this sufficiently?

bors-servo pushed a commit to servo/core-graphics-rs that referenced this pull request Nov 27, 2017
Add functions to get font tag information

This depends on servo/core-foundation-rs#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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants