#![macro_use]
#[macro_export]
macro_rules! constructor {
($($FN:ident),*) => {
$(pub mod $FN {
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![deny(private_no_mangle_statics /* >>> constructor must be used from a pub mod <<< */)]
#[cfg(target_os = "linux")]
#[link_section = ".ctors"]
#[no_mangle]
pub static $FN: extern fn() = super::$FN;
#[cfg(target_os = "macos")]
#[link_section = "__DATA,__mod_init_func"]
#[no_mangle]
pub static $FN: extern fn() = super::$FN;
#[cfg(target_os = "windows")]
#[link_section = ".CRT$XCU"]
#[no_mangle]
pub static $FN: extern fn() = super::$FN;
})*
};
}
#[cfg(test)]
pub mod test {
static mut BUNNY: &'static str = "i'm just a cute li'l bunny!\nand i wont hurt nobody!!\n🐰";
#[test]
fn bunny_is_fluffy() {
println!("{}", unsafe { BUNNY });
}
pub static mut RAN: bool = false;
extern "C" fn set_ran() {
unsafe { RAN = true }
}
constructor! { set_ran }
#[test]
fn works() {
assert!(unsafe { RAN });
}
extern crate zalgo;
constructor! { corrupt_bunny }
pub extern "C" fn corrupt_bunny() {
unsafe {
use self::zalgo::*;
let mr_bun = gen(BUNNY, false, false, true, ZalgoSize::None);
let red = "\x1b[31m";
let reset = "\x1b[0m";
let mr_bun = format!("{}{}{}", red, mr_bun, reset);
use std::mem::{transmute, forget};
{
let mr_bun: &str = &mr_bun;
BUNNY = transmute(mr_bun);
}
forget(mr_bun); }
}
}