You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by fa...@apache.org on 2008/03/18 15:09:17 UTC

svn commit: r638369 - in /stdcxx/trunk/include: loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h

Author: faridz
Date: Tue Mar 18 07:09:17 2008
New Revision: 638369

URL: http://svn.apache.org/viewvc?rev=638369&view=rev
Log:
2008-03-18  Farid Zaripov  <fa...@epam.com>

	* include/loc/_num_get.cc (num_get::get): Code checking for overflow moved from here...
	* include/loc/num_get.h (_rw_check_overflow_{short|int}): ... to here.
	* include/rw/_iosfwd.h: Added new define _RWSTD_FMTFLAGS (used in _rw_check_overflow_{short|int}).

Modified:
    stdcxx/trunk/include/loc/_num_get.cc
    stdcxx/trunk/include/loc/_num_get.h
    stdcxx/trunk/include/rw/_iosfwd.h

Modified: stdcxx/trunk/include/loc/_num_get.cc
URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/loc/_num_get.cc?rev=638369&r1=638368&r2=638369&view=diff
==============================================================================
--- stdcxx/trunk/include/loc/_num_get.cc (original)
+++ stdcxx/trunk/include/loc/_num_get.cc Tue Mar 18 07:09:17 2008
@@ -76,34 +76,7 @@
     long __tmp = __val;
 
     __begin = do_get (__begin, __end, __flags, __err, __tmp);
-
-    long __shrt_min;
-    long __shrt_max;
-
-    if (   __tmp < 0
-        || (__flags.flags () & _RWSTD_IOS_BASEFIELD) == _RWSTD_IOS_DEC) {
-        // decimal parsing overflows outside the range below
-        __shrt_max = long (_RWSTD_SHRT_MAX);
-        __shrt_min = long (_RWSTD_SHRT_MIN);
-    }
-    else {
-        // other than decimal parsing overflows outside the range below
-        // (unreliable if basefield is 0 and the sequence is decimal)
-        __shrt_max = long (_RWSTD_USHRT_MAX);
-        __shrt_min = long (_RWSTD_USHRT_MIN);
-    }
-
-    // lwg issue 23: check for overflow
-    if (__tmp < __shrt_min) {
-        __err |= _RW::__rw_failbit;
-        __val  = short (_RWSTD_SHRT_MIN);
-    }
-    else if (__tmp > __shrt_max) {
-        __err |= _RW::__rw_failbit;
-        __val  = short (_RWSTD_SHRT_MAX);
-    }
-    else
-        __val = _RWSTD_STATIC_CAST (short, __tmp);
+    __val = __rw_check_overflow_short (__tmp, __flags.flags (), __err);
 
     return __begin;
 }
@@ -122,39 +95,7 @@
     long __tmp = long (__val);
 
     __begin = do_get (__begin, __end, __flags, __err, __tmp);
-
-#if _RWSTD_INT_MAX < _RWSTD_LONG_MAX
-
-    long __int_min;
-    long __int_max;
-
-    if (   __tmp < 0
-        || (__flags.flags () & _RWSTD_IOS_BASEFIELD) == _RWSTD_IOS_DEC) {
-        // decimal parsing overflows outside the range below
-        __int_max = long (_RWSTD_INT_MAX);
-        __int_min = long (_RWSTD_INT_MIN);
-    }
-    else {
-        // other than decimal parsing overflows outside the range below
-        // (unreliable if basefield is 0 and the sequence is decimal)
-        __int_max = long (_RWSTD_UINT_MAX);
-        __int_min = long (_RWSTD_UINT_MIN);
-    }
-
-    // lwg issue 23: check for overflow
-    if (__tmp < __int_min) {
-        __err |= _RW::__rw_failbit;
-        __val  = _RWSTD_INT_MIN;
-    }
-    else if (__tmp > __int_max) {
-        __err |= _RW::__rw_failbit;
-        __val  = _RWSTD_INT_MAX;
-    }
-    else
-
-#endif   // _RWSTD_INT_MAX < _RWSTD_LONG_MAX
-
-        __val = _RWSTD_STATIC_CAST (int, __tmp);
+    __val = __rw_check_overflow_int (__tmp, __flags.flags (), __err);
 
     return __begin;
 }

Modified: stdcxx/trunk/include/loc/_num_get.h
URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/loc/_num_get.h?rev=638369&r1=638368&r2=638369&view=diff
==============================================================================
--- stdcxx/trunk/include/loc/_num_get.h (original)
+++ stdcxx/trunk/include/loc/_num_get.h Tue Mar 18 07:09:17 2008
@@ -259,6 +259,87 @@
 }   // namespace std
 
 
+_RWSTD_NAMESPACE (__rw) { 
+
+inline short
+__rw_check_overflow_short (long __lval, _RWSTD_FMTFLAGS __flags,
+                           _RWSTD_IOSTATE &__err)
+{
+#if _RWSTD_SHRT_MAX < _RWSTD_LONG_MAX
+
+    long __shrt_min;
+    long __shrt_max;
+
+    if (   __lval < 0
+        || (__flags & _RW::__rw_basefield) == _RW::__rw_dec) {
+        // decimal parsing overflows outside the range below
+        __shrt_max = long (_RWSTD_SHRT_MAX);
+        __shrt_min = long (_RWSTD_SHRT_MIN);
+    }
+    else {
+        // other than decimal parsing overflows outside the range below
+        // (unreliable if basefield is 0 and the sequence is decimal)
+        __shrt_max = long (_RWSTD_USHRT_MAX);
+        __shrt_min = long (_RWSTD_USHRT_MIN);
+    }
+
+    // lwg issue 23: check for overflow
+    if (__lval < __shrt_min) {
+        __err |= _RW::__rw_failbit;
+        return short (_RWSTD_SHRT_MIN);
+    }
+    else if (__lval > __shrt_max) {
+        __err |= _RW::__rw_failbit;
+        return short (_RWSTD_SHRT_MAX);
+    }
+    else
+
+#endif   // _RWSTD_SHRT_MAX < _RWSTD_LONG_MAX
+
+        return _RWSTD_STATIC_CAST (short, __lval);
+}
+
+inline int
+__rw_check_overflow_int (long __lval, _RWSTD_FMTFLAGS __flags,
+                         _RWSTD_IOSTATE &__err)
+{
+#if _RWSTD_INT_MAX < _RWSTD_LONG_MAX
+
+    long __int_min;
+    long __int_max;
+
+    if (   __lval < 0
+        || (__flags & _RW::__rw_basefield) == _RW::__rw_dec) {
+        // decimal parsing overflows outside the range below
+        __int_max = long (_RWSTD_INT_MAX);
+        __int_min = long (_RWSTD_INT_MIN);
+    }
+    else {
+        // other than decimal parsing overflows outside the range below
+        // (unreliable if basefield is 0 and the sequence is decimal)
+        __int_max = long (_RWSTD_UINT_MAX);
+        __int_min = long (_RWSTD_UINT_MIN);
+    }
+
+    // lwg issue 23: check for overflow
+    if (__lval < __int_min) {
+        __err |= _RW::__rw_failbit;
+        return int (_RWSTD_INT_MIN);
+    }
+    else if (__lval > __int_max) {
+        __err |= _RW::__rw_failbit;
+        return = int (_RWSTD_INT_MAX);
+    }
+    else
+
+#endif   // _RWSTD_INT_MAX < _RWSTD_LONG_MAX
+
+        return _RWSTD_STATIC_CAST (int, __lval);
+}
+
+}   // namespace __rw
+
+
 #if _RWSTD_DEFINE_TEMPLATE_FIRST (_NUM_GET)
 #  include <loc/_num_get.cc>
 #endif   // _RWSTD_DEFINE_TEMPLATE_FIRST (_NUM_GET)

Modified: stdcxx/trunk/include/rw/_iosfwd.h
URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/rw/_iosfwd.h?rev=638369&r1=638368&r2=638369&view=diff
==============================================================================
--- stdcxx/trunk/include/rw/_iosfwd.h (original)
+++ stdcxx/trunk/include/rw/_iosfwd.h Tue Mar 18 07:09:17 2008
@@ -88,7 +88,8 @@
 
 
 // used in money_get and num_get facets
-#define _RWSTD_IOSTATE _RWSTD_BITMASK_ENUM (_RW::__rw_iostate)
+#define _RWSTD_IOSTATE  _RWSTD_BITMASK_ENUM (_RW::__rw_iostate)
+#define _RWSTD_FMTFLAGS _RWSTD_BITMASK_ENUM (_RW::__rw_fmtflags)
 
 
 _RWSTD_NAMESPACE (__rw) {



RE: svn commit: r638369 - in /stdcxx/trunk/include: loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Monday, March 24, 2008 4:41 PM
> To: dev@stdcxx.apache.org
> Subject: Re: svn commit: r638369 - in /stdcxx/trunk/include: 
> loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h
> 
> Farid Zaripov wrote:
> >   I have tested on MSVC 7.1 and found no problems. The
> > __rw_check_overflow_{short|int}()
> > are not exported from library and can't be called directly, only 
> > through num_get<>::get().
> 
> I assume you tested with both debug and optimized shared lib builds.

  I tested 15d and 15s builds on both MSVC and gcc.

  Let me check the optimized builds also.

Farid.

Re: svn commit: r638369 - in /stdcxx/trunk/include: loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Martin Sebor [mailto:sebor@roguewave.com] 
>> Sent: Wednesday, March 19, 2008 6:46 PM
>> To: dev@stdcxx.apache.org
>> Subject: Re: svn commit: r638369 - in /stdcxx/trunk/include: 
>> loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h
>>
>>> URL: http://svn.apache.org/viewvc?rev=638369&view=rev
>>> Log:
>>> 2008-03-18  Farid Zaripov  <fa...@epam.com>
>>>
>>> 	* include/loc/_num_get.cc (num_get::get): Code checking 
>> for overflow moved from here...
>>> 	* include/loc/num_get.h 
>> (_rw_check_overflow_{short|int}): ... to here.
>>> 	* include/rw/_iosfwd.h: Added new define 
>> _RWSTD_FMTFLAGS (used in _rw_check_overflow_{short|int}).
>>
>> It occurs to me: is this forward binary compatible? We're 
>> adding a function in this patch, even though it's inline, I 
>> suspect that in debug builds (w/o inlining) this will break 
>> when we replace 4.2.1 with 4.2.0. Have you tested it?
> 
>   I have tested on MSVC 7.1 and found no problems. The
> __rw_check_overflow_{short|int}()
> are not exported from library and can't be called directly, only through
> num_get<>::get().

I assume you tested with both debug and optimized shared lib
builds.

> 
>   Also I have tested on gcc/Linux and found no problems in forward and
> backward compatibility.

That's interesting. If this is true on other platforms it would
mean a lot more flexibility in terms of what changes can go in
a patch release. Let's try to test this on other platforms so
we can make a policy decision for 4.2.1 and beyond.

Martin

RE: svn commit: r638369 - in /stdcxx/trunk/include: loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com] 
> Sent: Wednesday, March 19, 2008 6:46 PM
> To: dev@stdcxx.apache.org
> Subject: Re: svn commit: r638369 - in /stdcxx/trunk/include: 
> loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h
> 
> > URL: http://svn.apache.org/viewvc?rev=638369&view=rev
> > Log:
> > 2008-03-18  Farid Zaripov  <fa...@epam.com>
> > 
> > 	* include/loc/_num_get.cc (num_get::get): Code checking 
> for overflow moved from here...
> > 	* include/loc/num_get.h 
> (_rw_check_overflow_{short|int}): ... to here.
> > 	* include/rw/_iosfwd.h: Added new define 
> _RWSTD_FMTFLAGS (used in _rw_check_overflow_{short|int}).
> 
> It occurs to me: is this forward binary compatible? We're 
> adding a function in this patch, even though it's inline, I 
> suspect that in debug builds (w/o inlining) this will break 
> when we replace 4.2.1 with 4.2.0. Have you tested it?

  I have tested on MSVC 7.1 and found no problems. The
__rw_check_overflow_{short|int}()
are not exported from library and can't be called directly, only through
num_get<>::get().

  Also I have tested on gcc/Linux and found no problems in forward and
backward compatibility.

Farid.

Re: svn commit: r638369 - in /stdcxx/trunk/include: loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h

Posted by Martin Sebor <se...@roguewave.com>.
faridz@apache.org wrote:
> Author: faridz
> Date: Tue Mar 18 07:09:17 2008
> New Revision: 638369
> 
> URL: http://svn.apache.org/viewvc?rev=638369&view=rev
> Log:
> 2008-03-18  Farid Zaripov  <fa...@epam.com>
> 
> 	* include/loc/_num_get.cc (num_get::get): Code checking for overflow moved from here...
> 	* include/loc/num_get.h (_rw_check_overflow_{short|int}): ... to here.
> 	* include/rw/_iosfwd.h: Added new define _RWSTD_FMTFLAGS (used in _rw_check_overflow_{short|int}).

It occurs to me: is this forward binary compatible? We're
adding a function in this patch, even though it's inline,
I suspect that in debug builds (w/o inlining) this will
break when we replace 4.2.1 with 4.2.0. Have you tested
it?

Martin

> 
> Modified:
>     stdcxx/trunk/include/loc/_num_get.cc
>     stdcxx/trunk/include/loc/_num_get.h
>     stdcxx/trunk/include/rw/_iosfwd.h
> 
> Modified: stdcxx/trunk/include/loc/_num_get.cc
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/loc/_num_get.cc?rev=638369&r1=638368&r2=638369&view=diff
> ==============================================================================
> --- stdcxx/trunk/include/loc/_num_get.cc (original)
> +++ stdcxx/trunk/include/loc/_num_get.cc Tue Mar 18 07:09:17 2008
> @@ -76,34 +76,7 @@
>      long __tmp = __val;
>  
>      __begin = do_get (__begin, __end, __flags, __err, __tmp);
> -
> -    long __shrt_min;
> -    long __shrt_max;
> -
> -    if (   __tmp < 0
> -        || (__flags.flags () & _RWSTD_IOS_BASEFIELD) == _RWSTD_IOS_DEC) {
> -        // decimal parsing overflows outside the range below
> -        __shrt_max = long (_RWSTD_SHRT_MAX);
> -        __shrt_min = long (_RWSTD_SHRT_MIN);
> -    }
> -    else {
> -        // other than decimal parsing overflows outside the range below
> -        // (unreliable if basefield is 0 and the sequence is decimal)
> -        __shrt_max = long (_RWSTD_USHRT_MAX);
> -        __shrt_min = long (_RWSTD_USHRT_MIN);
> -    }
> -
> -    // lwg issue 23: check for overflow
> -    if (__tmp < __shrt_min) {
> -        __err |= _RW::__rw_failbit;
> -        __val  = short (_RWSTD_SHRT_MIN);
> -    }
> -    else if (__tmp > __shrt_max) {
> -        __err |= _RW::__rw_failbit;
> -        __val  = short (_RWSTD_SHRT_MAX);
> -    }
> -    else
> -        __val = _RWSTD_STATIC_CAST (short, __tmp);
> +    __val = __rw_check_overflow_short (__tmp, __flags.flags (), __err);
>  
>      return __begin;
>  }
> @@ -122,39 +95,7 @@
>      long __tmp = long (__val);
>  
>      __begin = do_get (__begin, __end, __flags, __err, __tmp);
> -
> -#if _RWSTD_INT_MAX < _RWSTD_LONG_MAX
> -
> -    long __int_min;
> -    long __int_max;
> -
> -    if (   __tmp < 0
> -        || (__flags.flags () & _RWSTD_IOS_BASEFIELD) == _RWSTD_IOS_DEC) {
> -        // decimal parsing overflows outside the range below
> -        __int_max = long (_RWSTD_INT_MAX);
> -        __int_min = long (_RWSTD_INT_MIN);
> -    }
> -    else {
> -        // other than decimal parsing overflows outside the range below
> -        // (unreliable if basefield is 0 and the sequence is decimal)
> -        __int_max = long (_RWSTD_UINT_MAX);
> -        __int_min = long (_RWSTD_UINT_MIN);
> -    }
> -
> -    // lwg issue 23: check for overflow
> -    if (__tmp < __int_min) {
> -        __err |= _RW::__rw_failbit;
> -        __val  = _RWSTD_INT_MIN;
> -    }
> -    else if (__tmp > __int_max) {
> -        __err |= _RW::__rw_failbit;
> -        __val  = _RWSTD_INT_MAX;
> -    }
> -    else
> -
> -#endif   // _RWSTD_INT_MAX < _RWSTD_LONG_MAX
> -
> -        __val = _RWSTD_STATIC_CAST (int, __tmp);
> +    __val = __rw_check_overflow_int (__tmp, __flags.flags (), __err);
>  
>      return __begin;
>  }
> 
> Modified: stdcxx/trunk/include/loc/_num_get.h
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/loc/_num_get.h?rev=638369&r1=638368&r2=638369&view=diff
> ==============================================================================
> --- stdcxx/trunk/include/loc/_num_get.h (original)
> +++ stdcxx/trunk/include/loc/_num_get.h Tue Mar 18 07:09:17 2008
> @@ -259,6 +259,87 @@
>  }   // namespace std
>  
>  
> +_RWSTD_NAMESPACE (__rw) { 
> +
> +inline short
> +__rw_check_overflow_short (long __lval, _RWSTD_FMTFLAGS __flags,
> +                           _RWSTD_IOSTATE &__err)
> +{
> +#if _RWSTD_SHRT_MAX < _RWSTD_LONG_MAX
> +
> +    long __shrt_min;
> +    long __shrt_max;
> +
> +    if (   __lval < 0
> +        || (__flags & _RW::__rw_basefield) == _RW::__rw_dec) {
> +        // decimal parsing overflows outside the range below
> +        __shrt_max = long (_RWSTD_SHRT_MAX);
> +        __shrt_min = long (_RWSTD_SHRT_MIN);
> +    }
> +    else {
> +        // other than decimal parsing overflows outside the range below
> +        // (unreliable if basefield is 0 and the sequence is decimal)
> +        __shrt_max = long (_RWSTD_USHRT_MAX);
> +        __shrt_min = long (_RWSTD_USHRT_MIN);
> +    }
> +
> +    // lwg issue 23: check for overflow
> +    if (__lval < __shrt_min) {
> +        __err |= _RW::__rw_failbit;
> +        return short (_RWSTD_SHRT_MIN);
> +    }
> +    else if (__lval > __shrt_max) {
> +        __err |= _RW::__rw_failbit;
> +        return short (_RWSTD_SHRT_MAX);
> +    }
> +    else
> +
> +#endif   // _RWSTD_SHRT_MAX < _RWSTD_LONG_MAX
> +
> +        return _RWSTD_STATIC_CAST (short, __lval);
> +}
> +
> +inline int
> +__rw_check_overflow_int (long __lval, _RWSTD_FMTFLAGS __flags,
> +                         _RWSTD_IOSTATE &__err)
> +{
> +#if _RWSTD_INT_MAX < _RWSTD_LONG_MAX
> +
> +    long __int_min;
> +    long __int_max;
> +
> +    if (   __lval < 0
> +        || (__flags & _RW::__rw_basefield) == _RW::__rw_dec) {
> +        // decimal parsing overflows outside the range below
> +        __int_max = long (_RWSTD_INT_MAX);
> +        __int_min = long (_RWSTD_INT_MIN);
> +    }
> +    else {
> +        // other than decimal parsing overflows outside the range below
> +        // (unreliable if basefield is 0 and the sequence is decimal)
> +        __int_max = long (_RWSTD_UINT_MAX);
> +        __int_min = long (_RWSTD_UINT_MIN);
> +    }
> +
> +    // lwg issue 23: check for overflow
> +    if (__lval < __int_min) {
> +        __err |= _RW::__rw_failbit;
> +        return int (_RWSTD_INT_MIN);
> +    }
> +    else if (__lval > __int_max) {
> +        __err |= _RW::__rw_failbit;
> +        return = int (_RWSTD_INT_MAX);
> +    }
> +    else
> +
> +#endif   // _RWSTD_INT_MAX < _RWSTD_LONG_MAX
> +
> +        return _RWSTD_STATIC_CAST (int, __lval);
> +}
> +
> +}   // namespace __rw
> +
> +
>  #if _RWSTD_DEFINE_TEMPLATE_FIRST (_NUM_GET)
>  #  include <loc/_num_get.cc>
>  #endif   // _RWSTD_DEFINE_TEMPLATE_FIRST (_NUM_GET)
> 
> Modified: stdcxx/trunk/include/rw/_iosfwd.h
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/rw/_iosfwd.h?rev=638369&r1=638368&r2=638369&view=diff
> ==============================================================================
> --- stdcxx/trunk/include/rw/_iosfwd.h (original)
> +++ stdcxx/trunk/include/rw/_iosfwd.h Tue Mar 18 07:09:17 2008
> @@ -88,7 +88,8 @@
>  
>  
>  // used in money_get and num_get facets
> -#define _RWSTD_IOSTATE _RWSTD_BITMASK_ENUM (_RW::__rw_iostate)
> +#define _RWSTD_IOSTATE  _RWSTD_BITMASK_ENUM (_RW::__rw_iostate)
> +#define _RWSTD_FMTFLAGS _RWSTD_BITMASK_ENUM (_RW::__rw_fmtflags)
>  
>  
>  _RWSTD_NAMESPACE (__rw) {
> 
> 


RE: svn commit: r638369 - in /stdcxx/trunk/include: loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Tuesday, March 18, 2008 6:12 PM
> To: dev@stdcxx.apache.org
> Subject: Re: svn commit: r638369 - in /stdcxx/trunk/include: 
> loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h
> 
> > +        return = int (_RWSTD_INT_MAX);
>             ^^^^^^^^^^^^
> 
> This looks like a typo (I'm getting a build error).

  I've tested the patched sources on MSVC and gcc/linux and
didn't found this bug due to _RWSTD_INT_MAX == _RWSTD_LONG_MAX
on these compilers.

  Fixed: http://svn.apache.org/viewvc?rev=638433&view=rev

Farid.

Re: svn commit: r638369 - in /stdcxx/trunk/include: loc/_num_get.cc loc/_num_get.h rw/_iosfwd.h

Posted by Martin Sebor <se...@roguewave.com>.
faridz@apache.org wrote:
> Author: faridz
> Date: Tue Mar 18 07:09:17 2008
> New Revision: 638369
> 
[...]
> Modified: stdcxx/trunk/include/loc/_num_get.h
> URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/loc/_num_get.h?rev=638369&r1=638368&r2=638369&view=diff
> ==============================================================================
> --- stdcxx/trunk/include/loc/_num_get.h (original)
> +++ stdcxx/trunk/include/loc/_num_get.h Tue Mar 18 07:09:17 2008
> @@ -259,6 +259,87 @@
[...]
> +    else if (__lval > __int_max) {
> +        __err |= _RW::__rw_failbit;
> +        return = int (_RWSTD_INT_MAX);
            ^^^^^^^^^^^^

This looks like a typo (I'm getting a build error).

Martin