Skip to content

Commit b1633d7

Browse files
authored
fix(ffi/ada_free_owned_string): c parameter is passed by value (#65)
* fix(ffi/ada_free_owned_string): c parameter is passed by value While working on #63, I noticed that my Drop wasn't correctly working because the Rust Implementation was assuming that the C parameters are passed by pointer, while they are actually passed by value Then on a deeper check of the C code, found it at https://github.com/ada-url/ada/blob/1227f60798b05a04412af867d2f13ed20ead9243/include/ada_c.h#L53C6-L53C27. BREAKING CHANGE: ada_free_owned_string parameter pass by value * test(ffi/ada_free_owned_string): add Add a single test case for ada_free_owned_string This way, the provided function is always present and always used in the codebase. Test case is based on the previously present test case for idna_to_ascii * style(ffi/tests): format Had not previously formatted the code
1 parent 7cd8574 commit b1633d7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/ffi.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extern "C" {
5959
base_length: usize,
6060
) -> *mut ada_url;
6161
pub fn ada_free(url: *mut ada_url);
62-
pub fn ada_free_owned_string(url: *mut ada_owned_string);
62+
pub fn ada_free_owned_string(url: ada_owned_string);
6363
pub fn ada_copy(url: *mut ada_url) -> *mut ada_url;
6464
pub fn ada_is_valid(url: *mut ada_url) -> bool;
6565
pub fn ada_can_parse(url: *const c_char, length: usize) -> bool;
@@ -118,3 +118,16 @@ extern "C" {
118118
pub fn ada_idna_to_unicode(input: *const c_char, length: usize) -> ada_owned_string;
119119
pub fn ada_idna_to_ascii(input: *const c_char, length: usize) -> ada_owned_string;
120120
}
121+
122+
#[cfg(test)]
123+
mod tests {
124+
use crate::ffi;
125+
126+
#[test]
127+
fn ada_free_owned_string_works() {
128+
let str = "meßagefactory.ca";
129+
let result = unsafe { ffi::ada_idna_to_ascii(str.as_ptr().cast(), str.len()) };
130+
assert_eq!(result.as_ref(), "xn--meagefactory-m9a.ca");
131+
unsafe { ffi::ada_free_owned_string(result) };
132+
}
133+
}

0 commit comments

Comments
 (0)