Bug in Win32file WaitCommEvent ???
Mark Hammond
mhammond at skippinet.com.au
Tue Nov 19 17:17:03 EST 2002
Grant Edwards wrote:
> I'm trying to figure out how WaitCommEvent() works in Python,
> and it looks like there's a problem when it's used in
> overlapped mode.
>
> My understanding is that (in C) you:
>
> 1) Call WaitCommEvent() and give it three parameters:
> * File handle
> * a pointer to where the output mask value is to be stored
> * a pointer to an overlapped struct
>
> 2) WaitCommEvent() returns immediately.
>
> 3) Call one of the WaitXXX() functions to wait on the event in
> the overloapped struct.
>
> 4) When the event is triggered WaitXXX() returns. Check the
> value stored via the output mask pointer passed in 1)
> above.
>
> [I've gleaned most of this from
> http://msdn.microsoft.com/library/en-us/devio/base/waitcommevent.asp]
I don't think this last step is correct. Certainly the link you posted
doesn't say this is true. Looking further, I can't find *anything* that
implies this is true.
KB Q175551 has sample code for Windows CE that uses overlapped IO, and
it examines the mask immediately after the call.
Further, if what you say is correct, I would expect Python COM port
based programs to regularly crash! In your scenario, by the time the
overlapped function ended up writing to our mask variable, that address
would be invalid. However, it would be pretty close to the top of the
stack, so I would expect it to corrupt whatever was running when the
mask was actually written. I know a number of people have used these
APIs to do serious serial port control - either directly, or via another
wrapper. I would be very surprised we survived this long.
Can you find an explicit reference to this?
Mark.
More information about the Python-list
mailing list