Skip to content

Commit 04b306c

Browse files
laminowanythiagomacieira
authored andcommitted
Use internal linkage for data.cpp files
The Qt uses test batching and potentially encoder/data.cpp and parser/data.cpp can end up in the same translation unit. This can be problematic as they declare symbols with the same names. Change both files to use internal linkage in order to avoid symbols clashing.
1 parent aee4f97 commit 04b306c

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

tests/encoder/data.cpp

+29-26
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,29 @@
2424

2525
#include <QtTest>
2626

27-
static float myNaNf()
27+
struct NegativeInteger { quint64 abs; };
28+
Q_DECLARE_METATYPE(NegativeInteger)
29+
30+
struct SimpleType { uint8_t type; };
31+
Q_DECLARE_METATYPE(SimpleType)
32+
33+
struct Float16Standin { uint16_t val; };
34+
Q_DECLARE_METATYPE(Float16Standin)
35+
36+
struct Tag { CborTag tag; QVariant tagged; };
37+
Q_DECLARE_METATYPE(Tag)
38+
39+
typedef QVector<QPair<QVariant, QVariant>> Map;
40+
Q_DECLARE_METATYPE(Map)
41+
42+
struct IndeterminateLengthArray : QVariantList { using QVariantList::QVariantList; };
43+
struct IndeterminateLengthMap : Map { using Map::Map; };
44+
Q_DECLARE_METATYPE(IndeterminateLengthArray)
45+
Q_DECLARE_METATYPE(IndeterminateLengthMap)
46+
47+
namespace {
48+
49+
float myNaNf()
2850
{
2951
uint32_t v = 0x7fc00000;
3052
float f;
@@ -33,7 +55,7 @@ static float myNaNf()
3355
return f;
3456
}
3557

36-
static float myInff()
58+
float myInff()
3759
{
3860
uint32_t v = 0x7f800000;
3961
float f;
@@ -42,7 +64,7 @@ static float myInff()
4264
return f;
4365
}
4466

45-
static float myNInff()
67+
float myNInff()
4668
{
4769
uint32_t v = 0xff800000;
4870
float f;
@@ -51,7 +73,7 @@ static float myNInff()
5173
return f;
5274
}
5375

54-
static double myNaN()
76+
double myNaN()
5577
{
5678
uint64_t v = UINT64_C(0x7ff8000000000000);
5779
double f;
@@ -60,7 +82,7 @@ static double myNaN()
6082
return f;
6183
}
6284

63-
static double myInf()
85+
double myInf()
6486
{
6587
uint64_t v = UINT64_C(0x7ff0000000000000);
6688
double f;
@@ -69,7 +91,7 @@ static double myInf()
6991
return f;
7092
}
7193

72-
static double myNInf()
94+
double myNInf()
7395
{
7496
uint64_t v = UINT64_C(0xfff0000000000000);
7597
double f;
@@ -83,36 +105,17 @@ template <size_t N> QByteArray raw(const char (&data)[N])
83105
return QByteArray::fromRawData(data, N - 1);
84106
}
85107

86-
struct NegativeInteger { quint64 abs; };
87-
Q_DECLARE_METATYPE(NegativeInteger)
88-
89-
struct SimpleType { uint8_t type; };
90-
Q_DECLARE_METATYPE(SimpleType)
91-
92-
struct Float16Standin { uint16_t val; };
93-
Q_DECLARE_METATYPE(Float16Standin)
94-
95-
struct Tag { CborTag tag; QVariant tagged; };
96-
Q_DECLARE_METATYPE(Tag)
97-
98108
template <typename... Args>
99109
QVariant make_list(const Args &... args)
100110
{
101111
return QVariantList{args...};
102112
}
103113

104-
typedef QVector<QPair<QVariant, QVariant>> Map;
105-
Q_DECLARE_METATYPE(Map)
106114
QVariant make_map(const std::initializer_list<QPair<QVariant, QVariant>> &list)
107115
{
108116
return QVariant::fromValue(Map(list));
109117
}
110118

111-
struct IndeterminateLengthArray : QVariantList { using QVariantList::QVariantList; };
112-
struct IndeterminateLengthMap : Map { using Map::Map; };
113-
Q_DECLARE_METATYPE(IndeterminateLengthArray)
114-
Q_DECLARE_METATYPE(IndeterminateLengthMap)
115-
116119
QVariant make_ilarray(const std::initializer_list<QVariant> &list)
117120
{
118121
return QVariant::fromValue(IndeterminateLengthArray(list));
@@ -343,4 +346,4 @@ void addArraysAndMaps()
343346
QTest::newRow("array-1(map)") << raw("\x81\xc1\xa0") << make_list(QVariant::fromValue(Tag{1, make_map({})}));
344347
QTest::newRow("map-1(2):3(4)") << raw("\xa1\xc1\2\xc3\4") << make_map({{QVariant::fromValue(Tag{1, 2}), QVariant::fromValue(Tag{3, 4})}});
345348
}
346-
349+
} // namespace

tests/parser/data.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
Q_DECLARE_METATYPE(CborError)
3030

31+
namespace {
32+
3133
template <size_t N> QByteArray raw(const char (&data)[N])
3234
{
3335
return QByteArray::fromRawData(data, N - 1);
@@ -605,3 +607,4 @@ void addValidationData(size_t minInvalid = ~size_t(0))
605607
// This test technically tests the dumper, not the parser.
606608
QTest::newRow("string-utf8-chunk-split") << raw("\x81\x7f\x61\xc2\x61\xa0\xff") << 0 << CborErrorInvalidUtf8TextString;
607609
}
610+
} // namespace

0 commit comments

Comments
 (0)