Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 11134
Merged at revision: 11306
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 208 lines (+61/-27)
7 files modified
src/runtime/random/random_impl.cpp (+2/-3)
src/unit_tests/test_time.cpp (+1/-1)
src/util/stl_util.h (+24/-10)
src/util/time_parse.cpp (+12/-12)
src/zorbatypes/floatimpl.h (+7/-0)
src/zorbatypes/numconversions.cpp (+6/-0)
src/zorbatypes/numconversions.h (+9/-1)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+155038@code.launchpad.net

Commit message

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

Description of the change

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

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2013-03-22T19-26-47.183Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2013-03-22T21-57-38.259Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/runtime/random/random_impl.cpp'
2--- src/runtime/random/random_impl.cpp 2013-02-07 17:24:36 +0000
3+++ src/runtime/random/random_impl.cpp 2013-03-22 19:09:23 +0000
4@@ -70,9 +70,8 @@
5
6 try
7 {
8- int_seed = static_cast<unsigned int>(
9- to_xs_int( seed->getIntegerValue() ) );
10- } catch (std::range_error& /*e*/)
11+ int_seed = static_cast<unsigned>( to_xs_int( seed->getIntegerValue() ) );
12+ } catch (std::range_error const&)
13 {
14 throw XQUERY_EXCEPTION(
15 zerr::ZXQD0004_INVALID_PARAMETER,
16
17=== modified file 'src/unit_tests/test_time.cpp'
18--- src/unit_tests/test_time.cpp 2013-03-20 15:26:41 +0000
19+++ src/unit_tests/test_time.cpp 2013-03-22 19:09:23 +0000
20@@ -90,7 +90,7 @@
21 /* 30 */ { 3, time::jan, 2010, calendar::ISO, 53 },
22 /* 31 */ { 4, time::jan, 2010, calendar::ISO, 1 },
23
24- { 0 },
25+ { 0, 0, 0, calendar::unknown, 0 }
26 };
27
28 for ( test_type const *t = test; t->mday; ++t ) {
29
30=== modified file 'src/util/stl_util.h'
31--- src/util/stl_util.h 2013-02-28 11:15:32 +0000
32+++ src/util/stl_util.h 2013-03-22 19:09:23 +0000
33@@ -436,22 +436,29 @@
34 //
35
36 template<typename N1,typename N2> inline
37-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
38- && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
39+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
40+ ZORBA_TR1_NS::is_floating_point<N1>::value)
41+ && (ZORBA_TR1_NS::is_signed<N2>::value ||
42+ ZORBA_TR1_NS::is_floating_point<N2>::value),
43+ bool>::type
44 ge_min( N1 n1, N2 ) {
45 return n1 >= std::numeric_limits<N2>::min();
46 }
47
48 template<typename N1,typename N2> inline
49-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
50- && !!ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
51+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
52+ ZORBA_TR1_NS::is_floating_point<N1>::value)
53+ && !!ZORBA_TR1_NS::is_unsigned<N2>::value,
54+ bool>::type
55 ge_min( N1 n1, N2 ) {
56 return n1 >= 0;
57 }
58
59 template<typename N1,typename N2> inline
60 typename std::enable_if<!!ZORBA_TR1_NS::is_unsigned<N1>::value
61- && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
62+ && (ZORBA_TR1_NS::is_signed<N2>::value ||
63+ ZORBA_TR1_NS::is_floating_point<N2>::value),
64+ bool>::type
65 ge_min( N1, N2 ) {
66 return true;
67 }
68@@ -464,22 +471,29 @@
69 }
70
71 template<typename N1,typename N2> inline
72-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
73- && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
74+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
75+ ZORBA_TR1_NS::is_floating_point<N1>::value)
76+ && (ZORBA_TR1_NS::is_signed<N2>::value ||
77+ ZORBA_TR1_NS::is_floating_point<N2>::value),
78+ bool>::type
79 le_max( N1 n1, N2 ) {
80 return n1 <= std::numeric_limits<N2>::max();
81 }
82
83 template<typename N1,typename N2> inline
84-typename std::enable_if<ZORBA_TR1_NS::is_signed<N1>::value
85- && !!ZORBA_TR1_NS::is_unsigned<N2>::value,bool>::type
86+typename std::enable_if<(ZORBA_TR1_NS::is_signed<N1>::value ||
87+ ZORBA_TR1_NS::is_floating_point<N1>::value)
88+ && !!ZORBA_TR1_NS::is_unsigned<N2>::value,
89+ bool>::type
90 le_max( N1 n1, N2 ) {
91 return n1 <= 0 || static_cast<N2>( n1 ) <= std::numeric_limits<N2>::max();
92 }
93
94 template<typename N1,typename N2> inline
95 typename std::enable_if<!!ZORBA_TR1_NS::is_unsigned<N1>::value
96- && ZORBA_TR1_NS::is_signed<N2>::value,bool>::type
97+ && (ZORBA_TR1_NS::is_signed<N2>::value ||
98+ ZORBA_TR1_NS::is_floating_point<N2>::value),
99+ bool>::type
100 le_max( N1 n1, N2 ) {
101 return n1 <= static_cast<N1>( std::numeric_limits<N2>::max() );
102 }
103
104=== modified file 'src/util/time_parse.cpp'
105--- src/util/time_parse.cpp 2013-01-10 01:53:57 +0000
106+++ src/util/time_parse.cpp 2013-03-22 19:09:23 +0000
107@@ -170,18 +170,18 @@
108 // Time."
109 //
110 static rfc2822_obs_zone const rfc2822_obs_zones[] = {
111- { "GMT", 0 },
112- { "UTC", 0 }, // non-RFC: be liberal in what you accept....
113- { "UT" , 0 }, // must go after "UTC"
114- { "EDT", -4 * 60 * 60, true },
115- { "EST", -5 * 60 * 60 },
116- { "CDT", -5 * 60 * 60, true },
117- { "CST", -6 * 60 * 60 },
118- { "MDT", -6 * 60 * 60, true },
119- { "MST", -7 * 60 * 60 },
120- { "PDT", -7 * 60 * 60, true },
121- { "PST", -8 * 60 * 60 },
122- { 0, 0, 0 }
123+ { "GMT", 0 , false },
124+ { "UTC", 0 , false }, // non-RFC: be liberal in what you accept....
125+ { "UT" , 0 , false }, // must go after "UTC"
126+ { "EDT", -4 * 60 * 60, true },
127+ { "EST", -5 * 60 * 60, false },
128+ { "CDT", -5 * 60 * 60, true },
129+ { "CST", -6 * 60 * 60, false },
130+ { "MDT", -6 * 60 * 60, true },
131+ { "MST", -7 * 60 * 60, false },
132+ { "PDT", -7 * 60 * 60, true },
133+ { "PST", -8 * 60 * 60, false },
134+ { 0, 0, false }
135 };
136
137 ///////////////////////////////////////////////////////////////////////////////
138
139=== modified file 'src/zorbatypes/floatimpl.h'
140--- src/zorbatypes/floatimpl.h 2013-02-07 17:24:36 +0000
141+++ src/zorbatypes/floatimpl.h 2013-03-22 19:09:23 +0000
142@@ -256,6 +256,8 @@
143
144 uint32_t hash() const;
145
146+ bool is_xs_int() const;
147+
148 bool isNaN() const;
149 bool isFinite() const;
150 bool isPosInf() const;
151@@ -935,6 +937,11 @@
152 }
153
154 template<typename F>
155+inline bool FloatImpl<F>::is_xs_int() const {
156+ return ZORBA_IN_RANGE( value_, xs_int );
157+}
158+
159+template<typename F>
160 inline bool FloatImpl<F>::isNeg() const {
161 return value_ < 0;
162 }
163
164=== modified file 'src/zorbatypes/numconversions.cpp'
165--- src/zorbatypes/numconversions.cpp 2013-02-07 17:24:36 +0000
166+++ src/zorbatypes/numconversions.cpp 2013-03-22 19:09:23 +0000
167@@ -29,8 +29,14 @@
168 std::range_error( BUILD_STRING( '"', (N), "\": number can not be represented as an " TYPE ) )
169
170 xs_int to_xs_int( xs_double const &d ) {
171+#ifdef ZORBA_WITH_BIG_INTEGER
172 zstring const temp( d.toIntegerString() );
173 return ztd::aton<xs_int>( temp.c_str() );
174+#else
175+ if ( d.is_xs_int() )
176+ return static_cast<xs_int>( d.getNumber() );
177+ throw RANGE_ERROR( d, "xs:int" );
178+#endif /* ZORBA_WITH_BIG_INTEGER */
179 }
180
181 xs_int to_xs_int( xs_integer const &i ) {
182
183=== modified file 'src/zorbatypes/numconversions.h'
184--- src/zorbatypes/numconversions.h 2013-02-07 17:24:36 +0000
185+++ src/zorbatypes/numconversions.h 2013-03-22 19:09:23 +0000
186@@ -29,7 +29,7 @@
187 *
188 * @param d The \c xs:double value to convert.
189 * @return Returns said value.
190- * @throws std::range_error if the \c xs:double value can not be accurately
191+ * @throws std::range_error if \c floor(xs:double) value can not be accurately
192 * represented as an \c xs:int.
193 */
194 xs_int to_xs_int( xs_double const &d );
195@@ -65,6 +65,14 @@
196 xs_long to_xs_long( xs_integer const &i );
197
198 #ifndef ZORBA_WITH_BIG_INTEGER
199+/**
200+ * Converts an \c xs:nonNegativeInteger value to an \c xs:long.
201+ *
202+ * @param i The \c xs:nonNegativeInteger value to convert.
203+ * @return Returns said value.
204+ * @throws std::range_error if the \c xs:nonNegativeInteger value can not be
205+ * accurately represented as an \c xs:long.
206+ */
207 xs_long to_xs_long( xs_nonNegativeInteger const &i );
208 #endif /* ZORBA_WITH_BIG_INTEGER */
209

Subscribers

People subscribed via source and target branches