Auto merge of #13911 - upsuper:bug1312338, r=Manishearth

Use nsACString to pass string params for bindings

This is the Servo side change of [bug 1312338](https://bugzilla.mozilla.org/show_bug.cgi?id=1312338) which has been reviewed by @Manishearth.

r? @Manishearth

(This should not be merged before the Gecko side code lands in m-c)

<!-- 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/13911)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-25 04:09:19 -05:00 committed by GitHub
commit a9715c1f02
4 changed files with 44 additions and 46 deletions

View file

@ -233,7 +233,13 @@ COMPILATION_TARGETS = {
# Generation of the ffi bindings.
"bindings": {
"target_dir": "../gecko_bindings",
"raw_lines": [],
"blacklist_types": [
"nsACString_internal",
],
"raw_lines": [
"pub use nsstring::nsACString;",
"type nsACString_internal = nsACString;",
],
"flags": [
"--ignore-methods",
],

View file

@ -1,5 +1,7 @@
/* automatically generated by rust-bindgen */
pub use nsstring::nsACString;
type nsACString_internal = nsACString;
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
@ -837,10 +839,10 @@ extern "C" {
pub fn Servo_Node_ClearNodeData(node: RawGeckoNodeBorrowed);
}
extern "C" {
pub fn Servo_StyleSheet_FromUTF8Bytes(bytes: *const u8, length: u32,
pub fn Servo_StyleSheet_FromUTF8Bytes(data: *const nsACString_internal,
parsing_mode: SheetParsingMode,
base_bytes: *const u8,
base_length: u32,
base_url:
*const nsACString_internal,
base: *mut ThreadSafeURIHolder,
referrer: *mut ThreadSafeURIHolder,
principal:
@ -876,10 +878,9 @@ extern "C" {
RawServoStyleSheetBorrowed);
}
extern "C" {
pub fn Servo_ParseProperty(property_bytes: *const u8,
property_length: u32, value_bytes: *const u8,
value_length: u32, base_bytes: *const u8,
base_length: u32,
pub fn Servo_ParseProperty(property: *const nsACString_internal,
value: *const nsACString_internal,
base_url: *const nsACString_internal,
base: *mut ThreadSafeURIHolder,
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder)
@ -893,7 +894,7 @@ extern "C" {
-> ServoComputedValuesStrong;
}
extern "C" {
pub fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32)
pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
-> RawServoDeclarationBlockStrong;
}
extern "C" {
@ -907,8 +908,8 @@ extern "C" {
buffer: *mut nsString);
}
extern "C" {
pub fn Servo_CSSSupports(name: *const u8, name_length: u32,
value: *const u8, value_length: u32) -> bool;
pub fn Servo_CSSSupports(name: *const nsACString_internal,
value: *const nsACString_internal) -> bool;
}
extern "C" {
pub fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)

View file

@ -144,6 +144,7 @@ use std::ptr;
use std::mem;
use std::fmt;
use std::cmp;
use std::str;
use std::u32;
//////////////////////////////////
@ -569,6 +570,10 @@ impl nsACString {
Gecko_AppendUTF16toCString(self as *mut _, other as *const _);
}
}
pub unsafe fn as_str_unchecked(&self) -> &str {
str::from_utf8_unchecked(self)
}
}
impl<'a> From<&'a str> for nsCString<'a> {