Uh oh!
There was an error while loading. Please reload this page.
platform: move get_id_info from platform.rs to public - #864
Conversation
534cfc4 to
263a1feCompareRichardhongyu
commented
Aug 9, 2022
bjorn3
left a comment
There was a problem hiding this comment.
There are two other options to consider:
- Create a standalone function that can be used by any adapter.
- Create a bang macro used inside the impl. So for example
impl<T: Driver> Adapter<T> { impl_get_id_info!(); /* ... */ }.
I think I prefer the first option.
| format!( | ||
| " | ||
| impl<T: Driver> {name}<T> {{ |
There was a problem hiding this comment.
#[derive(Foo)] generally implements a trait called Foo for the respective type. Not sure if we should introduce a trait GetIdInfo, or not.
wedsonaf
commented
Aug 9, 2022
@Richardhongyu thanks for doing this. What I had in mind, however, was similar to what @bjorn3 said: a function that other adapters can call. Is there a reason why you think such an option wouldn't work? |
Richardhongyu
commented
Aug 9, 2022
I tried this before. But the |
bjorn3
commented
Aug 9, 2022
Then option 2
Should work. |
Richardhongyu
commented
Aug 9, 2022
Option 2 looks easier to read. I will change to this style. |
263a1fe to
ce42dbdCompareRichardhongyu
commented
Aug 9, 2022
The new commit uses Option 2. |
Uh oh!
There was an error while loading. Please reload this page.
ce42dbd to
b52bafaCompareRichardhongyu
commented
Aug 9, 2022
@bjorn3 Thanks for reviewing and helping improve the code! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
b52bafa to
8495bc9CompareRichardhongyu
commented
Aug 9, 2022
I pushed a new version to apply the above changes. |
8495bc9 to
59bff0eComparewedsonaf
commented
Aug 9, 2022
Why can't these be passed in as arguments? |
wedsonaf
commented
Aug 9, 2022
Here's a working version (just the first few lines are different, the rest is exactly the same): fnget_id_info<T>(dev:&implRawDevice,table:Option<driver::IdTable<'static, of::DeviceId,T>>,) -> Option<&'staticT>{let table = table?;// SAFETY: `table` has static lifetime, so it is valid for read. `dev` is guaranteed to be// valid while it's alive, so is the raw device returned by it.let id = unsafe{ bindings::of_match_device(table.as_ref(), dev.raw_device())};if id.is_null(){returnNone;}// SAFETY: `id` is a pointer within the static table, so it's always valid.let offset = unsafe{(*id).data};if offset.is_null(){returnNone;}// SAFETY: The offset comes from a previous call to `offset_from` in `IdArray::new`, which// guarantees that the resulting pointer is within the table.let ptr = unsafe{ id.cast::<u8>().offset(offset as_).cast::<Option<T>>()};// SAFETY: The id table has a static lifetime, so `ptr` is guaranteed to be valid for read.unsafe{(&*ptr).as_ref()}}
let info = get_id_info(&dev,T::OF_DEVICE_ID_TABLE);Do you see a reason why this wouldn't work? |
59bff0e to
cf1679dCompare93551a0 to
260a52fCompareSigned-off-by: Li Hongyu <lihongyu1999@bupt.edu.cn>
260a52f to
c13e4d1Compare@wedsonaf This is really cool! Thanks for your help! I didn't think of passing |
Signed-off-by: Li Hongyu lihongyu1999@bupt.edu.cn