Re: bizzare bug

brian <briand-/[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
Figured it out.

C.discard event causes the problem.

I am making the (incorrect ?) assumption that :

C.Get.sint (S_'XKeyEvent.f_type keyEvent)

is making a "local" copy of the value.  The dependency of the correct  
operation on C.discard makes me think otherwise.  Certainly the  
question as to why adding a print statement works is not solved yet  
either.

The real question, is, how do I force the code to make a persistent  
copy of the variable value.  It seems as though it must be using the  
pointer to the memory in some fashion.  Yuch.  I knew there was a  
reason I gave up C.

Brian


On Jan 1, 2007, at 11:01 AM, brian wrote:

> 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
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list


-------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.