Browse Source

Remove init function as it's not needed anymore

pull/92/head
Andrea Ciliberti 2 years ago
parent
commit
3d83b3e40e
  1. 4
      ctru-rs/Cargo.toml
  2. 3
      ctru-rs/examples/audio-filters.rs
  3. 4
      ctru-rs/examples/buttons.rs
  4. 2
      ctru-rs/examples/camera-image.rs
  5. 3
      ctru-rs/examples/file-explorer.rs
  6. 3
      ctru-rs/examples/futures-basic.rs
  7. 3
      ctru-rs/examples/futures-tokio.rs
  8. 3
      ctru-rs/examples/gfx-3d-mode.rs
  9. 3
      ctru-rs/examples/gfx-wide-mode.rs
  10. 3
      ctru-rs/examples/graphics-bitmap.rs
  11. 5
      ctru-rs/examples/hashmaps.rs
  12. 4
      ctru-rs/examples/hello-both-screens.rs
  13. 3
      ctru-rs/examples/hello-world.rs
  14. 3
      ctru-rs/examples/linear-memory.rs
  15. 2
      ctru-rs/examples/mii-selector.rs
  16. 3
      ctru-rs/examples/network-sockets.rs
  17. 3
      ctru-rs/examples/output-3dslink.rs
  18. 3
      ctru-rs/examples/romfs.rs
  19. 3
      ctru-rs/examples/software-keyboard.rs
  20. 3
      ctru-rs/examples/system-configuration.rs
  21. 4
      ctru-rs/examples/thread-basic.rs
  22. 3
      ctru-rs/examples/thread-info.rs
  23. 3
      ctru-rs/examples/thread-locals.rs
  24. 2
      ctru-rs/examples/time-rtc.rs
  25. 3
      ctru-rs/src/applets/swkbd.rs
  26. 40
      ctru-rs/src/lib.rs
  27. 2
      ctru-rs/src/services/ps.rs
  28. 2
      ctru-rs/src/test_runner.rs

4
ctru-rs/Cargo.toml

@ -15,8 +15,8 @@ name = "ctru"
cfg-if = "1.0" cfg-if = "1.0"
ctru-sys = { path = "../ctru-sys", version = "0.4" } ctru-sys = { path = "../ctru-sys", version = "0.4" }
const-zero = "0.1.0" const-zero = "0.1.0"
linker-fix-3ds = { git = "https://github.com/rust3ds/rust-linker-fix-3ds.git" } linker-fix-3ds = { path = "../../rust-linker-fix-3ds" }
pthread-3ds = { git = "https://github.com/rust3ds/pthread-3ds.git" } pthread-3ds = { path = "../../pthread-3ds" }
libc = "0.2.121" libc = "0.2.121"
bitflags = "1.0.0" bitflags = "1.0.0"
widestring = "0.2.2" widestring = "0.2.2"

3
ctru-rs/examples/audio-filters.rs

@ -35,7 +35,8 @@ fn fill_buffer(audio_data: &mut [u8], frequency: f32) {
} }
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

4
ctru-rs/examples/buttons.rs

@ -1,8 +1,8 @@
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
// Setup services ctru::use_panic_handler();
ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();

2
ctru-rs/examples/camera-image.rs

@ -15,7 +15,7 @@ const BUF_SIZE: usize = WIDTH * HEIGHT * 2 * 2;
const WAIT_TIMEOUT: Duration = Duration::from_micros(300); const WAIT_TIMEOUT: Duration = Duration::from_micros(300);
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let apt = Apt::init().expect("Failed to initialize Apt service."); let apt = Apt::init().expect("Failed to initialize Apt service.");
let hid = Hid::init().expect("Failed to initialize Hid service."); let hid = Hid::init().expect("Failed to initialize Hid service.");

3
ctru-rs/examples/file-explorer.rs

@ -9,7 +9,8 @@ use std::os::horizon::fs::MetadataExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();

3
ctru-rs/examples/futures-basic.rs

@ -13,7 +13,8 @@ use futures::StreamExt;
use std::os::horizon::thread::BuilderExt; use std::os::horizon::thread::BuilderExt;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

3
ctru-rs/examples/futures-tokio.rs

@ -6,7 +6,8 @@ use std::os::horizon::thread::BuilderExt;
use std::time::Duration; use std::time::Duration;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

3
ctru-rs/examples/gfx-3d-mode.rs

@ -10,7 +10,8 @@ const IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");
static ZERO: &[u8] = &[0; IMAGE.len()]; static ZERO: &[u8] = &[0; IMAGE.len()];
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

3
ctru-rs/examples/gfx-wide-mode.rs

@ -1,7 +1,8 @@
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();

3
ctru-rs/examples/graphics-bitmap.rs

@ -15,7 +15,8 @@ use ctru::prelude::*;
static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb"); static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

5
ctru-rs/examples/hashmaps.rs

@ -1,12 +1,13 @@
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler();
// Initialize services // Initialize services
// //
// HashMaps generate hashes thanks to the 3DS' cryptografically secure generator. // HashMaps generate hashes thanks to the 3DS' cryptografically secure generator.
// This generator is only active when activating the `PS` service. // This generator is only active when activating the `PS` service.
// This service is automatically initialized in `ctru::init` // This service is automatically initialized.
ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();

4
ctru-rs/examples/hello-both-screens.rs

@ -1,8 +1,8 @@
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
// Initialize services ctru::use_panic_handler();
ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();

3
ctru-rs/examples/hello-world.rs

@ -3,7 +3,8 @@ use ctru::prelude::*;
use std::io::BufWriter; use std::io::BufWriter;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

3
ctru-rs/examples/linear-memory.rs

@ -4,7 +4,8 @@ use ctru::linear::LinearAllocator;
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

2
ctru-rs/examples/mii-selector.rs

@ -2,7 +2,7 @@ use ctru::applets::mii_selector::MiiSelector;
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");

3
ctru-rs/examples/network-sockets.rs

@ -5,7 +5,8 @@ use std::net::{Shutdown, TcpListener};
use std::time::Duration; use std::time::Duration;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();

3
ctru-rs/examples/output-3dslink.rs

@ -11,7 +11,8 @@
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

3
ctru-rs/examples/romfs.rs

@ -1,7 +1,8 @@
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

3
ctru-rs/examples/software-keyboard.rs

@ -2,7 +2,8 @@ use ctru::applets::swkbd::{Button, Swkbd};
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();

3
ctru-rs/examples/system-configuration.rs

@ -2,7 +2,8 @@ use ctru::prelude::*;
use ctru::services::cfgu::Cfgu; use ctru::services::cfgu::Cfgu;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

4
ctru-rs/examples/thread-basic.rs

@ -6,8 +6,8 @@ use std::os::horizon::thread::BuilderExt;
use std::time::Duration; use std::time::Duration;
fn main() { fn main() {
// Initialize services ctru::use_panic_handler();
ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();

3
ctru-rs/examples/thread-info.rs

@ -7,7 +7,8 @@ use ctru::prelude::*;
use std::os::horizon::thread::BuilderExt; use std::os::horizon::thread::BuilderExt;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

3
ctru-rs/examples/thread-locals.rs

@ -10,7 +10,8 @@ std::thread_local! {
} }
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
gfx.top_screen.borrow_mut().set_wide_mode(true); gfx.top_screen.borrow_mut().set_wide_mode(true);
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");

2
ctru-rs/examples/time-rtc.rs

@ -1,7 +1,7 @@
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
ctru::init(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");

3
ctru-rs/src/applets/swkbd.rs

@ -3,7 +3,6 @@ use ctru_sys::{
self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText, SwkbdState, self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText, SwkbdState,
}; };
use libc; use libc;
use std::convert::TryInto;
use std::iter::once; use std::iter::once;
use std::str; use std::str;
@ -130,7 +129,7 @@ impl Swkbd {
match swkbdInputText( match swkbdInputText(
self.state.as_mut(), self.state.as_mut(),
buf.as_mut_ptr(), buf.as_mut_ptr(),
buf.len().try_into().unwrap(), buf.len(),
) { ) {
ctru_sys::SWKBD_BUTTON_NONE => Err(self.parse_swkbd_error()), ctru_sys::SWKBD_BUTTON_NONE => Err(self.parse_swkbd_error()),
ctru_sys::SWKBD_BUTTON_LEFT => Ok(Button::Left), ctru_sys::SWKBD_BUTTON_LEFT => Ok(Button::Left),

40
ctru-rs/src/lib.rs

@ -7,40 +7,28 @@
#![feature(nonnull_slice_from_raw_parts)] #![feature(nonnull_slice_from_raw_parts)]
#![test_runner(test_runner::run)] #![test_runner(test_runner::run)]
extern "C" fn services_deinit() { // These functions are imported to assure ´cargo´ we need to link the crates.
unsafe { // These don't need to run to link the functions properly!
ctru_sys::psExit(); #[allow(unused_imports)]
} use linker_fix_3ds::init as link_init;
} #[allow(unused_imports)]
use pthread_3ds::init as pthread_init;
#[no_mangle] #[no_mangle]
#[cfg(feature = "big-stack")] #[cfg(feature = "big-stack")]
static __stacksize__: usize = 2 * 1024 * 1024; // 2MB static __stacksize__: usize = 2 * 1024 * 1024; // 2MB
/// Call this somewhere to force Rust to link some required crates /// Activate ´ctru-rs´' default panic handler.
/// This is also a setup for some crate integration only available at runtime
/// ///
/// See <https://github.com/rust-lang/rust/issues/47384> /// With this implementation, the main thread will stop and try to print debug info to an available [console::Console].
pub fn init() { /// In case it fails to find an active [console::Console], the program will just exit.
linker_fix_3ds::init(); ///
pthread_3ds::init(); /// # Notes
///
/// When ´test´ is enabled, this function won't do anything, as it should be overridden by the ´test´ environment.
pub fn use_panic_handler() {
#[cfg(not(test))] #[cfg(not(test))]
panic_hook_setup(); panic_hook_setup();
// Initialize the PS service for random data generation
unsafe {
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
libc::atexit(services_deinit);
}
} }
#[cfg(not(test))] #[cfg(not(test))]

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

@ -1,7 +1,7 @@
//! Process Services (PS) module. This is used for miscellaneous utility tasks, but //! Process Services (PS) module. This is used for miscellaneous utility tasks, but
//! is particularly important because it is used to generate random data, which //! is particularly important because it is used to generate random data, which
//! is required for common things like [`HashMap`](std::collections::HashMap). //! is required for common things like [`HashMap`](std::collections::HashMap).
//! As such, it is initialized by default in `ctru::init` instead of having a safety handler //! That's why this is the only service initialised automatically.
//! See also <https://www.3dbrew.org/wiki/Process_Services> //! See also <https://www.3dbrew.org/wiki/Process_Services>
use crate::error::ResultCode; use crate::error::ResultCode;

2
ctru-rs/src/test_runner.rs

@ -15,8 +15,6 @@ use crate::services::Apt;
/// runs all tests in series, "failing" on the first one to panic (really, the /// runs all tests in series, "failing" on the first one to panic (really, the
/// panic is just treated the same as any normal application panic). /// panic is just treated the same as any normal application panic).
pub(crate) fn run(tests: &[&TestDescAndFn]) { pub(crate) fn run(tests: &[&TestDescAndFn]) {
crate::init();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();

Loading…
Cancel
Save