[Xcb] XHSB and Google Summer of Code

Spencer Janssen sjanssen at cse.unl.edu
Thu Mar 29 02:14:54 PDT 2007

On Mon, 26 Mar 2007 22:16:25 -0700
Jamey Sharp <jamey at minilop.net> wrote:

> - How should a Haskell binding ensure that replies are always
>   appropriately garbage collected?

Haskell has an interface to attach a "finalizer" to any value, and
finalizers are run when a value is garbage collected.  I'll attach a
finalizer that calls xcb_wait_for_reply to every cookie.

> - What is the best way to model "Plan 7" in a Haskell interface?

First, a few words about how XHSB handles responses lazily.  The general
structure of a call into XCB looks something like:
> someFunction conn args = do
>     cookie <- xcb_some_function conn args
>     reply  <- unsafeInterleaveIO (xcb_wait_for_reply conn cookie)
>     return reply

'unsafeInterleaveIO' is the magical lazy part there.  It delays
execution of the given action until the result is demanded.  Once
the program requires the value of the response xcb_wait_for_reply is

You'll note that I ignored the third argument to xcb_wait_for_reply --
the details of allocating and checking an error pointer are too lengthy
to include in this short snippet.  In the case that xcb_wait_for_reply
indicates an error, that error will be returned instead of the value of
the response.

For requests that don't expect a response, errors will be sent to the
event queue (just like the standard "Plan 7" scheme).

It may also be useful to include the checked and unchecked variants of
each function.

It seems that the answer, in short, is "handle errors just like Plan 7
does" :).

Spencer janssen

More information about the Xcb mailing list