stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: svn commit: r466955 - /incubator/stdcxx/trunk/tests/src/printf.cpp
Date Mon, 06 Nov 2006 20:58:38 GMT
Farid Zaripov wrote:
>  > -----Original Message-----
>  > From: Martin Sebor [mailto:sebor@roguewave.com]
>  > Sent: Friday, November 03, 2006 1:40 AM
>  > To: stdcxx-dev@incubator.apache.org
>  > Subject: Re: svn commit: r466955 -
>  > /incubator/stdcxx/trunk/tests/src/printf.cpp
>  >
>  > faridz@apache.org wrote:
>  > > Author: faridz
>  > > Date: Mon Oct 23 01:57:26 2006
>  > > New Revision: 466955
>  > >
>  > > URL: http://svn.apache.org/viewvc?view=rev&rev=466955
>  > > Log:
>  > > 2006-10-23 Farid Zaripov <faridz@kyiv.vdiweb.com>
>  > >
>  > >     * printf.cpp (_rw_fmtstrarray): Use ' ' as delimiter if
>  > >     ' ' is specified in flags field
>  >
>  > This new feature should be exercised in the self/0.printf.cpp test.
> 
>   I have added new format ("%{P}") for print rw_pid_t. Also I have 
> modified 0.printf.cpp test to exercise "%{P}" and %{ As} formatting 
> directives. The diff files are attached.

Okay.

> 
>   We have a problem with "%{M}" formatting directive. In rwtest library 
> the memptr_t type is defined within fmt_defs.h as a pointer to member 
> function of incomplete type with size sizeof(memptr_t) == 16 on MSVC. 
> The 0.printf.cpp test exercising the "%{M}" directive with memptr_t 
> defined as pointer to member function of complete type with size 
> sizeof(memptr_t) == 4 on MSVC.
> 
>   Does the "%{M}" formatting directive is intended for printing the any 
> pointer to member of any class or only void (Class::*)() where Class
> is the simple class? Because the size of pointer to class member can 
> vary depending from the class I think we should pass the sizeof of the 
> pointer too.

That seems odd. How can the size of an type change like that?
It must be a bug. I opened the following issue with Microsoft:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=236074

I'd be willing to bet that the few tests that need to print
the value of a member pointer will have seen the definition
on the class, so I would simply supply an empty definition
for Class in fmt_defs.h.

Martin

> 
>   ChangeLog:
>   * printf.cpp (rw_vasnprintf): Added checking for malformed directive
>   (_rw_fmttm, _rw_fmtarray, _rw_fmtstrarray, _rw_fmtstr, _rw_fmtwstr):
>   Third parameter of __rw::__rw_memattr() changed to -1
>   (_rw_vasnprintf_ext): Ditto. Added "%{P}" formating directive to
>   format the rw_pid_t value
>   * 0.printf.cpp: #included rw_process.h for rw_pid_t
>   (test_chararray): Added missing backslash in result string
>   (test_stringarray): Added exercising of the "%{ As}" formatting
>   directive
>   (test_pid): New function exercising the "%{P}" formating directive
>   (main): Added call to the test_pid()
> 
> Farid.
> 
> 
> ------------------------------------------------------------------------
> 
> Index: 0.printf.cpp
> ===================================================================
> --- 0.printf.cpp	(revision 471674)
> +++ 0.printf.cpp	(working copy)
> @@ -27,22 +27,23 @@
>   **************************************************************************/
>  
>  #include <rw_printf.h>
> -#include <environ.h>   // for rw_putenv()
> +#include <rw_process.h> // for rw_pid_t
> +#include <environ.h>    // for rw_putenv()
>  
> -#include <bitset>      // for bitset
> -#include <ios>         // for ios::openmode, ios::seekdir
> -#include <string>      // for string
> +#include <bitset>       // for bitset
> +#include <ios>          // for ios::openmode, ios::seekdir
> +#include <string>       // for string
>  
> -#include <assert.h>    // for assert()
> -#include <ctype.h>     // for isdigit()
> -#include <errno.h>     // for EXXX, errno
> -#include <limits.h>    // for INT_MAX, ...
> -#include <signal.h>    // for SIGABRT, ...
> -#include <stdio.h>     // for printf(), ...
> -#include <stdlib.h>    // for free(), size_t
> -#include <string.h>    // for strcpy()
> -#include <stdarg.h>    // for va_arg, ...
> -#include <time.h>      // for struct tm
> +#include <assert.h>     // for assert()
> +#include <ctype.h>      // for isdigit()
> +#include <errno.h>      // for EXXX, errno
> +#include <limits.h>     // for INT_MAX, ...
> +#include <signal.h>     // for SIGABRT, ...
> +#include <stdio.h>      // for printf(), ...
> +#include <stdlib.h>     // for free(), size_t
> +#include <string.h>     // for strcpy()
> +#include <stdarg.h>     // for va_arg, ...
> +#include <time.h>       // for struct tm
>  
>  
>  // disable tests for function name in "%{lF}"
> @@ -559,7 +560,7 @@
>          TEST ("%{2Ac}", L"abc", 0, 0, "L\"abc\"");
>  
>          TEST ("%{2.0Ac}", L"",    0, 0, "L\"\"");
> -        TEST ("%{2.1Ac}", L"",    0, 0, "L\"\0\"");
> +        TEST ("%{2.1Ac}", L"",    0, 0, "L\"\\0\"");
>  
>          TEST ("%{2.0Ac}", L"a",   0, 0, "L\"\"");
>          TEST ("%{2.1Ac}", L"a",   0, 0, "L\"a\"");
> @@ -675,6 +676,17 @@
>      TEST ("%{#As}", ARG ("abcd"),              0, 0, "\"abcd\"");
>      TEST ("%{#As}", ARG ("abcd", "efg"),       0, 0, "\"abcd\",\"efg\"");
>      TEST ("%{#As}", ARG ("abcd", "efg", "hi"), 0, 0, "\"abcd\",\"efg\",\"hi\"");
> +
> +    TEST ("%{ As}", 0,                              0, 0, "(null)");
> +    TEST ("%{ As}", ARG ("a"),                      0, 0, "a");
> +    TEST ("%{ As}", ARG ("a", "bc"),                0, 0, "a bc");
> +    TEST ("%{ As}", ARG ("a", "bc", "def"),         0, 0, "a bc def");
> +    TEST ("%{ As}", ARG ("a", "bc", "def", "ghij"), 0, 0, "a bc def ghij");
> +
> +    TEST ("%{ #As}", 0,                        0, 0, "(null)");
> +    TEST ("%{ #As}", ARG ("abc"),              0, 0, "\"abc\"");
> +    TEST ("%{ #As}", ARG ("abc", "efg"),       0, 0, "\"abc\" \"efg\"");
> +    TEST ("%{ #As}", ARG ("abc", "efg", "hi"), 0, 0, "\"abc\" \"efg\" \"hi\"");
>  }
>  
>  /***********************************************************************/
> @@ -2234,6 +2246,27 @@
>  
>  /***********************************************************************/
>  
> +static void
> +test_pid ()
> +{
> +    //////////////////////////////////////////////////////////////////
> +    printf ("%s\n", "extension: \"%P\": rw_pid_t");
> +
> +    const rw_pid_t pid = 12345;
> +
> +    TEST ("%{P}", pid, 0, 0, "12345");
> +
> +    TEST ("[%{10P}]",    pid, 0, 0, "[     12345]");
> +    TEST ("[%{+10P}]",   pid, 0, 0, "[     12345]");
> +    TEST ("[%{-10P}]",   pid, 0, 0, "[12345     ]");
> +    TEST ("[%{.3P}]",    pid, 0, 0, "[12345]");
> +    TEST ("[%{10.3P}]",  pid, 0, 0, "[     12345]");
> +    TEST ("[%{+10.3P}]", pid, 0, 0, "[     12345]");
> +    TEST ("[%{-10.3P}]", pid, 0, 0, "[12345     ]");
> +}
> +
> +/***********************************************************************/
> +
>  static const tm*
>  make_tm (int sec = 0,            // [0,60]
>           int min = 0,            // [0,59]
> @@ -2822,6 +2855,7 @@
>      test_memptr ();
>      test_errno ();
>      test_signal ();
> +    test_pid ();
>  
>      test_basic_string ();
>  
> 
> 
> ------------------------------------------------------------------------
> 
> Index: printf.cpp
> ===================================================================
> --- printf.cpp	(revision 471674)
> +++ printf.cpp	(working copy)
> @@ -790,7 +790,7 @@
>          if ('{' == *fc) {
>              const char* const endbrace = strchr (++fc, '}');
>  
> -            if (0 == endbrace) {
> +            if (0 == endbrace || fc == endbrace) {
>                  const size_t flen = strlen (fc -= 2);
>                  next = _rw_bufcat (buf, fc, flen);
>                  if (0 == next)
> @@ -1670,7 +1670,7 @@
>  static int
>  _rw_fmttm (const FmtSpec &spec, Buffer &buf, const tm *tmb)
>  {
> -    if (   0 == tmb || 0 > _RW::__rw_memattr (tmb, sizeof *tmb, 0)
> +    if (   0 == tmb || 0 > _RW::__rw_memattr (tmb, sizeof *tmb, -1)
>          || (size_t)tmb & (sizeof (int) - 1)) {
>          return _rw_fmtbadaddr (spec, buf, tmb, sizeof (int));
>      }
> @@ -1897,7 +1897,7 @@
>  {
>      RW_ASSERT (0 != buf.pbuf);
>  
> -    if (   0 == array || 0 > _RW::__rw_memattr (array, _RWSTD_SIZE_MAX, 0)
> +    if (   0 == array || 0 > _RW::__rw_memattr (array, _RWSTD_SIZE_MAX, -1)
>          || ((size_t)array & (sizeof *array - 1))) {
>          // qualify the name of the static function in order to
>          // allow it to be found when referenced from a template
> @@ -2234,7 +2234,7 @@
>  
>      int len = 0;
>  
> -    if (0 == argv || 0 > _RW::__rw_memattr (argv, sizeof *argv, 0))
> +    if (0 == argv || 0 > _RW::__rw_memattr (argv, sizeof *argv, -1))
>          return _rw_fmtbadaddr (spec, buf, argv);
>  
>      size_t argc = spec.prec;
> @@ -2333,7 +2333,7 @@
>      if (spec.fl_pound)
>          return _rw_fmtarray (spec, buf, str, len, A_CHAR | A_ESC);
>  
> -    if (0 == str || 0 > _RW::__rw_memattr (str, _RWSTD_SIZE_MAX, 0))
> +    if (0 == str || 0 > _RW::__rw_memattr (str, _RWSTD_SIZE_MAX, -1))
>          return _rw_fmtbadaddr (spec, buf, str);
>  
>      if (_RWSTD_SIZE_MAX == len)
> @@ -2404,7 +2404,7 @@
>          return _rw_fmtarray (spec, buf, wstr, len, flags);
>      }
>  
> -    if (   0 == wstr || 0 > _RW::__rw_memattr (wstr, _RWSTD_SIZE_MAX, 0)
> +    if (   0 == wstr || 0 > _RW::__rw_memattr (wstr, _RWSTD_SIZE_MAX, -1)
>          || ((size_t)wstr & (sizeof *wstr - 1)))
>          return _rw_fmtbadaddr (spec, buf, wstr, sizeof *wstr);
>  
> @@ -2597,7 +2597,7 @@
>          // std::bitset
>          spec.param.ptr_ = PARAM (ptr_);
>          if (   0 == spec.param.ptr_
> -            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, 0))
> +            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, -1))
>              len = _rw_fmtbadaddr (spec, buf, spec.param.ptr_, sizeof (long));
>          else
>              len = _rw_fmtbits (spec, buf, spec.param.ptr_, sizeof (long));
> @@ -2606,7 +2606,7 @@
>      case 'b':   // %{b}
>          spec.param.ptr_ = PARAM (ptr_);
>          if (   0 == spec.param.ptr_
> -            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, 0))
> +            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, -1))
>              len = _rw_fmtbadaddr (spec, buf, spec.param.ptr_);
>          else
>              len = _rw_fmtbits (spec, buf, spec.param.ptr_, 1);
> @@ -2806,6 +2806,12 @@
>          break;
>      }
>  
> +    case 'P':   // %{P}
> +        // rw_pid_t is _RWSTD_SSIZE_T which is equal to _RWSTD_PTRDIFF_T
> +        spec.param.diff_ = PARAM (diff_);
> +        len = rw_fmtinteger (spec, buf, spec.param.diff_);
> +        break;
> +
>      case 's':   // %{s}, %{As}, %{Is}, %{ls}
>          if (spec.mod == spec.mod_ext_A) {   // array of strings
>              spec.param.ptr_ = PARAM (ptr_);
> @@ -2840,7 +2846,7 @@
>  
>              const std::wstring* const pstr = (std::wstring*)spec.param.ptr_;
>  
> -            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, 0)
> +            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, -1)
>                  || (size_t)pstr & (sizeof (pstr) - 1)) {
>                  len = _rw_fmtbadaddr (spec, buf, pstr, sizeof pstr);
>              }
> @@ -2857,7 +2863,7 @@
>  
>              const std::string* const pstr = (std::string*)spec.param.ptr_;
>  
> -            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, 0)
> +            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, -1)
>                  || (size_t)pstr & (sizeof (pstr) - 1)) {
>                  len = _rw_fmtbadaddr (spec, buf, pstr, sizeof pstr);
>              }


Mime
View raw message