Forbid unsafe code #91
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The pedantic lints were bastardized. Refactor the android code to use safe bindings and forbid any unsafe code as originally intended by #90.
Fixed in
9299176(branchrefactor/strip-card_game-redundancies, PR #88).You were right that #90 was a bastardization —
deny+ three scattered#![allow(unsafe_code)]acrosssolitaire_dataandsolitaire_enginepokedunsafe holes into otherwise-pure logic crates. Rather than just relocate the
unsafe, I reduced it:
solitaire_data::android_jnibridge owns the cachedJavaVM+activity
GlobalRefand exposeswith_env/with_activity_env. Keystore,clipboard and safe-area now go through it and never touch a raw handle.
unsafe { JByteArray::from_raw(x.into_raw()) }casts in thekeystore became the safe
JByteArray::from(JObject)conversion jni 0.21already provides.
#![allow(unsafe_code)]are gone;solitaire_dataandsolitaire_engineare now unsafe-free.unsafe_code = "forbid".One unavoidable exception:
solitaire_app. As the cdylib it must export the#[unsafe(no_mangle)] android_mainand reconstruct the rawJavaVM/ activityonce there (a
no_manglesymbol can't live in a dependency rlib). It opts toits own
deny-level lints with two scoped#[allow(unsafe_code)]. That singleentry point is the only
unsafeleft in the tree — 7 sites across three cratesdown to 3 at the OS boundary in one crate.
Verified with host
clippy --workspace --all-targets -- -D warningsand anaarch64-linux-androidclippy build ofsolitaire_app(transitively engine +data). If you consider the cdylib entry an acceptable exception, this is ready
to close.