1 From f71c288c6d853e623461f97cd72e6a9e6541f61a Mon Sep 17 00:00:00 2001
2 From: Waldemar Brodkorb <wbx@openadk.org>
3 Date: Tue, 1 Nov 2016 09:25:30 +0100
4 Subject: [PATCH 1/4] Bug#714923: opencv FTBFS on sparc64
5 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=714923
7 opencv uses functions from <ext/atomicity.h>, but it wrongly assumes
8 this functions apply to an int type. While it is true for some
9 architectures, some architectures are using a long type there. The
10 correct type to use is _Atomic_word.
12 Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
13 [Samuel Martin: convert to git diff]
14 Signed-off-by: Samuel Martin <s.martin49@gmail.com>
16 modules/core/include/opencv2/core/core.hpp | 10 +++++-----
17 modules/core/include/opencv2/core/gpumat.hpp | 2 +-
18 modules/core/include/opencv2/core/operations.hpp | 4 ++--
19 modules/core/src/gpumat.cpp | 2 +-
20 modules/core/src/matrix.cpp | 4 ++--
21 modules/core/src/system.cpp | 8 ++++----
22 modules/gpu/include/opencv2/gpu/gpu.hpp | 2 +-
23 modules/ocl/include/opencv2/ocl/ocl.hpp | 2 +-
24 modules/ocl/src/matrix_operations.cpp | 2 +-
25 modules/python/src2/cv2.cpp | 8 ++++----
26 10 files changed, 22 insertions(+), 22 deletions(-)
28 diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp
29 index 591d50a..5b4261e 100644
30 --- a/modules/core/include/opencv2/core/core.hpp
31 +++ b/modules/core/include/opencv2/core/core.hpp
32 @@ -1290,7 +1290,7 @@ public:
33 operator const _Tp*() const;
35 _Tp* obj; //< the object pointer.
36 - int* refcount; //< the associated reference counter
37 + _Atomic_word* refcount; //< the associated reference counter
41 @@ -1490,9 +1490,9 @@ class CV_EXPORTS MatAllocator
44 virtual ~MatAllocator() {}
45 - virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
46 + virtual void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
47 uchar*& datastart, uchar*& data, size_t* step) = 0;
48 - virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
49 + virtual void deallocate(_Atomic_word* refcount, uchar* datastart, uchar* data) = 0;
53 @@ -1985,7 +1985,7 @@ public:
55 //! pointer to the reference counter;
56 // when matrix points to user-allocated data, the pointer is NULL
58 + _Atomic_word* refcount;
60 //! helper fields used in locateROI and adjustROI
62 @@ -3449,7 +3449,7 @@ public:
64 Hdr(int _dims, const int* _sizes, int _type);
67 + _Atomic_word refcount;
71 diff --git a/modules/core/include/opencv2/core/gpumat.hpp b/modules/core/include/opencv2/core/gpumat.hpp
72 index 68647d9..d488c27 100644
73 --- a/modules/core/include/opencv2/core/gpumat.hpp
74 +++ b/modules/core/include/opencv2/core/gpumat.hpp
75 @@ -301,7 +301,7 @@ namespace cv { namespace gpu
77 //! pointer to the reference counter;
78 // when GpuMatrix points to user-allocated data, the pointer is NULL
80 + _Atomic_word* refcount;
82 //! helper fields used in locateROI and adjustROI
84 diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp
85 index 0ae51c6..a455502 100644
86 --- a/modules/core/include/opencv2/core/operations.hpp
87 +++ b/modules/core/include/opencv2/core/operations.hpp
88 @@ -2589,7 +2589,7 @@ template<typename _Tp> inline Ptr<_Tp>::Ptr(_Tp* _obj) : obj(_obj)
92 - refcount = (int*)fastMalloc(sizeof(*refcount));
93 + refcount = (_Atomic_word*)fastMalloc(sizeof(*refcount));
97 @@ -2628,7 +2628,7 @@ template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _p
101 - int* _refcount = _ptr.refcount;
102 + _Atomic_word* _refcount = _ptr.refcount;
104 CV_XADD(_refcount, 1);
106 diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp
107 index 9669191..0bd2568 100644
108 --- a/modules/core/src/gpumat.cpp
109 +++ b/modules/core/src/gpumat.cpp
110 @@ -716,7 +716,7 @@ void cv::gpu::GpuMat::create(int _rows, int _cols, int _type)
111 datastart = data = static_cast<uchar*>(devPtr);
112 dataend = data + nettosize;
114 - refcount = static_cast<int*>(fastMalloc(sizeof(*refcount)));
115 + refcount = static_cast<_Atomic_word*>(fastMalloc(sizeof(*refcount)));
119 diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp
120 index 57abffc..7b840a0 100644
121 --- a/modules/core/src/matrix.cpp
122 +++ b/modules/core/src/matrix.cpp
123 @@ -213,7 +213,7 @@ void Mat::create(int d, const int* _sizes, int _type)
125 size_t totalsize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
126 data = datastart = (uchar*)fastMalloc(totalsize + (int)sizeof(*refcount));
127 - refcount = (int*)(data + totalsize);
128 + refcount = (_Atomic_word*)(data + totalsize);
132 @@ -228,7 +228,7 @@ void Mat::create(int d, const int* _sizes, int _type)
134 size_t totalSize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
135 data = datastart = (uchar*)fastMalloc(totalSize + (int)sizeof(*refcount));
136 - refcount = (int*)(data + totalSize);
137 + refcount = (_Atomic_word*)(data + totalSize);
141 diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp
142 index f5a1af2..9a7b262 100644
143 --- a/modules/core/src/system.cpp
144 +++ b/modules/core/src/system.cpp
145 @@ -892,7 +892,7 @@ struct Mutex::Impl
146 void unlock() { LeaveCriticalSection(&cs); }
150 + _Atomic_word refcount;
154 @@ -920,7 +920,7 @@ struct Mutex::Impl
155 void unlock() { OSSpinLockUnlock(&sl); }
159 + _Atomic_word refcount;
162 #elif defined __linux__ && !defined ANDROID && !defined __LINUXTHREADS_OLD__
163 @@ -935,7 +935,7 @@ struct Mutex::Impl
164 void unlock() { pthread_spin_unlock(&sl); }
166 pthread_spinlock_t sl;
168 + _Atomic_word refcount;
172 @@ -950,7 +950,7 @@ struct Mutex::Impl
173 void unlock() { pthread_mutex_unlock(&sl); }
177 + _Atomic_word refcount;
181 diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp
182 index de16982..266fa2f 100644
183 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp
184 +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp
185 @@ -125,7 +125,7 @@ public:
190 + _Atomic_word* refcount;
194 diff --git a/modules/ocl/include/opencv2/ocl/ocl.hpp b/modules/ocl/include/opencv2/ocl/ocl.hpp
195 index e8eb3e8..5ea05fc 100644
196 --- a/modules/ocl/include/opencv2/ocl/ocl.hpp
197 +++ b/modules/ocl/include/opencv2/ocl/ocl.hpp
198 @@ -404,7 +404,7 @@ namespace cv
200 //! pointer to the reference counter;
201 // when oclMatrix points to user-allocated data, the pointer is NULL
203 + _Atomic_word *refcount;
205 //! helper fields used in locateROI and adjustROI
206 //datastart and dataend are not used in current version
207 diff --git a/modules/ocl/src/matrix_operations.cpp b/modules/ocl/src/matrix_operations.cpp
208 index 331e432..c61dca4 100644
209 --- a/modules/ocl/src/matrix_operations.cpp
210 +++ b/modules/ocl/src/matrix_operations.cpp
211 @@ -591,7 +591,7 @@ void cv::ocl::oclMat::createEx(int _rows, int _cols, int _type, DevMemRW rw_type
212 datastart = data = (uchar *)dev_ptr;
213 dataend = data + nettosize;
215 - refcount = (int *)fastMalloc(sizeof(*refcount));
216 + refcount = (_Atomic_word *)fastMalloc(sizeof(*refcount));
220 diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp
221 index 04cea39..40e5d43 100644
222 --- a/modules/python/src2/cv2.cpp
223 +++ b/modules/python/src2/cv2.cpp
224 @@ -157,12 +157,12 @@ static PyObject* failmsgp(const char *fmt, ...)
225 static size_t REFCOUNT_OFFSET = (size_t)&(((PyObject*)0)->ob_refcnt) +
226 (0x12345678 != *(const size_t*)"\x78\x56\x34\x12\0\0\0\0\0")*sizeof(int);
228 -static inline PyObject* pyObjectFromRefcount(const int* refcount)
229 +static inline PyObject* pyObjectFromRefcount(const _Atomic_word* refcount)
231 return (PyObject*)((size_t)refcount - REFCOUNT_OFFSET);
234 -static inline int* refcountFromPyObject(const PyObject* obj)
235 +static inline _Atomic_word* refcountFromPyObject(const PyObject* obj)
237 return (int*)((size_t)obj + REFCOUNT_OFFSET);
239 @@ -173,7 +173,7 @@ public:
243 - void allocate(int dims, const int* sizes, int type, int*& refcount,
244 + void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
245 uchar*& datastart, uchar*& data, size_t* step)
248 @@ -206,7 +206,7 @@ public:
249 datastart = data = (uchar*)PyArray_DATA((PyArrayObject*) o);
252 - void deallocate(int* refcount, uchar*, uchar*)
253 + void deallocate(_Atomic_word* refcount, uchar*, uchar*)