You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Martin Sebor <se...@roguewave.com> on 2008/03/27 15:58:21 UTC

Re: svn commit: r641783 - in /stdcxx/trunk/tests/src: braceexp.cpp char.cpp printf.cpp process.cpp rand.cpp

faridz@apache.org wrote:
> Author: faridz
> Date: Thu Mar 27 04:05:41 2008
> New Revision: 641783
> 
> URL: http://svn.apache.org/viewvc?rev=641783&view=rev
> Log:
> 2008-03-27  Farid Zaripov  <fa...@epam.com>
> 
> 	* tests/src/braceexp.cpp (_rw_string_buffer): Declare n parameter as
> 	_RWSTD_SIZE_T instead of int to silence conversion warning.

FYI: it's okay (even preferable(*)) to size_t in .cpp files. The reason
why we use the _RWSTD_SIZE_T macro is to avoid namespace pollution in
our library headers by having to #include <stddef.h> or <cstddef>.

[*] It's preferable because size_t can be used in function-like casts
(e.g., size_t(foo)) while _RWSTD_SIZE_T cannot (it might expand to
somthing like unsigned long). That being said, I wonder if we should
switch away from using function-like casts and to the more targeted
and more cleanly specified C++ casts (reinterpret or static_cast).

Martin

> 	* tests/src/char.cpp (_rw_fmtstringv): Silence size_t to int conversion warning.
> 	* tests/src/process.cpp (rw_process_kill): Silence conversion warning.
> 	* tests/src/printf.cpp (_rw_vasnprintf_c99): Same.
> 	(_rw_fmtbadaddr): Same.
> 	(_rw_fmtarray): Same.
> 	(_rw_vfprintf): Same. Use OutputDebugString() depending on _WIN32 macro instead
> 	of _MSC_VER. Don't call IsDebuggerPresent() (which depends on macros _WIN32_WINNT
> 	and WINVER) because the OutputDebugString() does nothing if there is no any
> 	attached debugger present.
> 	* tests/src/rand.cpp (rw_seed32): Declare k as _RWSTD_UINT32 instead of _RWSTD_SIZE_T.
> 	Removed useless casting of table32[ii] of type _RWSTD_UINT32 to _RWSTD_SIZE_T before
> 	assign the value to _RWSTD_UINT32 seed.
> 	(rw_seed32): Declare k as _RWSTD_UINT64 instead of _RWSTD_SIZE_T. Removed useless
> 	casting of table64[ii] of type _RWSTD_UINT64 to _RWSTD_SIZE_T before assign the value
> 	to _RWSTD_UINT64 seed.
> 
> Modified:
>     stdcxx/trunk/tests/src/braceexp.cpp
>     stdcxx/trunk/tests/src/char.cpp
>     stdcxx/trunk/tests/src/printf.cpp
>     stdcxx/trunk/tests/src/process.cpp
>     stdcxx/trunk/tests/src/rand.cpp
> 
> Modified: stdcxx/trunk/tests/src/braceexp.cpp
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/braceexp.cpp?rev=641783&r1=641782&r2=641783&view=diff
> ==============================================================================
> --- stdcxx/trunk/tests/src/braceexp.cpp (original)
> +++ stdcxx/trunk/tests/src/braceexp.cpp Thu Mar 27 04:05:41 2008
> @@ -220,7 +220,7 @@
>  
>  struct _rw_string_buffer
>  {
> -    _rw_string_buffer (char* s, int n)
> +    _rw_string_buffer (char* s, _RWSTD_SIZE_T n)
>          : capacity_ (n)
>          , length_ (0)
>          , buffer_ (s)
> 
> Modified: stdcxx/trunk/tests/src/char.cpp
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/char.cpp?rev=641783&r1=641782&r2=641783&view=diff
> ==============================================================================
> --- stdcxx/trunk/tests/src/char.cpp (original)
> +++ stdcxx/trunk/tests/src/char.cpp Thu Mar 27 04:05:41 2008
> @@ -1284,7 +1284,7 @@
>  
>      if (-1 == elemsize || 1 == elemsize) {
>          if (nelems < 0)
> -            nelems = beg.pc ? strlen (beg.pc) : 0;
> +            nelems = beg.pc ? int (strlen (beg.pc)) : 0;
>  
>          nbytes = rw_asnprintf (pbuf, pbufsize, "%{+}%{#*s}", nelems, beg.pc);
>      }
> 
> Modified: stdcxx/trunk/tests/src/printf.cpp
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/printf.cpp?rev=641783&r1=641782&r2=641783&view=diff
> ==============================================================================
> --- stdcxx/trunk/tests/src/printf.cpp (original)
> +++ stdcxx/trunk/tests/src/printf.cpp Thu Mar 27 04:05:41 2008
> @@ -53,14 +53,11 @@
>  #  include <wctype.h>   // for iswalpha(), ...
>  #endif   // _RWSTD_NO_WCTYPE_H
>  
> -#if defined (_WIN32) || defined (_WIN64)
> -   // define macros to enable Win98 + WinNT support in <windows.h>
> -#  define _WIN32_WINNT 0x0410
> -#  define WINVER       0x400
> -#  include <windows.h>   // for GetLastError(), IsDebuggerPresent()
> +#if defined (_WIN32)
> +#  include <windows.h>   // for GetLastError(), OutputDebugString()
>  #else
>  #  include <dlfcn.h>
> -#endif   // _WIN{32,64}
> +#endif   // _WIN32
>  
>  #include <ios>
>  #include <iostream>
> @@ -625,7 +622,7 @@
>          RW_ASSERT (0 != *buf.pbuf);
>  
>          // len = int (strlen (*buf.pbuf));
> -        len = buf.endoff;
> +        len = int (buf.endoff);
>  
>          spec.param.ptr_ = PARAM (ptr_, pva);
>  
> @@ -1650,7 +1647,7 @@
>      if (0 == _rw_bufcat (buf, ")", 1))
>          return -1;
>  
> -    return buf.endoff - off;
> +    return int (buf.endoff - off);
>  }
>  
>  /********************************************************************/
> @@ -2031,7 +2028,7 @@
>              // repeated occurrences of the element to conserve
>              // space and make the string more readable
>  
> -            const long repeat = pelem - last;
> +            const long repeat = long (pelem - last);
>  
>              if (flags & (A_CHAR | A_WCHAR)) {
>                  // format element into elemstr as a character
> @@ -3430,25 +3427,17 @@
>              //        for async-signal safety
>              FILE* const stdio_file = _RWSTD_REINTERPRET_CAST (FILE*, file);
>  
> -            nwrote = fwrite (buf, 1, size_t (nchars), stdio_file);
> +            nwrote = int (fwrite (buf, 1, size_t (nchars), stdio_file));
>  
>              // flush in case stderr isn't line-buffered (e.g., when
>              // it's determined not to refer to a terminal device,
>              // for example after it has been redirected to a file)
>              fflush (stdio_file);
>  
> -#ifdef _MSC_VER
> -
> -            // IsDebuggerPresent() depends on the macros _WIN32_WINNT
> -            // and WINVER being appropriately #defined prior to the
> -            // #inclusion of <windows.h>
> -            if (IsDebuggerPresent ()) {
> -
> -                // write string to the attached debugger (if any)
> -                OutputDebugString (buf);
> -            }
> -
> -#endif   // _MSC_VER
> +#ifdef _WIN32
> +            // write string to the attached debugger (if any)
> +            OutputDebugString (buf);
> +#endif   // _WIN32
>  
>          }
>      }
> 
> Modified: stdcxx/trunk/tests/src/process.cpp
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/process.cpp?rev=641783&r1=641782&r2=641783&view=diff
> ==============================================================================
> --- stdcxx/trunk/tests/src/process.cpp (original)
> +++ stdcxx/trunk/tests/src/process.cpp Thu Mar 27 04:05:41 2008
> @@ -695,11 +695,11 @@
>      }
>  
>      // wait for process termination
> -    int ret = rw_waitpid (pid, 0, timeout);
> -    if (pid == ret)
> +    rw_pid_t res = rw_waitpid (pid, 0, timeout);
> +    if (pid == res)
>          return 0;
>  
> -    if (-1 == ret)
> +    if (-1 == res)
>          rw_error (0, __FILE__, __LINE__,
>                    "rw_waitpid (%{P}, 0, %i) failed: errno = %{#m} (%{m})",
>                    pid, timeout);
> @@ -733,11 +733,11 @@
>          }
>  
>          // wait for process termination
> -        ret = rw_waitpid (pid, 0, timeout);
> -        if (pid == ret)
> +        rw_pid_t res = rw_waitpid (pid, 0, timeout);
> +        if (pid == res)
>              return 0;
>  
> -        if (-1 == ret)
> +        if (-1 == res)
>              rw_error (0, __FILE__, __LINE__,
>                        "rw_waitpid (%{P}, 0, %i) failed: errno = %{#m} (%{m})",
>                        pid, timeout);
> 
> Modified: stdcxx/trunk/tests/src/rand.cpp
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/rand.cpp?rev=641783&r1=641782&r2=641783&view=diff
> ==============================================================================
> --- stdcxx/trunk/tests/src/rand.cpp (original)
> +++ stdcxx/trunk/tests/src/rand.cpp Thu Mar 27 04:05:41 2008
> @@ -48,18 +48,17 @@
>  
>      table32 [TABLE_SIZE - 1] = seed;
>  
> -    _RWSTD_SIZE_T i;
> -    _RWSTD_SIZE_T k = 1;
> +    _RWSTD_UINT32_T k = 1;
>  
> -    for (i = 0; i != TABLE_SIZE - 1U; ++i) {
> +    for (_RWSTD_SIZE_T i = 0; i != TABLE_SIZE - 1U; ++i) {
>  
>          const _RWSTD_SIZE_T ii = 21U * i % TABLE_SIZE;
>          table32 [ii] =  k;
>          k            = seed - k;
> -        seed         = _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, table32 [ii]);
> +        seed         = table32 [ii];
>      }
>  
> -    for (i = 0; i != 4U; ++i) {
> +    for (_RWSTD_SIZE_T i = 0; i != 4U; ++i) {
>          for (_RWSTD_SIZE_T ii = 0; ii != TABLE_SIZE; ++ii)
>              table32 [i] = table32 [i] - table32 [(i + 31U) % TABLE_SIZE];
>      }
> @@ -99,18 +98,17 @@
>  
>      table64 [TABLE_SIZE - 1] = seed;
>  
> -    _RWSTD_SIZE_T i;
> -    _RWSTD_SIZE_T k = 1;
> +    _RWSTD_UINT64_T k = 1;
>  
> -    for (i = 0; i != TABLE_SIZE - 1U; ++i) {
> +    for (_RWSTD_SIZE_T i = 0; i != TABLE_SIZE - 1U; ++i) {
>  
>          const _RWSTD_SIZE_T ii = 21U * i % TABLE_SIZE;
>          table64 [ii] =  k;
>          k            = seed - k;
> -        seed         = _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, table64 [ii]);
> +        seed         = table64 [ii];
>      }
>  
> -    for (i = 0; i != 4U; ++i) {
> +    for (_RWSTD_SIZE_T i = 0; i != 4U; ++i) {
>          for (_RWSTD_SIZE_T ii = 0; ii != TABLE_SIZE; ++ii)
>              table64 [i] = table64 [i] - table64 [(i + 31U) % TABLE_SIZE];
>      }
> 
> 
>