summaryrefslogtreecommitdiff
path: root/ffi/src/lib.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-20 21:54:29 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-20 21:57:49 +0800
commit9a60751a901f568bdeb154c4115235d4f3a0f8b9 (patch)
tree65df323f6478bae51473a3d6471df39a596ce9c5 /ffi/src/lib.rs
parenta9e5c086584d3e697188be7003f564e7e2137135 (diff)
Apply clippy suggestions and improve code quality
Diffstat (limited to 'ffi/src/lib.rs')
-rw-r--r--ffi/src/lib.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs
index 7ffcb00..4682136 100644
--- a/ffi/src/lib.rs
+++ b/ffi/src/lib.rs
@@ -3,11 +3,18 @@ pub use constants::*;
#[unsafe(no_mangle)]
#[allow(nonstandard_style)]
-pub extern "C" fn JV_FreeString(ptr: *mut libc::c_char) {
- if ptr.is_null() {
- return;
- }
+/// # Safety
+///
+/// This function must be called with a pointer that was obtained from
+/// `JV_Const_*` functions or `std::ffi::CString::into_raw()`. The pointer
+/// must not be null unless it was explicitly returned as null from the
+/// allocating function. After calling this function, the pointer becomes
+/// invalid and must not be used again.
+pub unsafe extern "C" fn JV_FreeString(ptr: *mut libc::c_char) {
unsafe {
+ if ptr.is_null() {
+ return;
+ }
drop(std::ffi::CString::from_raw(ptr));
}
}