1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#![feature(asm)] 


#[macro_export]
macro_rules! releasetag {
    ($tag:expr) => {{
        // CAPACITY incl leading and trailing \0 (+2)
        const CAPACITY : usize = 64;
        let mut stackmem : &mut[u8;  CAPACITY] = &mut[0; CAPACITY];

        stackmem[0] = '\0' as u8; // delimit from preceding string
        
        // copy tag into stack mem
        for (i,c) in $tag.iter().enumerate() {
            stackmem[i+1] = *c;
        }
        // nop to force linker to preserve the variable on stack
        unsafe { asm!("" : : "r"(&stackmem)) }
    }};
}


#[cfg(test)]
mod tests {
    #[test]
    fn valid_macro() {
        releasetag!(b"TAG1=123");
        releasetag!(b"TAG2=ABC");
    }
}