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

Subscribers

People subscribed via source and target branches

to all changes: