Browse Source

Merge pull request #62 from ian-h-chamberlain/must-use-bindgen

Generate #[must_use] on bindings that return a Result
pull/67/head
Meziu 3 years ago committed by GitHub
parent
commit
9305abf60d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      Cargo.toml
  2. 14
      ctru-rs/src/lib.rs
  3. 6
      ctru-rs/src/services/fs.rs
  4. 2
      ctru-rs/src/services/soc.rs
  5. 1
      ctru-sys/bindgen.sh
  6. 1706
      ctru-sys/src/bindings.rs

5
Cargo.toml

@ -1,9 +1,6 @@
[workspace] [workspace]
members = ["ctru-rs", "ctru-sys"] members = ["ctru-rs", "ctru-sys"]
[patch.'https://github.com/Meziu/libc']
libc = "0.2.121"
[patch.'https://github.com/Meziu/ctru-rs'] [patch.'https://github.com/Meziu/ctru-rs']
# Make sure all dependencies use the local ctru-sys package # Make sure all dependencies use the local ctru-sys package
ctru-sys = { path = "ctru-sys" } ctru-sys = { path = "ctru-sys" }

14
ctru-rs/src/lib.rs

@ -22,16 +22,22 @@ pub fn init() {
linker_fix_3ds::init(); linker_fix_3ds::init();
pthread_3ds::init(); pthread_3ds::init();
#[cfg(not(test))]
panic_hook_setup();
// Initialize the PS service for random data generation // Initialize the PS service for random data generation
unsafe { unsafe {
ctru_sys::psInit(); let ps_ret = ctru_sys::psInit();
if ctru_sys::R_FAILED(ps_ret) {
panic!(
"Failed to initialize random data generation: {:?}",
Error::from(ps_ret)
)
}
// Setup the deconstruction at the program's end // Setup the deconstruction at the program's end
libc::atexit(services_deinit); libc::atexit(services_deinit);
} }
#[cfg(not(test))]
panic_hook_setup();
} }
#[cfg(not(test))] #[cfg(not(test))]

6
ctru-rs/src/services/fs.rs

@ -996,7 +996,7 @@ impl Drop for Fs {
impl Drop for Archive { impl Drop for Archive {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ctru_sys::FSUSER_CloseArchive(self.handle); let _ = ctru_sys::FSUSER_CloseArchive(self.handle);
} }
} }
} }
@ -1004,7 +1004,7 @@ impl Drop for Archive {
impl Drop for File { impl Drop for File {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ctru_sys::FSFILE_Close(self.handle); let _ = ctru_sys::FSFILE_Close(self.handle);
} }
} }
} }
@ -1012,7 +1012,7 @@ impl Drop for File {
impl Drop for Dir { impl Drop for Dir {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ctru_sys::FSDIR_Close(self.0); let _ = ctru_sys::FSDIR_Close(self.0);
} }
} }
} }

2
ctru-rs/src/services/soc.rs

@ -50,7 +50,7 @@ impl Soc {
// Surely nothing bad will happens :D // Surely nothing bad will happens :D
|| unsafe { || unsafe {
// The socket buffer is freed automatically by `socExit` // The socket buffer is freed automatically by `socExit`
ctru_sys::socExit(); let _ = ctru_sys::socExit();
}, },
)?; )?;

1
ctru-sys/bindgen.sh

@ -6,6 +6,7 @@ bindgen "$DEVKITPRO/libctru/include/3ds.h" \
--rust-target nightly \ --rust-target nightly \
--use-core \ --use-core \
--distrust-clang-mangling \ --distrust-clang-mangling \
--must-use-type 'Result' \
--no-doc-comments \ --no-doc-comments \
--no-layout-tests \ --no-layout-tests \
--ctypes-prefix "::libc" \ --ctypes-prefix "::libc" \

1706
ctru-sys/src/bindings.rs

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save