Auto merge of #10848 - heycam:struct-accessor, r=bholley

Add Servo_GetStyleFoo functions to get style structs from GeckoComputedValues

r?@bholley

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10848)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-27 02:20:17 -07:00
commit e079e01320
27 changed files with 71 additions and 37 deletions

View file

@ -92,29 +92,29 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8,
}
}
struct ArcHelpers<GeckoType, ServoType> {
pub struct ArcHelpers<GeckoType, ServoType> {
phantom1: PhantomData<GeckoType>,
phantom2: PhantomData<ServoType>,
}
impl<GeckoType, ServoType> ArcHelpers<GeckoType, ServoType> {
fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
pub fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
let owned = unsafe { Self::into(raw) };
let result = cb(&owned);
forget(owned);
result
}
unsafe fn into(ptr: *mut GeckoType) -> Arc<ServoType> {
pub unsafe fn into(ptr: *mut GeckoType) -> Arc<ServoType> {
transmute(ptr)
}
unsafe fn addref(ptr: *mut GeckoType) {
pub unsafe fn addref(ptr: *mut GeckoType) {
Self::with(ptr, |arc| forget(arc.clone()));
}
unsafe fn release(ptr: *mut GeckoType) {
pub unsafe fn release(ptr: *mut GeckoType) {
let _ = Self::into(ptr);
}
}