Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
* Added over-flow check for to_xs_int().
* Fixed warnings.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/155038

* Added over-flow check for to_xs_int().
* Fixed warnings.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/155038
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/random/random_impl.cpp'
--- src/runtime/random/random_impl.cpp	2013-02-07 17:24:36 +0000
+++ src/runtime/random/random_impl.cpp	2013-03-22 19:09:23 +0000
@@ -70,9 +70,8 @@
 
     try
     {
-      int_seed = static_cast<unsigned int>(
-          to_xs_int( seed->getIntegerValue() ) );
-    } catch (std::range_error& /*e*/)
+      int_seed = static_cast<unsigned>( to_xs_int( seed->getIntegerValue() ) );
+    } catch (std::range_error const&)
     {
       throw XQUERY_EXCEPTION(
           zerr::ZXQD0004_INVALID_PARAMETER,

=== modified file 'src/unit_tests/test_time.cpp'
--- src/unit_tests/test_time.cpp	2013-03-20 15:26:41 +0000
+++ src/unit_tests/test_time.cpp	2013-03-22 19:09:23 +0000
@@ -90,7 +90,7 @@
     /* 30 */ {  3, time::jan, 2010, calendar::ISO, 53 },
     /* 31 */ {  4, time::jan, 2010, calendar::ISO,  1 },
 
-    {  0 },
+    { 0, 0, 0, calendar::unknown, 0 }
   };
 
   for ( test_type const *t = test; t->mday; ++t ) {

=== modified file 'src/util/stl_util.h'
--- src/util/stl_util.h	2013-02-28 11:15:32 +0000
+++ src/util/stl_util.h	2013-03-22 19:09:23 +0000
@@ -436,22 +436,29 @@
 //
 
 template<typename N1,typename N2> inline
-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
-                     && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N1>::value)
+                     && (ZORBA_TR1_NS::is_signed<N2>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N2>::value),
+                        bool>::type
 ge_min( N1 n1, N2 ) {
   return n1 >= std::numeric_limits<N2>::min();
 }
 
 template<typename N1,typename N2> inline
-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
-                     && !!ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N1>::value)
+                     && !!ZORBA_TR1_NS::is_unsigned<N2>::value,
+                         bool>::type
 ge_min( N1 n1, N2 ) {
   return n1 >= 0;
 }
 
 template<typename N1,typename N2> inline
 typename std::enable_if<!!ZORBA_TR1_NS::is_unsigned<N1>::value
-                     && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
+                     && (ZORBA_TR1_NS::is_signed<N2>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N2>::value),
+                        bool>::type
 ge_min( N1, N2 ) {
   return true;
 }
@@ -464,22 +471,29 @@
 }
 
 template<typename N1,typename N2> inline
-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
-                     && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N1>::value)
+                     && (ZORBA_TR1_NS::is_signed<N2>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N2>::value),
+                        bool>::type
 le_max( N1 n1, N2 ) {
   return n1 <= std::numeric_limits<N2>::max();
 }
 
 template<typename N1,typename N2> inline
-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
-                     && !!ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N1>::value)
+                     && !!ZORBA_TR1_NS::is_unsigned<N2>::value,
+                        bool>::type
 le_max( N1 n1, N2 ) {
   return n1 <= 0 || static_cast<N2>( n1 ) <= std::numeric_limits<N2>::max();
 }
 
 template<typename N1,typename N2> inline
 typename std::enable_if<!!ZORBA_TR1_NS::is_unsigned<N1>::value
-                     && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
+                     && (ZORBA_TR1_NS::is_signed<N2>::value ||
+                         ZORBA_TR1_NS::is_floating_point<N2>::value),
+                        bool>::type
 le_max( N1 n1, N2 ) {
   return n1 <= static_cast<N1>( std::numeric_limits<N2>::max() );
 }

=== modified file 'src/util/time_parse.cpp'
--- src/util/time_parse.cpp	2013-01-10 01:53:57 +0000
+++ src/util/time_parse.cpp	2013-03-22 19:09:23 +0000
@@ -170,18 +170,18 @@
 // Time."
 //
 static rfc2822_obs_zone const rfc2822_obs_zones[] = {
-  { "GMT",  0                 },
-  { "UTC",  0                 }, // non-RFC: be liberal in what you accept....
-  { "UT" ,  0                 }, // must go after "UTC"
-  { "EDT", -4 * 60 * 60, true },
-  { "EST", -5 * 60 * 60       },
-  { "CDT", -5 * 60 * 60, true },
-  { "CST", -6 * 60 * 60       },
-  { "MDT", -6 * 60 * 60, true },
-  { "MST", -7 * 60 * 60       },
-  { "PDT", -7 * 60 * 60, true },
-  { "PST", -8 * 60 * 60       },
-  { 0, 0, 0 }
+  { "GMT",  0          , false },
+  { "UTC",  0          , false }, // non-RFC: be liberal in what you accept....
+  { "UT" ,  0          , false }, // must go after "UTC"
+  { "EDT", -4 * 60 * 60, true  },
+  { "EST", -5 * 60 * 60, false },
+  { "CDT", -5 * 60 * 60, true  },
+  { "CST", -6 * 60 * 60, false },
+  { "MDT", -6 * 60 * 60, true  },
+  { "MST", -7 * 60 * 60, false },
+  { "PDT", -7 * 60 * 60, true  },
+  { "PST", -8 * 60 * 60, false },
+  { 0, 0, false }
 };
 
 ///////////////////////////////////////////////////////////////////////////////

=== modified file 'src/zorbatypes/floatimpl.h'
--- src/zorbatypes/floatimpl.h	2013-02-07 17:24:36 +0000
+++ src/zorbatypes/floatimpl.h	2013-03-22 19:09:23 +0000
@@ -256,6 +256,8 @@
 
   uint32_t hash() const;
 
+  bool is_xs_int() const;
+
   bool isNaN() const;
   bool isFinite() const;
   bool isPosInf() const;
@@ -935,6 +937,11 @@
 }
 
 template<typename F>
+inline bool FloatImpl<F>::is_xs_int() const {
+  return ZORBA_IN_RANGE( value_, xs_int );
+}
+
+template<typename F>
 inline bool FloatImpl<F>::isNeg() const {
   return value_ < 0;
 }

=== modified file 'src/zorbatypes/numconversions.cpp'
--- src/zorbatypes/numconversions.cpp	2013-02-07 17:24:36 +0000
+++ src/zorbatypes/numconversions.cpp	2013-03-22 19:09:23 +0000
@@ -29,8 +29,14 @@
   std::range_error( BUILD_STRING( '"', (N), "\": number can not be represented as an " TYPE ) )
 
 xs_int to_xs_int( xs_double const &d ) {
+#ifdef ZORBA_WITH_BIG_INTEGER
   zstring const temp( d.toIntegerString() );
   return ztd::aton<xs_int>( temp.c_str() );
+#else
+  if ( d.is_xs_int() )
+    return static_cast<xs_int>( d.getNumber() );
+  throw RANGE_ERROR( d, "xs:int" );
+#endif /* ZORBA_WITH_BIG_INTEGER */
 }
 
 xs_int to_xs_int( xs_integer const &i ) {

=== modified file 'src/zorbatypes/numconversions.h'
--- src/zorbatypes/numconversions.h	2013-02-07 17:24:36 +0000
+++ src/zorbatypes/numconversions.h	2013-03-22 19:09:23 +0000
@@ -29,7 +29,7 @@
  *
  * @param d The \c xs:double value to convert.
  * @return Returns said value.
- * @throws std::range_error if the \c xs:double value can not be accurately
+ * @throws std::range_error if \c floor(xs:double) value can not be accurately
  * represented as an \c xs:int.
  */
 xs_int to_xs_int( xs_double const &d );
@@ -65,6 +65,14 @@
 xs_long to_xs_long( xs_integer const &i );
 
 #ifndef ZORBA_WITH_BIG_INTEGER
+/**
+ * Converts an \c xs:nonNegativeInteger value to an \c xs:long.
+ *
+ * @param i The \c xs:nonNegativeInteger value to convert.
+ * @return Returns said value.
+ * @throws std::range_error if the \c xs:nonNegativeInteger value can not be
+ * accurately represented as an \c xs:long.
+ */
 xs_long to_xs_long( xs_nonNegativeInteger const &i );
 #endif /* ZORBA_WITH_BIG_INTEGER */
 

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to