Bug 1317179 - [Servo] Use XPCOM string bindings instead of Gecko_Utf8SliceToString. draft
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 23 Nov 2016 19:26:07 +0800
changeset 445119 eb6044cf82f87ab47430e316ed77750aa147c626
parent 445113 e7b695e7731d1ed2c0259d9bfc6234030bbf8f4b
child 538438 84a0be33e17b654ebd8e47562a66730c6544030a
push id37418
push userbmo:boris.chiou@gmail.com
push dateTue, 29 Nov 2016 03:48:48 +0000
bugs1317179
milestone53.0a1
Bug 1317179 - [Servo] Use XPCOM string bindings instead of Gecko_Utf8SliceToString. MozReview-Commit-ID: Ct9K47QiXYl
servo/components/style/gecko_bindings/bindings.rs
servo/ports/geckolib/glue.rs
--- a/servo/components/style/gecko_bindings/bindings.rs
+++ b/servo/components/style/gecko_bindings/bindings.rs
@@ -81,17 +81,16 @@ use gecko_bindings::structs::nsCursorIma
 use gecko_bindings::structs::nsFont;
 use gecko_bindings::structs::nsIAtom;
 use gecko_bindings::structs::nsIDocument;
 use gecko_bindings::structs::nsINode;
 use gecko_bindings::structs::nsIPrincipal;
 use gecko_bindings::structs::nsIURI;
 use gecko_bindings::structs::nsMainThreadPtrHolder;
 use gecko_bindings::structs::nsRestyleHint;
-use gecko_bindings::structs::nsString;
 use gecko_bindings::structs::nsStyleBackground;
 unsafe impl Send for nsStyleBackground {}
 unsafe impl Sync for nsStyleBackground {}
 use gecko_bindings::structs::nsStyleBorder;
 unsafe impl Send for nsStyleBorder {}
 unsafe impl Sync for nsStyleBorder {}
 use gecko_bindings::structs::nsStyleColor;
 unsafe impl Send for nsStyleColor {}
@@ -484,20 +483,16 @@ extern "C" {
 }
 extern "C" {
     pub fn Gecko_AtomEqualsUTF8IgnoreCase(aAtom: *mut nsIAtom,
                                           aString:
                                               *const ::std::os::raw::c_char,
                                           aLength: u32) -> bool;
 }
 extern "C" {
-    pub fn Gecko_Utf8SliceToString(aString: *mut nsString, aBuffer: *const u8,
-                                   aBufferLen: usize);
-}
-extern "C" {
     pub fn Gecko_FontFamilyList_Clear(aList: *mut FontFamilyList);
 }
 extern "C" {
     pub fn Gecko_FontFamilyList_AppendNamed(aList: *mut FontFamilyList,
                                             aName: *mut nsIAtom);
 }
 extern "C" {
     pub fn Gecko_FontFamilyList_AppendGeneric(list: *mut FontFamilyList,
@@ -1090,17 +1085,17 @@ extern "C" {
                                                  RawServoDeclarationBlockBorrowed,
                                              result: *mut nsAString_internal);
 }
 extern "C" {
     pub fn Servo_DeclarationBlock_SerializeOneValue(declarations:
                                                         RawServoDeclarationBlockBorrowed,
                                                     property: *const nsIAtom,
                                                     is_custom: bool,
-                                                    buffer: *mut nsString);
+                                                    buffer: *mut nsAString_internal);
 }
 extern "C" {
     pub fn Servo_DeclarationBlock_Count(declarations:
                                             RawServoDeclarationBlockBorrowed)
      -> u32;
 }
 extern "C" {
     pub fn Servo_DeclarationBlock_GetNthProperty(declarations:
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -32,24 +32,22 @@ use style::gecko_bindings::bindings;
 use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong};
 use style::gecko_bindings::bindings::{RawServoStyleRuleBorrowed, RawServoStyleRuleStrong};
 use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
 use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
 use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
 use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong};
 use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
 use style::gecko_bindings::bindings::{nsACString, nsAString};
-use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
 use style::gecko_bindings::bindings::RawGeckoElementBorrowed;
 use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
 use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
 use style::gecko_bindings::structs;
 use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
 use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint};
-use style::gecko_bindings::structs::nsString;
 use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasBoxFFI};
 use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
 use style::gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
 use style::parallel;
 use style::parser::{ParserContext, ParserContextExtraData};
 use style::properties::{CascadeFlags, ComputedValues, Importance, PropertyDeclaration};
 use style::properties::{PropertyDeclarationParseResult, PropertyDeclarationBlock};
 use style::properties::{apply_declarations, parse_one_declaration};
@@ -560,29 +558,25 @@ pub extern "C" fn Servo_DeclarationBlock
     let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
     declarations.read().to_css(unsafe { result.as_mut().unwrap() }).unwrap();
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
     declarations: RawServoDeclarationBlockBorrowed,
     property: *mut nsIAtom, is_custom: bool,
-    buffer: *mut nsString)
+    buffer: *mut nsAString)
 {
     let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
     let property = get_property_name_from_atom(property, is_custom);
     let mut string = String::new();
     let rv = declarations.read().single_value_to_css(&property, &mut string);
     debug_assert!(rv.is_ok());
 
-    // FIXME: Once we have nsString bindings for Servo (bug 1294742), we should be able to drop
-    // this and fill in |buffer| directly.
-    unsafe {
-        Gecko_Utf8SliceToString(buffer, string.as_ptr(), string.len());
-    }
+    write!(unsafe { &mut *buffer }, "{}", string).expect("Failed to copy string");
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_Count(declarations: RawServoDeclarationBlockBorrowed) -> u32 {
      let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
      declarations.read().declarations.len() as u32
 }