Bug 788014 - Part 1: Define nsrefcnt to be unsigned long unconditionally on Windows; r=jrmuizel

On Windows, IUknown::AddRef and IUnknown::Release are defined to
return ULONG, which is defined as unsigned long.  The existing
code relies on the PR_BYTES_PER_LONG macro which is #defined in
prtypes.h to always be 4 on Windows.  If we remove the prtypes.h
inclusion from nscore.h, in the places where prtypes.h is not
included by other things, we will fall into the other path in the
#ifdef condition which defines nsrefcnt to be unsigned int, which
causes the signature of AddRef and Release to change, which
results in linker errors.

There are a couple of reasons why this change is correct:

1. On both Win32 and Win64, the size of the long type is 4 bytes,
always.  And prtypes.h doesn't detect the size of longs, it just
assumes it, so this check is really a tautology.
2. If the size of the long type changes on Windows, sometime,
the return value of AddRef and Release on Windows should change
size as well in order to maintain binary compatibility with
IUnknown, and before this change, the code would fail to hold
that promise.

--HG--
extra : rebase_source : 8333582b494aaca17c91cf35287a084083219050
This commit is contained in:
Ehsan Akhgari 2012-09-07 15:09:01 -04:00
parent e1dcd9f8bf
commit ab697fda8e

View File

@ -318,7 +318,7 @@ typedef uint32_t nsresult;
* The following ifdef exists to maintain binary compatibility with
* IUnknown.
*/
#if defined(XP_WIN) && PR_BYTES_PER_LONG == 4
#ifdef XP_WIN
typedef unsigned long nsrefcnt;
#else
typedef uint32_t nsrefcnt;