Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

binding KeyboardListener results in a segfault #2

Closed
abooij opened this issue Aug 28, 2014 · 3 comments
Closed

binding KeyboardListener results in a segfault #2

abooij opened this issue Aug 28, 2014 · 3 comments

Comments

@abooij
Copy link
Owner

abooij commented Aug 28, 2014

me being lazy and ignoring "array" type arguments has turned against me: the KeyboardListener now doesn't have the right number of entries, causing a segfault when trying to bind to it.

@nh2
Copy link

nh2 commented Aug 30, 2014

Can you give me a hint where precisely the problem is and what would have to be done about it?

@abooij
Copy link
Owner Author

abooij commented Aug 30, 2014

Wayland message arguments can have one of a number of types, as detailed in the wayland documentation. These bindings use that information to properly marshal data to Haskell types - e.g. an fd type argument is converted into a System.Posix.IO.Fd.

The array type argument is an opaque array-like structure. However, the type of its elements is not specified by the protocol, giving us little chance to properly marshal the data to Haskell types. So I just ignored all messages containing such arguments.

But the wl_keyboard interface makes use of an array argument in its enter event, so we can't set a callback for enter: indeed, KeyboardListener doesn't even offer a place to set it.

But now the C structure that we pass to the wayland library (notice that the KeyboardListener is Storable, a fact that we don't want the user to exploit but can't really hide either AFAIA) has the wrong length (since it's missing the enter field), causing a segfault.

The solution is to either add that field to the C struct we store and set it to null (ie. properly disable interfacing with messages which have an array type argument), or invent a smart way to marshal array type arguments into Haskell, which would be the preferred thing to do, but takes some, well, let's say "creative" solutions.

The former would simply be done by remembering that there is some disabled message in an interface, and then pass a nullFunPtr in Graphics/Wayland/Scanner.chs.

The latter would consist of, if possible, use heuristics to figure out how to present the data neatly (e.g. the wl_keyboard.enter.keys argument is a list of ints specifying the currently pressed keys), or otherwise just return the underlying length and a data pointer, since officially it is indeed just a blob of binary data.

@abooij abooij closed this as completed in fe96266 Sep 16, 2014
@nh2
Copy link

nh2 commented Sep 16, 2014

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants