Skip to content

Commit f63ff79

Browse files
bors[bot]Bromeon
andauthored
Merge #641
641: Fix Object.callv() not marked unsafe r=toasteater a=Bromeon Fixes a typo causing `Object.callv()` accidentally not being marked unsafe. Also adds the following statement to all unsafe binding functions: > **Safety:** This function bypasses Rust's static type checks (aliasing, thread boundaries, calls to free(), ...). I was thinking about a per-function reason and can change it if needed. The description is also very generic at the moment and can probably be made more concrete. Co-authored-by: Jan Haller <[email protected]>
2 parents a709225 + 8e2e853 commit f63ff79

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

bindings_generator/src/methods.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn rename_property_getter<'a>(name: &'a str, class: &GodotClass) -> &'a str {
256256

257257
const UNSAFE_OBJECT_METHODS: &[(&str, &str)] = &[
258258
("Object", "call"),
259-
("Object", "vcall"),
259+
("Object", "callv"),
260260
("Object", "call_deferred"),
261261
];
262262

@@ -348,10 +348,15 @@ pub(crate) fn generate_methods(
348348

349349
let rusty_name = format_ident!("{}", rusty_method_name);
350350

351-
let maybe_unsafe = if UNSAFE_OBJECT_METHODS.contains(&(&class.name, method_name)) {
352-
quote! { unsafe }
351+
let maybe_unsafe: TokenStream;
352+
let maybe_unsafe_reason: &str;
353+
if UNSAFE_OBJECT_METHODS.contains(&(&class.name, method_name)) {
354+
maybe_unsafe = quote! { unsafe };
355+
maybe_unsafe_reason = "\n# Safety\nThis function bypasses Rust's static type checks \
356+
(aliasing, thread boundaries, calls to free(), ...).";
353357
} else {
354-
Default::default()
358+
maybe_unsafe = TokenStream::default();
359+
maybe_unsafe_reason = "";
355360
};
356361

357362
let method_bind_fetch = {
@@ -370,8 +375,8 @@ pub(crate) fn generate_methods(
370375
let recover = ret_recover(&ret_type, icall_ty);
371376

372377
let output = quote! {
373-
374378
#[doc = #doc_comment]
379+
#[doc = #maybe_unsafe_reason]
375380
#[inline]
376381
pub #maybe_unsafe fn #rusty_name(&self #params_decl) -> #rust_ret_type {
377382
unsafe {

0 commit comments

Comments
 (0)