[ovs-dev] [PATCH] lib/util.h: use types compatible with DWORD

Nithin Raju nithin at vmware.com
Wed Feb 11 17:51:44 UTC 2015


Unit tests pass except for 3 failures. 2 of them seem expected, and the third one is with running ovsdb-server.exe as a Windows service. This does not seem to be related to my change, and the failure seen without my change as well. I’ll debug that as a separate issue.

thanks,
— Nithin

> On Feb 10, 2015, at 4:50 PM, Nithin Raju <nithin at vmware.com> wrote:
> 
> Caveat: Unit tests are running and not complete yet. I’ll reply back once they are complete.
> 
> thanks,
> -- Nithin
> 
>> On Feb 10, 2015, at 4:38 PM, Nithin Raju <nithin at vmware.com> wrote:
>> 
>> _BitScanForward() and friends are part of the Windows API and
>> take DWORD as parameter type. DWORD is defined to be 'unsigned long'
>> in Windows' header files.
>> 
>> We call into these functions from within lib/util.h. Currently, we
>> pass arguments of type uint32_t which is type defined to
>> 'unsigned int'. This incompatiblity causes failures when we compile
>> the code as C++ code or with warnings enabled.
>> 
>> The fix is to use 'unsigned long' rather than fixed size type.
>> 
>> A simplied version of the problem is illustrated using a sample
>> program:
>> -------
>> $ cat test.c
>> 
>> void
>> init_dword(DWORD *d)
>> {
>>   *d = 0;
>> }
>> 
>> int main()
>> {
>>   uint32_t u;
>> 
>>   init_dword(&u);
>> 
>>   return 0;
>> }
>> 
>> ===========
>> Problem manifests when warnings are enabled, and compiled as 'C' code:
>> ===========
>> $ cl -WX -W4 test.c
>> Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
>> Copyright (C) Microsoft Corporation.  All rights reserved.
>> 
>> test.c
>> test.c(14) : error C2220: warning treated as error - no 'object' file generated
>> test.c(14) : warning C4057: 'function' : 'DWORD *' differs in indirection to slightly different base types from 'uint32_t *'
>> 
>> ===========
>> Problem manifests when code is compiled as 'C++' code:
>> ===========
>> $ cl -Tptest.c
>> Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
>> Copyright (C) Microsoft Corporation.  All rights reserved.
>> 
>> test.c
>> test.c(14) : error C2664: 'void init_dword(DWORD *)' : cannot convert argument 1 from 'uint32_t *' to 'DWORD *'
>>       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>> -------
>> 
>> Signed-off-by: Nithin Raju <nithin at vmware.com>
>> Co-Authored-by: Linda Sun <lsun at vmware.com>
>> ---
>> lib/util.h | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>> 
>> diff --git a/lib/util.h b/lib/util.h
>> index cbaa3ac..276edb5 100644
>> --- a/lib/util.h
>> +++ b/lib/util.h
>> @@ -352,11 +352,11 @@ static inline int
>> raw_ctz(uint64_t n)
>> {
>> #ifdef _WIN64
>> -    uint32_t r = 0;
>> +    unsigned long r = 0;
>>    _BitScanForward64(&r, n);
>>    return r;
>> #else
>> -    uint32_t low = n, high, r = 0;
>> +    unsigned long low = n, high, r = 0;
>>    if (_BitScanForward(&r, low)) {
>>        return r;
>>    }
>> @@ -370,11 +370,11 @@ static inline int
>> raw_clz64(uint64_t n)
>> {
>> #ifdef _WIN64
>> -    uint32_t r = 0;
>> +    unsigned long r = 0;
>>    _BitScanReverse64(&r, n);
>>    return 63 - r;
>> #else
>> -    uint32_t low, high = n >> 32, r = 0;
>> +    unsigned long low, high = n >> 32, r = 0;
>>    if (_BitScanReverse(&r, high)) {
>>        return 31 - r;
>>    }
>> -- 
>> 1.9.4.msysgit.2
>> 
> 



More information about the dev mailing list