Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ffi/ada_free_owned_string): c parameter is passed by value #65

Merged
merged 3 commits into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" {
base_length: usize,
) -> *mut ada_url;
pub fn ada_free(url: *mut ada_url);
pub fn ada_free_owned_string(url: *mut ada_owned_string);
pub fn ada_free_owned_string(url: ada_owned_string);
pub fn ada_copy(url: *mut ada_url) -> *mut ada_url;
pub fn ada_is_valid(url: *mut ada_url) -> bool;
pub fn ada_can_parse(url: *const c_char, length: usize) -> bool;
Expand Down Expand Up @@ -118,3 +118,16 @@ extern "C" {
pub fn ada_idna_to_unicode(input: *const c_char, length: usize) -> ada_owned_string;
pub fn ada_idna_to_ascii(input: *const c_char, length: usize) -> ada_owned_string;
}

#[cfg(test)]
mod tests {
use crate::ffi;

#[test]
fn ada_free_owned_string_works() {
let str = "meßagefactory.ca";
let result = unsafe { ffi::ada_idna_to_ascii(str.as_ptr().cast(), str.len()) };
assert_eq!(result.as_ref(), "xn--meagefactory-m9a.ca");
unsafe { ffi::ada_free_owned_string(result) };
}
}
Loading