aboutsummaryrefslogtreecommitdiffstats
path: root/moder.c
diff options
context:
space:
mode:
authorTeddy Wing2018-09-03 18:00:56 +0200
committerTeddy Wing2018-09-06 04:03:20 +0200
commit84d29715900209b8ab4c600ad40ef99cdad03bd6 (patch)
tree598fc93981cc3a1109ce1fa29136b264a093ed43 /moder.c
parent4b31eb9b8412e429949aca73ef475787910e4b0b (diff)
downloaddome-key-map-84d29715900209b8ab4c600ad40ef99cdad03bd6.tar.bz2
Trying to fix pointer lifetime of mode `CKeyActionResult` (WIP)
Can't get this working. Tried a bunch of things. Decided to commit this at a stopping point before messing any further. Sort of getting there, with some things that seem like they're pointing in the right direction, but it's not working out so far. Still getting a segfault. Actually, with the `Box::into_raw` addition, the lifetime of the mode result actually lasts for a single call (printf), and then gets freed (weirdly). Makefile: * Add `-W` error flags to see if those would give me any extra information about the pointer problems, but didn't get anything. The fact that I didn't get errors indicated it was a problem on the Rust side. * Change `clean` dependency to `moder.c` so we don't rebuild if the C file (and lib) hasn't changed. c_run_key_action(): * Add some `println!`s and debug clutter * Add a separate `let` binding for `run_key_action_for_mode()` because that seemed to fix some weirdness in control flow when I was debugging the code at one point in `lldb`. Not sure it this change still makes sense to keep. * Changed function/closure version of `in_mode` to `if`/`else` because that may have made a difference in some dumb things I was experimenting with at some point. * Unsuccessful tries of `mem::forget()`, ultimately commented out. * Return a `Box::into_raw` pointer to the `CKeyActionResult` instead of the Rust pointer we were previously returning. This allows the value to live beyond the function and beyond Rust's control into the calling C code. This does, however, mean that the value leaks memory, and will need to be freed manually in the calling C code. run_key_action_for_mode(): * Wrap map handler in a check to verify `in_mode` is `None`. This ensures that if we should be returning a `KeyActionResult` for a mapping inside a mode, we don't run this code that's meant for mappings outside a mode.
Diffstat (limited to 'moder.c')
-rw-r--r--moder.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/moder.c b/moder.c
index a10a6da..c50a7d5 100644
--- a/moder.c
+++ b/moder.c
@@ -10,7 +10,7 @@ int main() {
.length = SIZE
};
const CKeyActionResult *mode = c_run_key_action(mode_trigger, NULL);
- printf("%d\n", *mode->kind);
+ /* printf("%d\n", *mode->kind); */
HeadphoneButton buttons[] = {HeadphoneButton_Down};
Trigger trigger = {