summaryrefslogtreecommitdiff
path: root/media-sound/mixxx/files/mixxx-2.0.0-fix-missing-pointer-initialization.patch
blob: 3364995ce4f5ffe8c59d5759588c877daf5da526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
diff -dNur a/src/analyserwaveform.cpp b/src/analyserwaveform.cpp
--- a/src/analyserwaveform.cpp	2017-02-04 21:14:33.266016824 +0100
+++ b/src/analyserwaveform.cpp	2017-02-04 21:19:09.205671982 +0100
@@ -11,8 +11,8 @@
 
 AnalyserWaveform::AnalyserWaveform(ConfigObject<ConfigValue>* pConfig) :
         m_skipProcessing(false),
-        m_waveformData(NULL),
-        m_waveformSummaryData(NULL),
+        m_waveformData(nullptr),
+        m_waveformSummaryData(nullptr),
         m_stride(0, 0),
         m_currentStride(0),
         m_currentSummaryStride(0) {
@@ -37,14 +37,13 @@
         }
     }
 
-    m_analysisDao = new AnalysisDao(m_database, pConfig);
+    m_pAnalysisDao = std::make_unique<AnalysisDao>(m_database, pConfig);
 }
 
 AnalyserWaveform::~AnalyserWaveform() {
     qDebug() << "AnalyserWaveform::~AnalyserWaveform()";
     destroyFilters();
     m_database.close();
-    delete m_analysisDao;
 }
 
 bool AnalyserWaveform::initialise(TrackPointer tio, int sampleRate, int totalSamples) {
@@ -115,7 +114,7 @@
 
     if (trackId != -1 && (missingWaveform || missingWavesummary)) {
         QList<AnalysisDao::AnalysisInfo> analyses =
-                m_analysisDao->getAnalysesForTrack(trackId);
+                m_pAnalysisDao->getAnalysesForTrack(trackId);
 
         QListIterator<AnalysisDao::AnalysisInfo> it(analyses);
         while (it.hasNext()) {
@@ -130,7 +129,7 @@
                     missingWaveform = false;
                 } else if (vc != WaveformFactory::VC_KEEP) {
                     // remove all other Analysis except that one we should keep
-                    m_analysisDao->deleteAnalysis(analysis.analysisId);
+                    m_pAnalysisDao->deleteAnalysis(analysis.analysisId);
                 }
             } if (analysis.type == AnalysisDao::TYPE_WAVESUMMARY) {
                 vc = WaveformFactory::waveformSummaryVersionToVersionClass(analysis.version);
@@ -140,7 +139,7 @@
                     missingWavesummary = false;
                 } else if (vc != WaveformFactory::VC_KEEP) {
                     // remove all other Analysis except that one we should keep
-                    m_analysisDao->deleteAnalysis(analysis.analysisId);
+                    m_pAnalysisDao->deleteAnalysis(analysis.analysisId);
                 }
             }
         }
@@ -273,13 +272,13 @@
     tio->setWaveform(ConstWaveformPointer());
     // Since clear() could delete the waveform, clear our pointer to the
     // waveform's vector data first.
-    m_waveformData = NULL;
+    m_waveformData = nullptr;
     m_waveform.clear();
 
     tio->setWaveformSummary(ConstWaveformPointer());
     // Since clear() could delete the waveform, clear our pointer to the
     // waveform's vector data first.
-    m_waveformSummaryData = NULL;
+    m_waveformSummaryData = nullptr;
     m_waveformSummary.clear();
 }
 
@@ -295,7 +294,7 @@
         m_waveform->setDescription(WaveformFactory::currentWaveformDescription());
         // Since clear() could delete the waveform, clear our pointer to the
         // waveform's vector data first.
-        m_waveformData = NULL;
+        m_waveformData = nullptr;
         m_waveform.clear();
     }
 
@@ -306,7 +305,7 @@
         m_waveformSummary->setDescription(WaveformFactory::currentWaveformSummaryDescription());
         // Since clear() could delete the waveform, clear our pointer to the
         // waveform's vector data first.
-        m_waveformSummaryData = NULL;
+        m_waveformSummaryData = nullptr;
         m_waveformSummary.clear();
     }
 
diff -dNur a/src/analyserwaveform.h b/src/analyserwaveform.h
--- a/src/analyserwaveform.h	2017-02-04 21:14:33.266016824 +0100
+++ b/src/analyserwaveform.h	2017-02-04 21:20:17.308598419 +0100
@@ -4,12 +4,14 @@
 #include <QTime>
 #include <QImage>
 #include <QSqlDatabase>
+
 #include <limits>
 
 #include "configobject.h"
 #include "analyser.h"
 #include "waveform/waveform.h"
 #include "util/math.h"
+#include "util/memory.h"
 
 //NOTS vrince some test to segment sound, to apply color in the waveform
 //#define TEST_HEAT_MAP
@@ -173,7 +175,7 @@
 
     QTime m_timer;
     QSqlDatabase m_database;
-    AnalysisDao* m_analysisDao;
+    std::unique_ptr<AnalysisDao> m_pAnalysisDao;
 
 #ifdef TEST_HEAT_MAP
     QImage* test_heatMap;
diff -dNur a/src/util/memory.h b/src/util/memory.h
--- a/src/util/memory.h	1970-01-01 01:00:00.000000000 +0100
+++ b/src/util/memory.h	2017-02-04 22:19:41.846922929 +0100
@@ -0,0 +1,149 @@
+// Taken from https://github.com/bstreiff/cppbits
+// Thank you Brandon Streiff!
+
+// Implementation of C++14's make_unique for C++11 compilers.
+//
+// This has been tested with:
+// - MSVC 11.0 (Visual Studio 2012)
+// - gcc 4.6.3
+// - Xcode 4.4 (with clang "4.0")
+//
+// It is based off an implementation proposed by Stephan T. Lavavej for
+// inclusion in the C++14 standard:
+//    http://isocpp.org/files/papers/N3656.txt
+// Where appropriate, it borrows the use of MSVC's _VARIADIC_EXPAND_0X macro
+// machinery to compensate for lack of variadic templates.
+//
+// This file injects make_unique into the std namespace, which I acknowledge is
+// technically forbidden ([C++11: 17.6.4.2.2.1/1]), but is necessary in order
+// to have syntax compatibility with C++14.
+//
+// I perform compiler version checking for MSVC, gcc, and clang to ensure that
+// we don't add make_unique if it is already there (instead, we include
+// <memory> to get the compiler-provided one). You can override the compiler
+// version checking by defining the symbol COMPILER_SUPPORTS_MAKE_UNIQUE.
+//
+//
+// ===============================================================================
+// This file is released into the public domain. See LICENCE for more information.
+// ===============================================================================
+
+#ifndef MIXXX_UTIL_MEMORY_H
+#define MIXXX_UTIL_MEMORY_H
+
+// If user hasn't specified COMPILER_SUPPORTS_MAKE_UNIQUE then try to figure out
+// based on compiler version if std::make_unique is provided.
+#if !defined(COMPILER_SUPPORTS_MAKE_UNIQUE)
+   // Compiling with -std=c++11 sets __cplusplus=201103L and disables
+   // std::make_unique() from C++14! We need to take this into account.
+   #define CPLUSPLUS_SUPPORTS_MAKE_UNIQUE (__cplusplus > 201103L)
+   #if defined(_MSC_VER)
+      // std::make_unique was added in MSVC 12.0
+      #if _MSC_VER >= 1800 // MSVC 12.0 (Visual Studio 2013)
+         #define COMPILER_SUPPORTS_MAKE_UNIQUE
+      #endif
+   #elif defined(__clang__)
+      // std::make_unique was added in clang 3.4, but not until Xcode 6.
+      // Annoyingly, Apple makes the clang version defines match the version
+      // of Xcode, not the version of clang.
+      #define CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
+      #if defined(__APPLE__) && CLANG_VERSION >= 60000 && CPLUSPLUS_SUPPORTS_MAKE_UNIQUE
+         #define COMPILER_SUPPORTS_MAKE_UNIQUE
+      #elif !defined(__APPLE__) && CLANG_VERSION >= 30400 && CPLUSPLUS_SUPPORTS_MAKE_UNIQUE
+         #define COMPILER_SUPPORTS_MAKE_UNIQUE
+      #endif
+   #elif defined(__GNUC__)
+      // std::make_unique was added in gcc 4.9
+      #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+      #if GCC_VERSION >= 40900 && CPLUSPLUS_SUPPORTS_MAKE_UNIQUE
+         #define COMPILER_SUPPORTS_MAKE_UNIQUE
+      #endif
+   #endif
+#endif
+
+#if defined(COMPILER_SUPPORTS_MAKE_UNIQUE)
+
+// If the compiler supports std::make_unique, then pull in <memory> to get it.
+#include <memory>
+
+#else
+
+// Otherwise, the compiler doesn't provide it, so implement it ourselves.
+
+#include <cstddef>
+#include <memory>
+#include <type_traits>
+#include <utility>
+
+namespace std {
+
+template<class _Ty> struct _Unique_if {
+   typedef unique_ptr<_Ty> _Single_object;
+};
+
+template<class _Ty> struct _Unique_if<_Ty[]> {
+   typedef unique_ptr<_Ty[]> _Unknown_bound;
+};
+
+template<class _Ty, size_t N> struct _Unique_if<_Ty[N]> {
+   typedef void _Known_bound;
+};
+
+//
+// template< class T, class... Args >
+// unique_ptr<T> make_unique( Args&&... args);
+//
+
+#if defined(_MSC_VER) && (_MSC_VER < 1800)
+
+// Macro machinery because MSVC 11.0 doesn't support variadic templates.
+// The _VARIADIC_EXPAND_0X stuff is defined in <xstddef>
+#define _MAKE_UNIQUE( \
+   TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
+   template<class _Ty COMMA LIST(_CLASS_TYPE)> inline \
+      typename _Unique_if<_Ty>::_Single_object make_unique(LIST(_TYPE_REFREF_ARG)) \
+   { \
+      return unique_ptr<_Ty>(new _Ty(LIST(_FORWARD_ARG))); \
+   } \
+
+_VARIADIC_EXPAND_0X(_MAKE_UNIQUE, , , , )
+#undef _MAKE_UNIQUE
+
+#else // not MSVC 11.0 or earlier
+
+template<class _Ty, class... Args>
+   typename _Unique_if<_Ty>::_Single_object
+   make_unique(Args&&... args) {
+      return unique_ptr<_Ty>(new _Ty(std::forward<Args>(args)...));
+   }
+
+#endif
+
+// template< class T >
+// unique_ptr<T> make_unique( std::size_t size );
+
+template<class _Ty>
+   typename _Unique_if<_Ty>::_Unknown_bound
+   make_unique(size_t n) {
+      typedef typename remove_extent<_Ty>::type U;
+      return unique_ptr<_Ty>(new U[n]());
+   }
+
+// template< class T, class... Args >
+// /* unspecified */ make_unique( Args&&... args ) = delete;
+
+// MSVC 11.0 doesn't support deleted functions, so the best we can do
+// is simply not define the function.
+#if !(defined(_MSC_VER) && (_MSC_VER < 1800))
+
+template<class T, class... Args>
+   typename _Unique_if<T>::_Known_bound
+   make_unique(Args&&...) = delete;
+
+#endif
+
+} // namespace std
+
+#endif // !COMPILER_SUPPORTS_MAKE_UNIQUE
+
+#endif /* MIXXX_UTIL_MEMORY_H */