mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #15809 - emilio:nsstuff, r=emilio
stylo: Backport rust-nsstring crash fixes to the vendored version. <!-- 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/15809) <!-- Reviewable:end -->
This commit is contained in:
commit
c32181c6db
1 changed files with 6 additions and 1 deletions
|
@ -313,7 +313,7 @@ macro_rules! define_string_types {
|
||||||
assert!(s.len() < (u32::MAX as usize));
|
assert!(s.len() < (u32::MAX as usize));
|
||||||
$String {
|
$String {
|
||||||
hdr: $StringRepr {
|
hdr: $StringRepr {
|
||||||
data: s.as_ptr(),
|
data: if s.is_empty() { ptr::null() } else { s.as_ptr()},
|
||||||
length: s.len() as u32,
|
length: s.len() as u32,
|
||||||
flags: F_NONE,
|
flags: F_NONE,
|
||||||
},
|
},
|
||||||
|
@ -325,6 +325,11 @@ macro_rules! define_string_types {
|
||||||
impl From<Box<[$char_t]>> for $String<'static> {
|
impl From<Box<[$char_t]>> for $String<'static> {
|
||||||
fn from(s: Box<[$char_t]>) -> $String<'static> {
|
fn from(s: Box<[$char_t]>) -> $String<'static> {
|
||||||
assert!(s.len() < (u32::MAX as usize));
|
assert!(s.len() < (u32::MAX as usize));
|
||||||
|
|
||||||
|
if s.is_empty() {
|
||||||
|
return $String::new();
|
||||||
|
}
|
||||||
|
|
||||||
// SAFETY NOTE: This method produces an F_OWNED ns[C]String from
|
// SAFETY NOTE: This method produces an F_OWNED ns[C]String from
|
||||||
// a Box<[$char_t]>. this is only safe because in the Gecko
|
// a Box<[$char_t]>. this is only safe because in the Gecko
|
||||||
// tree, we use the same allocator for Rust code as for C++
|
// tree, we use the same allocator for Rust code as for C++
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue