You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
safety: a safe extern "C" fn accepts null and safe code calls it (SIGTRAP) #2216
Safe code can hold and call a null C function pointer:
fn main:
let f: extern "C" fn(i32) -> i32 = null
print(f(1)) // exit 133 (SIGTRAP), no diagnostic
extern "C" fn is the safe callable type (§16.11: only unsafe extern "C" fn needs an unsafe context), so this is a crash in a program with no unsafe. The null literal is also accepted for unsafe extern "C" fn and for c_import function-pointer fields (rec { cb: null }).
Root of the class: nothing distinguishes a nullable C function pointer from a non-null one. D72's zero-storage walk already treats TY_EXTERN_FN as never zero, so the type is non-null by the compiler's own reasoning; the null literal contradicts it.
Fix plan (with #2215): extern "C" fn is non-null and refuses null; the nullable form is Option[extern "C" fn], pointer-sized with null = None (it is 16 bytes today, so it cannot sit in a repr(C) field yet). c_import maps C function-pointer fields and returns to the Option form (§16.2b.2: unknown nullability is nullable).
Fixed by #2218 (73c7cf8): extern "C" fn refuses null with the §16.6 message; the nullable form is Option of it, pointer-sized with None = null (with-abi.md §3 guarantee).
Activity
D102: extern "C" fn is non-null; nullable C function pointers are a p…
D102: nullable C function pointers are Option, placed by direction; e…
D102: non-null extern fn; nullable C function pointers as pointer-siz…
ehartford commentedon Oct 6, 2026
Fixed by #2218 (73c7cf8):
extern "C" fnrefusesnullwith the §16.6 message; the nullable form isOptionof it, pointer-sized withNone= null (with-abi.md §3 guarantee).