-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In functions using ada_owned_string, return ada_owned_string instead …
…of &str (#67) * feat(idna-&-lib/&str->ada_owned_string): change return type to ada_owned_string ada_owned_string is supposed to be cleared manually. This was not being done currently. Instead an internal reference to the memory was being returned by these functions. This led to us being unable to delete the memory out of fear of invalidating the &str present in user space. By returning ada_owned_string, this issue is resolved and the memory leaks no longer happen in library space. Old &str can still be accessed using as_ref. BREAKING CHANGE: Functions using ada_owned_string now return ada_owned_string instead of &str. Memory leaks no longer happen in library space. Old &str can still be accessed using as_ref. * feat(ada_owned_string/Drop): add Clears the memory after the ada_owned_string goes out of scope. This ensures that ada_owned_string is cleared in user space. BREAKING CHANGE: ada_owned_string was previously not freed upon going out of scope. Now it is. * feat(ada_owned_string/ToString): add Makes it possible to convert ada_owned_string to ToString * refactor(ada_owned_string->String): change return type from ada_owned_string to String Ensures that ada_owned_string does not leak to user space and allows us to make internal breaking changes to its implementation. Fixes all leak issue. Causes small performance downgrades due to copies. Causes functions to be usable only if std is enabled. BREAKING CHANGE: Return type changed from ada_owned_string->String. Functions now work only with std feature enabled.
- Loading branch information
Showing
3 changed files
with
51 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,12 @@ pub mod ffi; | |
mod idna; | ||
pub use idna::Idna; | ||
|
||
#[cfg(feature = "std")] | ||
extern crate std; | ||
|
||
#[cfg(feature = "std")] | ||
use std::string::String; | ||
|
||
use core::{borrow, ffi::c_uint, fmt, hash, ops}; | ||
use derive_more::Display; | ||
|
||
|
@@ -270,12 +276,9 @@ impl Url { | |
/// assert_eq!(url.origin(), "https://example.com"); | ||
/// ``` | ||
#[must_use] | ||
pub fn origin(&self) -> &str { | ||
unsafe { | ||
let out = ffi::ada_get_origin(self.0); | ||
let slice = core::slice::from_raw_parts(out.data.cast(), out.length); | ||
core::str::from_utf8_unchecked(slice) | ||
} | ||
#[cfg(feature = "std")] | ||
pub fn origin(&self) -> String { | ||
unsafe { ffi::ada_get_origin(self.0) }.to_string() | ||
} | ||
|
||
/// Return the parsed version of the URL with all components. | ||
|
@@ -949,7 +952,10 @@ mod test { | |
None, | ||
) | ||
.expect("Should have parsed a simple url"); | ||
|
||
#[cfg(feature = "std")] | ||
assert_eq!(out.origin(), "https://google.com:9090"); | ||
|
||
assert_eq!( | ||
out.href(), | ||
"https://username:[email protected]:9090/search?query#hash" | ||
|