servo: Merge #14404 - Use XPCOM string bindings instead of Gecko_Utf8SliceToString (from BorisChiou:Bug1317179); r=Manishearth
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 30 Nov 2016 20:12:28 -0800
changeset 340256 d608d978ded1dd947191dd8ec708d773d94f5cf8
parent 340255 e758e3f57135b0e7c7ce189a39ba1fd2e7d383db
child 340257 cf7af9f4dfbeb1153aca8a4e94f0ef6951e0357d
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
bugs1317179
servo: Merge #14404 - Use XPCOM string bindings instead of Gecko_Utf8SliceToString (from BorisChiou:Bug1317179); r=Manishearth These are the servo-side changes for [bug 1317179](https://bugzilla.mozilla.org/show_bug.cgi?id=1317179). @Manishearth has already reviewed them there. I'd like to merge these patches until the gecko-side changes for [bug 1317179](https://bugzilla.mozilla.org/show_bug.cgi?id=1317179) is landed. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix [bug 1317179](https://bugzilla.mozilla.org/show_bug.cgi?id=1317179). - [X] These changes do not require tests because there are existing tests for this in mozilla-central Source-Repo: https://github.com/servo/servo Source-Revision: 22c8df150af341064abac25a26768c8c1517df1f
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: *mut 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};
@@ -562,29 +560,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
 }