bizzare bug
brian <briand-/[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
Needless to say I, either I am completely missing something here, or
I found an SML bug.
Here's the code:
fun keyEvents (display, win) =
let val event = C.new U__XEvent.typ
fun getEvent() =
let val _ = F_XNextEvent.f (display, C.Ptr.|&| event)
val etype = C.Get.sint (U__XEvent.f_type event)
val keyEvent = (U__XEvent.f_xkey event)
val ewin = C.Get.ulong (S_'XKeyEvent.f_window keyEvent)
(* key press or release *)
val ektype = C.Get.sint (S_'XKeyEvent.f_type keyEvent)
val ekstate = C.Get.uint (S_'XKeyEvent.f_state keyEvent)
val ekcode = C.Get.uint (S_'XKeyEvent.f_keycode keyEvent)
in
print ("ewin="^Word32.toString(ewin)^
" etype="^Int32.toString(etype)^"\n");
if etype = XDefs.KeyPress andalso ewin = win then
(print ("keyPress type:"^Int32.toString(ektype)^
" state:"^Word32.toString(ekstate)^
" kcode:"^Word32.toString(ekcode)^
"\n");
SOME(ektype, ekstate, ekcode))
else
NONE
end
fun loop () =
let val e = getEvent()
in
case e of
SOME(x,y,z) => (C.discard event;
(x,y,z))
| NONE => loop()
end
The problem is this:
If I remove the print statement in if etype... then ... SOME(..)
else NONE , the calling routine gets the wrong answers. As you can
imagine this is rather impossible to figure it out. With the print
statement there it works fine, i.e. I get correct keypress codes, but
using :
if etype = XDefs.KeyPress andalso ewin = win then
SOME(ektype, ekstate, ekcode)
else
NONE
Does not work, in that I get the same answer over and over again.
???
Brian
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV