stylo: Allow setting nsTArray members directly

This commit is contained in:
Emilio Cobos Álvarez 2016-06-01 11:40:34 +02:00
parent abf8ced0bf
commit 3204bfdcfd
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
6 changed files with 678 additions and 194 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(const_fn)]
#![feature(concat_idents)]
#![feature(type_macros)]
@ -10,5 +11,6 @@ extern crate heapsize;
#[allow(dead_code, non_camel_case_types)]
pub mod bindings;
pub mod ptr;
pub mod sugar;
#[allow(dead_code, non_camel_case_types, non_snake_case, non_upper_case_globals)]
pub mod structs;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
mod ns_t_array;

View file

@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::mem;
use std::ops::{Index, IndexMut};
use structs::{nsTArray, nsTArrayHeader};
impl<T> Index<u32> for nsTArray<T> {
type Output = T;
fn index<'a>(&'a self, index: u32) -> &'a T {
unsafe { mem::transmute(self.ptr_at(index)) }
}
}
impl<T> IndexMut<u32> for nsTArray<T> {
fn index_mut<'a>(&'a mut self, index: u32) -> &'a mut T {
unsafe { mem::transmute(self.ptr_at_mut(index)) }
}
}
impl<T> nsTArray<T> {
#[inline]
fn header<'a>(&'a self) -> &'a nsTArrayHeader {
debug_assert!(!self.mBuffer.is_null());
unsafe { mem::transmute(self.mBuffer) }
}
#[inline]
pub fn len(&self) -> u32 {
self.header().mLength
}
fn ptr_at_mut(&mut self, index: u32) -> *mut T {
debug_assert!(index <= self.len());
unsafe {
let slice_begin = (self.mBuffer as *const nsTArrayHeader).offset(1) as *mut T;
slice_begin.offset(index as isize)
}
}
fn ptr_at(&self, index: u32) -> *const T {
debug_assert!(index <= self.len());
unsafe {
let slice_begin = (self.mBuffer as *const nsTArrayHeader).offset(1) as *const T;
slice_begin.offset(index as isize)
}
}
}

View file

@ -46,7 +46,6 @@ export RUST_BACKTRACE=1
"-I$1/../nsprpub/pr/include" \
$PLATFORM_DEPENDENT_DEFINES \
-ignore-functions \
-no-bitfield-methods \
-no-type-renaming \
-DMOZILLA_INTERNAL_API \
-DMOZ_STYLO_BINDINGS=1 \
@ -99,6 +98,7 @@ export RUST_BACKTRACE=1
-match "nsCSSScanner.h" \
-match "Types.h" \
-match "utility" \
-match "nsTArray" \
-match "pair" \
-match "SheetParsingMode.h" \
-match "StaticPtr.h" \
@ -106,6 +106,9 @@ export RUST_BACKTRACE=1
-blacklist-type "IsDestructibleFallbackImpl" \
-blacklist-type "IsDestructibleFallback" \
-blacklist-type "nsProxyReleaseEvent" \
-blacklist-type "FallibleTArray" \
-blacklist-type "nsTArray_Impl" \
-blacklist-type "__is_tuple_like_impl" \
-opaque-type "nsIntMargin" \
-opaque-type "nsIntPoint" \
-opaque-type "nsIntRect" \
@ -130,7 +133,11 @@ if [ $? -ne 0 ]; then
else
echo -e "\e[34minfo:\e[0m bindgen exited successfully, running tests"
TESTS_FILE=$(mktemp)
rustc ../structs.rs --test -o $TESTS_FILE
TESTS_SRC=$(mktemp)
echo "#![feature(const_fn)]" > $TESTS_SRC
cat ../structs.rs >> $TESTS_SRC
rustc $TESTS_SRC --test -o $TESTS_FILE
$TESTS_FILE
rm $TESTS_FILE
rm $TESTS_SRC
fi

View file

@ -809,11 +809,10 @@ fn static_assert() {
};
unsafe {
Gecko_SetGradientStop(gecko_gradient,
index as u32,
&coord,
color,
/* interpolation_hint = */ false);
let mut stop = &mut (*gecko_gradient).mStops[index as u32];
stop.mColor = color;
stop.mIsInterpolationHint = false;
stop.mLocation.copy_from(&coord);
}
}