Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd as_void_ptr helper method to &T #15252
Comments
|
Would the T in this case be |
|
We can define a trait and import it everywhere that it's needed. |
|
Ah, I see what this is. Create a trait: pub trait AsVoidPtr {
fn as_void_ptr(&self) -> *const c_void
}And then implementing this trait on every |
|
I'm pretty sure we can implement the trait for a generic type T, rather than specific implementations for types we care about. |
|
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the If you intend to work on this issue, then add |
|
@highfive: assign me |
|
Hey @mckaymatt! Thanks for your interest in working on this issue. It's now assigned to you! |
|
@jdm Is this what you are talking about? use std::os::raw::c_void;
trait AsVoidPtr {
fn as_void_ptr(&self) -> *const c_void;
}
impl<T> AsVoidPtr for T {
fn as_void_ptr(&self) -> *const c_void {
// &*self as *const _ as *const c_void
&*self as *const _ as *const c_void
}
}I'm thinking I would put it someplace like |
|
|
Add as_void_ptr helper method to &T <!-- Please describe your changes on the following line: --> r? @jdm issue #15252 The primary goal of this PR is to add add a generic trait method that returns a void ptr. In addition to that change, I made the casting explicit in `components/script/dom/bindings/callback.rs` and `components/script/dom/promise.rs`. I did not use the new trait method because `AddRawValueRoot` is not looking for a `c_void`. It's looking for `std::os::raw::c_char`. ```rust pub fn AddRawValueRoot(cx: *mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool; ``` So I replace the `as *const _ ` with a more specific cast. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15252 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because This seems like code cleanup. It shouldn't change behaviour. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16234) <!-- Reviewable:end -->
…matt:as_void_ptr_helper_method_15252); r=jdm <!-- Please describe your changes on the following line: --> r? @jdm issue servo/servo#15252 The primary goal of this PR is to add add a generic trait method that returns a void ptr. In addition to that change, I made the casting explicit in `components/script/dom/bindings/callback.rs` and `components/script/dom/promise.rs`. I did not use the new trait method because `AddRawValueRoot` is not looking for a `c_void`. It's looking for `std::os::raw::c_char`. ```rust pub fn AddRawValueRoot(cx: *mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool; ``` So I replace the `as *const _ ` with a more specific cast. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15252 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because This seems like code cleanup. It shouldn't change behaviour. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8d8fea0b4bf323be42eff3ad5624ce33892fb6df --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : d5992625f30523ee372f54d0005b211d6c9a6b41
…matt:as_void_ptr_helper_method_15252); r=jdm <!-- Please describe your changes on the following line: --> r? @jdm issue servo/servo#15252 The primary goal of this PR is to add add a generic trait method that returns a void ptr. In addition to that change, I made the casting explicit in `components/script/dom/bindings/callback.rs` and `components/script/dom/promise.rs`. I did not use the new trait method because `AddRawValueRoot` is not looking for a `c_void`. It's looking for `std::os::raw::c_char`. ```rust pub fn AddRawValueRoot(cx: *mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool; ``` So I replace the `as *const _ ` with a more specific cast. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15252 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because This seems like code cleanup. It shouldn't change behaviour. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8d8fea0b4bf323be42eff3ad5624ce33892fb6df
…matt:as_void_ptr_helper_method_15252); r=jdm <!-- Please describe your changes on the following line: --> r? @jdm issue servo/servo#15252 The primary goal of this PR is to add add a generic trait method that returns a void ptr. In addition to that change, I made the casting explicit in `components/script/dom/bindings/callback.rs` and `components/script/dom/promise.rs`. I did not use the new trait method because `AddRawValueRoot` is not looking for a `c_void`. It's looking for `std::os::raw::c_char`. ```rust pub fn AddRawValueRoot(cx: *mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool; ``` So I replace the `as *const _ ` with a more specific cast. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15252 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because This seems like code cleanup. It shouldn't change behaviour. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8d8fea0b4bf323be42eff3ad5624ce33892fb6df
…matt:as_void_ptr_helper_method_15252); r=jdm <!-- Please describe your changes on the following line: --> r? jdm issue servo/servo#15252 The primary goal of this PR is to add add a generic trait method that returns a void ptr. In addition to that change, I made the casting explicit in `components/script/dom/bindings/callback.rs` and `components/script/dom/promise.rs`. I did not use the new trait method because `AddRawValueRoot` is not looking for a `c_void`. It's looking for `std::os::raw::c_char`. ```rust pub fn AddRawValueRoot(cx: *mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool; ``` So I replace the `as *const _ ` with a more specific cast. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15252 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because This seems like code cleanup. It shouldn't change behaviour. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8d8fea0b4bf323be42eff3ad5624ce33892fb6df UltraBlame original commit: 7186df029be0a17d5e97806e6ea9e923b2a5082c
…matt:as_void_ptr_helper_method_15252); r=jdm <!-- Please describe your changes on the following line: --> r? jdm issue servo/servo#15252 The primary goal of this PR is to add add a generic trait method that returns a void ptr. In addition to that change, I made the casting explicit in `components/script/dom/bindings/callback.rs` and `components/script/dom/promise.rs`. I did not use the new trait method because `AddRawValueRoot` is not looking for a `c_void`. It's looking for `std::os::raw::c_char`. ```rust pub fn AddRawValueRoot(cx: *mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool; ``` So I replace the `as *const _ ` with a more specific cast. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15252 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because This seems like code cleanup. It shouldn't change behaviour. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8d8fea0b4bf323be42eff3ad5624ce33892fb6df UltraBlame original commit: 7186df029be0a17d5e97806e6ea9e923b2a5082c
…matt:as_void_ptr_helper_method_15252); r=jdm <!-- Please describe your changes on the following line: --> r? jdm issue servo/servo#15252 The primary goal of this PR is to add add a generic trait method that returns a void ptr. In addition to that change, I made the casting explicit in `components/script/dom/bindings/callback.rs` and `components/script/dom/promise.rs`. I did not use the new trait method because `AddRawValueRoot` is not looking for a `c_void`. It's looking for `std::os::raw::c_char`. ```rust pub fn AddRawValueRoot(cx: *mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool; ``` So I replace the `as *const _ ` with a more specific cast. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15252 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because This seems like code cleanup. It shouldn't change behaviour. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8d8fea0b4bf323be42eff3ad5624ce33892fb6df UltraBlame original commit: 7186df029be0a17d5e97806e6ea9e923b2a5082c
There are lots of places where we write code like
&foo *const _ as *const _(like here, here, and here) where the receiver code expects a*const c_void. This code would be clearer if we could usefoo.as_void_ptr()where as_void_ptr is a trait method that's implemented for every type T.