unsafe blocks
To improve static analysis, Vala should have the unsafe
keyword, which will allow users to write code that uses pointers. Outside of these blocks, pointers will be forbidden.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/unsafe
Examples:
unsafe void unsafe_fn () {
// pointers allowed anywhere inside
}
unsafe int unsafe_fn2 () { return 1; }
void main () {
int *x = null; // not allowed
unsafe {
int *y = null; // allowed
// use y ...
}
unsafe_fn (); // not allowed
unsafe { unsafe_fn (); } // allowed
int k = unsafe { unsafe_fn2 () }; // unsafe blocks are expressions
}
// external methods may or may not be unsafe
extern void foo ();
extern unsafe void foo2 ();
It remains an open question whether APIs created from C sources with vapigen
should be unsafe
by default.
Edited by Princeton Ferro