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

C APIのセーフティネットのメッセージを改善する #625

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 9 additions & 2 deletions crates/voicevox_core_c_api/src/drop_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ impl CStringDropChecker {
owned_str_addrs, ..
} = &mut *self.0.lock().unwrap();

let duplicated = !owned_str_addrs.insert(s.as_ptr() as usize);
assert!(!duplicated, "duplicated");
let ptr = s.as_ptr();
let duplicated = !owned_str_addrs.insert(ptr as usize);
if duplicated {
panic!(
"別の{ptr:p}が管理下にあります。原因としては以前の文字列{ptr:p}が誤った形で解放\
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
されたことが考えられます。このライブラリで生成したオブジェクトの解放は、この\
ライブラリが提供するAPIで行われなくてはなりません",
);
}
s
}

Expand Down
8 changes: 7 additions & 1 deletion crates/voicevox_core_c_api/src/slice_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ impl<T> SliceOwner<T> {
let len = slice.len();

let duplicated = slices.insert(ptr as usize, slice.into()).is_some();
assert!(!duplicated, "duplicated");
if duplicated {
panic!(
"別の{ptr:p}が管理下にあります。原因としては以前の配列{ptr:p}が誤った形で解放\
されたことが考えられます。このライブラリで生成したオブジェクトの解放は、この\
ライブラリが提供するAPIで行われなくてはなりません",
);
}

out_ptr.as_ptr().write_unaligned(ptr);
out_len.as_ptr().write_unaligned(len);
Expand Down
Loading