Merge lp:~timo-jyrinki/ubuntu/saucy/qtbase-opensource-src/fix_number_precision into lp:ubuntu/saucy/qtbase-opensource-src

Proposed by Timo Jyrinki
Status: Merged
Merge reported by: Sebastien Bacher
Merged at revision: not available
Proposed branch: lp:~timo-jyrinki/ubuntu/saucy/qtbase-opensource-src/fix_number_precision
Merge into: lp:ubuntu/saucy/qtbase-opensource-src
Diff against target: 174 lines (+151/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/fix_number_precision_qjsondocument.patch_8e8becdc.patch (+143/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~timo-jyrinki/ubuntu/saucy/qtbase-opensource-src/fix_number_precision
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+173442@code.launchpad.net

Commit message

* debian/patches/fix_number_precision_qjsondocument.patch_8e8becdc.patch:
  - Cherry-pick from upstream (LP: #1181359)

Description of the change

* debian/patches/fix_number_precision_qjsondocument.patch_8e8becdc.patch:
  - Cherry-pick from upstream (LP: #1181359)

Tested successfully in the bug report.

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-06-27 16:29:34 +0000
3+++ debian/changelog 2013-07-08 08:58:31 +0000
4@@ -1,3 +1,10 @@
5+qtbase-opensource-src (5.0.2+dfsg1-7ubuntu2) UNRELEASED; urgency=low
6+
7+ * debian/patches/fix_number_precision_qjsondocument.patch_8e8becdc.patch:
8+ - Cherry-pick from upstream (LP: #1181359)
9+
10+ -- Timo Jyrinki <timo-jyrinki@ubuntu.com> Thu, 06 Jun 2013 15:15:57 +0300
11+
12 qtbase-opensource-src (5.0.2+dfsg1-7ubuntu1) saucy; urgency=low
13
14 * Merge with Debian experimental, remaining changes:
15
16=== added file 'debian/patches/fix_number_precision_qjsondocument.patch_8e8becdc.patch'
17--- debian/patches/fix_number_precision_qjsondocument.patch_8e8becdc.patch 1970-01-01 00:00:00 +0000
18+++ debian/patches/fix_number_precision_qjsondocument.patch_8e8becdc.patch 2013-07-08 08:58:31 +0000
19@@ -0,0 +1,143 @@
20+From 1ac1ec2a823222e0d130552a4c0da6068e8becdc Mon Sep 17 00:00:00 2001
21+From: Liang Qi <liang.qi@digia.com>
22+Date: Tue, 14 May 2013 14:19:47 +0200
23+Subject: [PATCH] QtCore: fix the number precision in QJsonDocument.toJson()
24+
25+In JSON, any number is stored in double. We need to make sure we
26+keep the maximum possible number precision for integer number. In
27+IEEE 754 double format, the significand precision is 53 bits(52
28+explicityly stored).
29+
30+Autotest is included. qint64 and double work fine.
31+
32+Task-number: QTBUG-28467
33+Change-Id: I7f857671c50e4334e9329c778f9b4f090f490540
34+---
35+ src/corelib/json/qjsonwriter.cpp | 2 +-
36+ tests/auto/corelib/json/tst_qtjson.cpp | 77 ++++++++++++++++++++++++++++------
37+ 2 files changed, 66 insertions(+), 13 deletions(-)
38+
39+diff --git a/src/corelib/json/qjsonwriter.cpp b/src/corelib/json/qjsonwriter.cpp
40+index 76f6224..b09c6dd 100644
41+--- a/src/corelib/json/qjsonwriter.cpp
42++++ b/src/corelib/json/qjsonwriter.cpp
43+@@ -170,7 +170,7 @@ static void valueToJson(const QJsonPrivate::Base *b, const QJsonPrivate::Value &
44+ json += v.toBoolean() ? "true" : "false";
45+ break;
46+ case QJsonValue::Double:
47+- json += QByteArray::number(v.toDouble(b));
48++ json += QByteArray::number(v.toDouble(b), 'g', 13);
49+ break;
50+ case QJsonValue::String:
51+ json += '"';
52+diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
53+index 6811551..fc4b383 100644
54+--- a/tests/auto/corelib/json/tst_qtjson.cpp
55++++ b/tests/auto/corelib/json/tst_qtjson.cpp
56+@@ -231,9 +231,54 @@ void tst_QtJson::testNumbers()
57+ QJsonArray array;
58+ for (int i = 0; i < n; ++i)
59+ array.append((double)numbers[i]);
60++
61++ QByteArray serialized = QJsonDocument(array).toJson();
62++ QJsonDocument json = QJsonDocument::fromJson(serialized);
63++ QJsonArray array2 = json.array();
64++
65++ QCOMPARE(array.size(), array2.size());
66++ for (int i = 0; i < array.size(); ++i) {
67++ QCOMPARE(array.at(i).type(), QJsonValue::Double);
68++ QCOMPARE(array.at(i).toDouble(), (double)numbers[i]);
69++ QCOMPARE(array2.at(i).type(), QJsonValue::Double);
70++ QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]);
71++ }
72++ }
73++
74++ {
75++ qint64 numbers[] = {
76++ 0,
77++ -1,
78++ 1,
79++ (1UL<<54),
80++ (1UL<<55),
81++ (1UL<<56),
82++ -(1UL<<54),
83++ -(1UL<<55),
84++ -(1UL<<56),
85++ (1UL<<54) - 1,
86++ (1UL<<55) - 1,
87++ (1UL<<56) - 1,
88++ -((1UL<<54) - 1),
89++ -((1UL<<55) - 1),
90++ -((1UL<<56) - 1)
91++ };
92++ int n = sizeof(numbers)/sizeof(qint64);
93++
94++ QJsonArray array;
95++ for (int i = 0; i < n; ++i)
96++ array.append((double)numbers[i]);
97++
98++ QByteArray serialized = QJsonDocument(array).toJson();
99++ QJsonDocument json = QJsonDocument::fromJson(serialized);
100++ QJsonArray array2 = json.array();
101++
102++ QCOMPARE(array.size(), array2.size());
103+ for (int i = 0; i < array.size(); ++i) {
104+ QCOMPARE(array.at(i).type(), QJsonValue::Double);
105+ QCOMPARE(array.at(i).toDouble(), (double)numbers[i]);
106++ QCOMPARE(array2.at(i).type(), QJsonValue::Double);
107++ QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]);
108+ }
109+ }
110+
111+@@ -242,18 +287,18 @@ void tst_QtJson::testNumbers()
112+ 0,
113+ -1,
114+ 1,
115+- (1<<26),
116+- (1<<27),
117+- (1<<28),
118+- -(1<<26),
119+- -(1<<27),
120+- -(1<<28),
121+- (1<<26) - 1,
122+- (1<<27) - 1,
123+- (1<<28) - 1,
124+- -((1<<26) - 1),
125+- -((1<<27) - 1),
126+- -((1<<28) - 1),
127++ (1UL<<54),
128++ (1UL<<55),
129++ (1UL<<56),
130++ -(1UL<<54),
131++ -(1UL<<55),
132++ -(1UL<<56),
133++ (1UL<<54) - 1,
134++ (1UL<<55) - 1,
135++ (1UL<<56) - 1,
136++ -((1UL<<54) - 1),
137++ -((1UL<<55) - 1),
138++ -((1UL<<56) - 1),
139+ 1.1,
140+ 0.1,
141+ -0.1,
142+@@ -266,9 +311,17 @@ void tst_QtJson::testNumbers()
143+ QJsonArray array;
144+ for (int i = 0; i < n; ++i)
145+ array.append(numbers[i]);
146++
147++ QByteArray serialized = QJsonDocument(array).toJson();
148++ QJsonDocument json = QJsonDocument::fromJson(serialized);
149++ QJsonArray array2 = json.array();
150++
151++ QCOMPARE(array.size(), array2.size());
152+ for (int i = 0; i < array.size(); ++i) {
153+ QCOMPARE(array.at(i).type(), QJsonValue::Double);
154+ QCOMPARE(array.at(i).toDouble(), numbers[i]);
155++ QCOMPARE(array2.at(i).type(), QJsonValue::Double);
156++ QCOMPARE(array2.at(i).toDouble(), numbers[i]);
157+ }
158+ }
159+
160+--
161+1.8.3
162+
163
164=== modified file 'debian/patches/series'
165--- debian/patches/series 2013-06-27 16:29:34 +0000
166+++ debian/patches/series 2013-07-08 08:58:31 +0000
167@@ -6,6 +6,7 @@
168 add_since_52_to_new_QColor_features.patch
169 inputmethod_fix_focusout.patch
170 Rename-qAbs-Function-for-timeval.patch
171+fix_number_precision_qjsondocument.patch_8e8becdc.patch
172
173 # Debian specific.
174 build_examples.patch

Subscribers

People subscribed via source and target branches

to all changes: