[Patches] [ python-Patches-500981 ] thread_nt.h weird prototype

noreply@sourceforge.net noreply@sourceforge.net
Wed, 09 Jan 2002 12:12:24 -0800


Patches item #500981, was opened at 2002-01-08 11:44
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=500981&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Jason Orendorff (jorend)
Assigned to: Nobody/Anonymous (nobody)
Summary: thread_nt.h weird prototype

Initial Comment:
Python/thread_nt.h gives a prototype of 
InterlockedCompareExchange that (strangely) disagrees 
with the MSDN definition of the API.

In python/dist/src/Python/thread_nt.h, line 19:
  typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID 
*dest, PVOID exc, PVOID comperand) ;

But:
  // According to MSDN
  LONG InterlockedCompareExchange( 
    LPLONG volatile Destination,  // destination 
address
    LONG Exchange,                // exchange value
    LONG Comperand                // value to compare
  );

Later on in the file, when the function actually gets 
called, the code contains a bunch of casts to 
compensate for the fact that the prototype is wrong!  
How weird is that?

I've attached a patch that fixes the wacky prototype 
in question.  (I built Python with it and ran the 
regression tests; everything works.)


----------------------------------------------------------------------

>Comment By: Jason Orendorff (jorend)
Date: 2002-01-09 12:12

Message:
Logged In: YES 
user_id=18139

Ah.  Makes perfect sense.  I do have a later platform SDK
installed.  Ater reading the support article, I am 
satisfied.

Bill me for your wasted time. :)


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-01-08 21:59

Message:
Logged In: YES 
user_id=31435

Our copies of winbase.h don't match.  I'm using VC6 SP5.  
Strange!

OK, according to
<http://support.microsoft.com/default.aspx?scid=kb;EN-
US;Q292752>

MS changed the signature of InterlockedCompareExchange in 
an incompatible way after VC6 was released.  Best guess is 
that you picked up a newer winbase.h from a platform SDK 
download specific to Win 2000.  But that isn't yet 
reflected in a service pack for VC 6 (SP5 is the most 
recent).  I really don't want to change Python until the 
new prototype ships with the compiler (or its service 
packs).

----------------------------------------------------------------------

Comment By: Jason Orendorff (jorend)
Date: 2002-01-08 20:17

Message:
Logged In: YES 
user_id=18139

Thanks for checking into this, tim.  Maybe I can provoke 
you into
thinking about it just a bit more.  I'll send e-mail to 
both the
authors asking them to take a look at this page, too.

I see declarations of InterlockedCompareExchange() on lines 
1007,
1036, 1093, and 1161 of winbase.h.  But they are consistent 
with MSDN,
*not* with thread_nt.h.  Right?

It *is* quite messy in winbase.h, messy enough to confuse 
Visual
Studio's tooltip feature.  So perhaps you will not 
immediately believe
my assertion above.  Believe this, then:

/* This program compiles without a hitch... */
#include <windows.h>
void main() {
    LONG x = 0, a = 1, b = 0;
    InterlockedCompareExchange(&x, a, b);
}

/* ...but this generates warnings about parameter types. */
#include <windows.h>
void main() {
    PVOID x = NULL, a = NULL, b = NULL;
    InterlockedCompareExchange(&x, a, b);
}

I'm using Visual C++ 6.0 on Windows 2000, on a vanilla 
Intel 32-bit system.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-01-08 12:13

Message:
Logged In: YES 
user_id=31435

Whatever MSDN may say, the prototype in the code matches 
what's actually in MS's winbase.h (at least under MSVC 6).  
This makes it too confused for me to even want to think 
about it -- maybe one of the thread_nt.h authors (listed at 
the top of the file) could be provoked into explaining what 
they believe.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=500981&group_id=5470