| 1 |
// Name mangling can cope with char-like byte literals. |
| 2 |
|
| 3 |
#[repr(C)] |
| 4 |
pub struct Parser<const OPEN: u8, const CLOSE: u8> { |
| 5 |
pub buf: *mut u8, |
| 6 |
pub len: usize, |
| 7 |
} |
| 8 |
|
| 9 |
#[no_mangle] |
| 10 |
pub unsafe extern "C" fn init_parens_parser(p: *mut Parser<b'(', b')'>, buf: *mut u8, len: usize) { |
| 11 |
unsafe { |
| 12 |
*p = Parser { buf, len }; |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
// The same type as above, because `b'(' == 40 && b')' == 41`. And it happens |
| 17 |
// to mangle to the same C identifier. It doesn't always work out that way! |
| 18 |
#[no_mangle] |
| 19 |
pub unsafe extern "C" fn destroy_parens_parser(p: *mut Parser<40, 41>) { |
| 20 |
// nothing to do |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
#[no_mangle] |
| 25 |
pub unsafe extern "C" fn init_braces_parser(p: *mut Parser<b'{', b'}'>, buf: *mut u8, len: usize) { |
| 26 |
unsafe { |
| 27 |
*p = Parser { buf, len }; |
| 28 |
} |
| 29 |
} |