diff options
| author | Teddy Wing | 2018-10-05 19:40:53 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-10-05 21:37:36 +0200 |
| commit | 9ec2632bb036defc9f5706c1f38981dc4eb55afe (patch) | |
| tree | cb6de899fd4eb3047155ce930827fb9115357d5a /src | |
| parent | 961b3b0b2d33a2c632fbc093b61e2c2d4dc07f70 (diff) | |
| download | dome-key-map-9ec2632bb036defc9f5706c1f38981dc4eb55afe.tar.bz2 | |
Turn `Config` into a C struct instead of an opaque struct
We want to be able to access the fields in `Config`, so make them
accessible across the FFI boundary.
* Return a regular, not boxed, `Config` from `parse_args()`.
* Add `repr(C)`s on our structs (had forgotten how this worked in
961b3b0b2d33a2c632fbc093b61e2c2d4dc07f70).
* Delete the `config_free()` function as I think the stuct doesn't need
to be freed being a POD struct. Hopefully that's the case.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cocoa_bridge.rs | 8 | ||||
| -rw-r--r-- | src/config.rs | 4 |
2 files changed, 3 insertions, 9 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index f572c37..529fb5d 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -319,13 +319,7 @@ pub extern "C" fn parse_args( let config = config::parse_args(&args); - Box::into_raw(Box::new(config)) as *const Config -} - -#[no_mangle] -pub extern "C" fn config_free(ptr: *mut Config) { - if ptr.is_null() { return } - unsafe { Box::from_raw(ptr); } + &config as *const Config } diff --git a/src/config.rs b/src/config.rs index 66769a9..b7b09ab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,13 +1,13 @@ use getopts::Options; -#[no_mangle] +#[repr(C)] #[derive(Default)] struct Args { reload: bool, daemon: bool, } -#[no_mangle] +#[repr(C)] #[derive(Default)] pub struct Config { args: Args, |
