From a160b3ba31caac3dd4984a1b8f8f7092edba05fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Wed, 2 Aug 2023 09:29:13 +0100
Subject: [PATCH] Revert "chore: temporary reversion of changes"

This reverts commit 866c23069f166e822bc0d260cc2f522647ee988e.
---
 .github/workflows/main.yml    | 2 ++
 frontends/libretro/src/lib.rs | 9 ++++++---
 frontends/sdl/src/main.rs     | 2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 7d015e37..0c6d3509 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -168,6 +168,8 @@ jobs:
         run: rustc --version
       - name: Verify Rust code format
         run: cd frontends/libretro && cargo fmt --all -- --check
+      - name: Verify Rust code linting
+        run: cd frontends/libretro && cargo clippy -- -D warnings -A unknown-lints
       - name: Run unit tests
         run: cd frontends/libretro && cargo test
       - name: Build development version
diff --git a/frontends/libretro/src/lib.rs b/frontends/libretro/src/lib.rs
index df2647aa..c7ba8d99 100644
--- a/frontends/libretro/src/lib.rs
+++ b/frontends/libretro/src/lib.rs
@@ -365,16 +365,19 @@ pub extern "C" fn retro_cheat_reset() {
     emulator.reset_cheats();
 }
 
+/// # Safety
+///
+/// This function should not be called only within Lib Retro context.
 #[no_mangle]
-pub extern "C" fn retro_cheat_set(_index: c_uint, enabled: bool, code: *const c_char) {
+pub unsafe extern "C" fn retro_cheat_set(_index: c_uint, enabled: bool, code: *const c_char) {
     debugln!("retro_cheat_set()");
     // we'll just ignore cheats that are not enabled, Boytacean
     // does not support pre-loading cheats
     if !enabled {
         return;
     }
-    let emulator = unsafe { EMULATOR.as_mut().unwrap() };
-    let code_c = unsafe { CStr::from_ptr(code) };
+    let emulator = EMULATOR.as_mut().unwrap();
+    let code_c = CStr::from_ptr(code);
     let code_s = code_c.to_string_lossy().into_owned();
     emulator.add_cheat_code(&code_s).unwrap();
 }
diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs
index 4c5ffefb..437e85ef 100644
--- a/frontends/sdl/src/main.rs
+++ b/frontends/sdl/src/main.rs
@@ -788,7 +788,7 @@ fn main() {
     // in case the default ROM path is provided and the file does not
     // exist then fails gracefully
     let path = Path::new(&args.rom_path);
-    if &args.rom_path == DEFAULT_ROM_PATH && !path.exists() {
+    if args.rom_path == DEFAULT_ROM_PATH && !path.exists() {
         println!("No ROM file provided, please provide one using the --rom-path option");
         return;
     }
-- 
GitLab