0001-atomic.patch 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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
  6. opencv uses functions from <ext/atomicity.h>, but it wrongly assumes
  7. this functions apply to an int type. While it is true for some
  8. architectures, some architectures are using a long type there. The
  9. correct type to use is _Atomic_word.
  10. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
  11. [Samuel Martin: convert to git diff]
  12. Signed-off-by: Samuel Martin <s.martin49@gmail.com>
  13. ---
  14. modules/core/include/opencv2/core/core.hpp | 10 +++++-----
  15. modules/core/include/opencv2/core/gpumat.hpp | 2 +-
  16. modules/core/include/opencv2/core/operations.hpp | 4 ++--
  17. modules/core/src/gpumat.cpp | 2 +-
  18. modules/core/src/matrix.cpp | 4 ++--
  19. modules/core/src/system.cpp | 8 ++++----
  20. modules/gpu/include/opencv2/gpu/gpu.hpp | 2 +-
  21. modules/ocl/include/opencv2/ocl/ocl.hpp | 2 +-
  22. modules/ocl/src/matrix_operations.cpp | 2 +-
  23. modules/python/src2/cv2.cpp | 8 ++++----
  24. 10 files changed, 22 insertions(+), 22 deletions(-)
  25. diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp
  26. index 591d50a..5b4261e 100644
  27. --- a/modules/core/include/opencv2/core/core.hpp
  28. +++ b/modules/core/include/opencv2/core/core.hpp
  29. @@ -1290,7 +1290,7 @@ public:
  30. operator const _Tp*() const;
  31. _Tp* obj; //< the object pointer.
  32. - int* refcount; //< the associated reference counter
  33. + _Atomic_word* refcount; //< the associated reference counter
  34. };
  35. template<typename T>
  36. @@ -1490,9 +1490,9 @@ class CV_EXPORTS MatAllocator
  37. public:
  38. MatAllocator() {}
  39. virtual ~MatAllocator() {}
  40. - virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
  41. + virtual void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
  42. uchar*& datastart, uchar*& data, size_t* step) = 0;
  43. - virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
  44. + virtual void deallocate(_Atomic_word* refcount, uchar* datastart, uchar* data) = 0;
  45. };
  46. /*!
  47. @@ -1985,7 +1985,7 @@ public:
  48. //! pointer to the reference counter;
  49. // when matrix points to user-allocated data, the pointer is NULL
  50. - int* refcount;
  51. + _Atomic_word* refcount;
  52. //! helper fields used in locateROI and adjustROI
  53. uchar* datastart;
  54. @@ -3449,7 +3449,7 @@ public:
  55. {
  56. Hdr(int _dims, const int* _sizes, int _type);
  57. void clear();
  58. - int refcount;
  59. + _Atomic_word refcount;
  60. int dims;
  61. int valueOffset;
  62. size_t nodeSize;
  63. diff --git a/modules/core/include/opencv2/core/gpumat.hpp b/modules/core/include/opencv2/core/gpumat.hpp
  64. index 68647d9..d488c27 100644
  65. --- a/modules/core/include/opencv2/core/gpumat.hpp
  66. +++ b/modules/core/include/opencv2/core/gpumat.hpp
  67. @@ -301,7 +301,7 @@ namespace cv { namespace gpu
  68. //! pointer to the reference counter;
  69. // when GpuMatrix points to user-allocated data, the pointer is NULL
  70. - int* refcount;
  71. + _Atomic_word* refcount;
  72. //! helper fields used in locateROI and adjustROI
  73. uchar* datastart;
  74. diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp
  75. index 0ae51c6..a455502 100644
  76. --- a/modules/core/include/opencv2/core/operations.hpp
  77. +++ b/modules/core/include/opencv2/core/operations.hpp
  78. @@ -2589,7 +2589,7 @@ template<typename _Tp> inline Ptr<_Tp>::Ptr(_Tp* _obj) : obj(_obj)
  79. {
  80. if(obj)
  81. {
  82. - refcount = (int*)fastMalloc(sizeof(*refcount));
  83. + refcount = (_Atomic_word*)fastMalloc(sizeof(*refcount));
  84. *refcount = 1;
  85. }
  86. else
  87. @@ -2628,7 +2628,7 @@ template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _p
  88. {
  89. if (this != &_ptr)
  90. {
  91. - int* _refcount = _ptr.refcount;
  92. + _Atomic_word* _refcount = _ptr.refcount;
  93. if( _refcount )
  94. CV_XADD(_refcount, 1);
  95. release();
  96. diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp
  97. index 9669191..0bd2568 100644
  98. --- a/modules/core/src/gpumat.cpp
  99. +++ b/modules/core/src/gpumat.cpp
  100. @@ -716,7 +716,7 @@ void cv::gpu::GpuMat::create(int _rows, int _cols, int _type)
  101. datastart = data = static_cast<uchar*>(devPtr);
  102. dataend = data + nettosize;
  103. - refcount = static_cast<int*>(fastMalloc(sizeof(*refcount)));
  104. + refcount = static_cast<_Atomic_word*>(fastMalloc(sizeof(*refcount)));
  105. *refcount = 1;
  106. }
  107. }
  108. diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp
  109. index 57abffc..7b840a0 100644
  110. --- a/modules/core/src/matrix.cpp
  111. +++ b/modules/core/src/matrix.cpp
  112. @@ -213,7 +213,7 @@ void Mat::create(int d, const int* _sizes, int _type)
  113. {
  114. size_t totalsize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
  115. data = datastart = (uchar*)fastMalloc(totalsize + (int)sizeof(*refcount));
  116. - refcount = (int*)(data + totalsize);
  117. + refcount = (_Atomic_word*)(data + totalsize);
  118. *refcount = 1;
  119. }
  120. else
  121. @@ -228,7 +228,7 @@ void Mat::create(int d, const int* _sizes, int _type)
  122. allocator = 0;
  123. size_t totalSize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
  124. data = datastart = (uchar*)fastMalloc(totalSize + (int)sizeof(*refcount));
  125. - refcount = (int*)(data + totalSize);
  126. + refcount = (_Atomic_word*)(data + totalSize);
  127. *refcount = 1;
  128. }
  129. #else
  130. diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp
  131. index f5a1af2..9a7b262 100644
  132. --- a/modules/core/src/system.cpp
  133. +++ b/modules/core/src/system.cpp
  134. @@ -892,7 +892,7 @@ struct Mutex::Impl
  135. void unlock() { LeaveCriticalSection(&cs); }
  136. CRITICAL_SECTION cs;
  137. - int refcount;
  138. + _Atomic_word refcount;
  139. };
  140. #ifndef __GNUC__
  141. @@ -920,7 +920,7 @@ struct Mutex::Impl
  142. void unlock() { OSSpinLockUnlock(&sl); }
  143. OSSpinLock sl;
  144. - int refcount;
  145. + _Atomic_word refcount;
  146. };
  147. #elif defined __linux__ && !defined ANDROID && !defined __LINUXTHREADS_OLD__
  148. @@ -935,7 +935,7 @@ struct Mutex::Impl
  149. void unlock() { pthread_spin_unlock(&sl); }
  150. pthread_spinlock_t sl;
  151. - int refcount;
  152. + _Atomic_word refcount;
  153. };
  154. #else
  155. @@ -950,7 +950,7 @@ struct Mutex::Impl
  156. void unlock() { pthread_mutex_unlock(&sl); }
  157. pthread_mutex_t sl;
  158. - int refcount;
  159. + _Atomic_word refcount;
  160. };
  161. #endif
  162. diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp
  163. index de16982..266fa2f 100644
  164. --- a/modules/gpu/include/opencv2/gpu/gpu.hpp
  165. +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp
  166. @@ -125,7 +125,7 @@ public:
  167. size_t step;
  168. uchar* data;
  169. - int* refcount;
  170. + _Atomic_word* refcount;
  171. uchar* datastart;
  172. uchar* dataend;
  173. diff --git a/modules/ocl/include/opencv2/ocl/ocl.hpp b/modules/ocl/include/opencv2/ocl/ocl.hpp
  174. index e8eb3e8..5ea05fc 100644
  175. --- a/modules/ocl/include/opencv2/ocl/ocl.hpp
  176. +++ b/modules/ocl/include/opencv2/ocl/ocl.hpp
  177. @@ -404,7 +404,7 @@ namespace cv
  178. //! pointer to the reference counter;
  179. // when oclMatrix points to user-allocated data, the pointer is NULL
  180. - int *refcount;
  181. + _Atomic_word *refcount;
  182. //! helper fields used in locateROI and adjustROI
  183. //datastart and dataend are not used in current version
  184. diff --git a/modules/ocl/src/matrix_operations.cpp b/modules/ocl/src/matrix_operations.cpp
  185. index 331e432..c61dca4 100644
  186. --- a/modules/ocl/src/matrix_operations.cpp
  187. +++ b/modules/ocl/src/matrix_operations.cpp
  188. @@ -591,7 +591,7 @@ void cv::ocl::oclMat::createEx(int _rows, int _cols, int _type, DevMemRW rw_type
  189. datastart = data = (uchar *)dev_ptr;
  190. dataend = data + nettosize;
  191. - refcount = (int *)fastMalloc(sizeof(*refcount));
  192. + refcount = (_Atomic_word *)fastMalloc(sizeof(*refcount));
  193. *refcount = 1;
  194. }
  195. }
  196. diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp
  197. index 04cea39..40e5d43 100644
  198. --- a/modules/python/src2/cv2.cpp
  199. +++ b/modules/python/src2/cv2.cpp
  200. @@ -157,12 +157,12 @@ static PyObject* failmsgp(const char *fmt, ...)
  201. static size_t REFCOUNT_OFFSET = (size_t)&(((PyObject*)0)->ob_refcnt) +
  202. (0x12345678 != *(const size_t*)"\x78\x56\x34\x12\0\0\0\0\0")*sizeof(int);
  203. -static inline PyObject* pyObjectFromRefcount(const int* refcount)
  204. +static inline PyObject* pyObjectFromRefcount(const _Atomic_word* refcount)
  205. {
  206. return (PyObject*)((size_t)refcount - REFCOUNT_OFFSET);
  207. }
  208. -static inline int* refcountFromPyObject(const PyObject* obj)
  209. +static inline _Atomic_word* refcountFromPyObject(const PyObject* obj)
  210. {
  211. return (int*)((size_t)obj + REFCOUNT_OFFSET);
  212. }
  213. @@ -173,7 +173,7 @@ public:
  214. NumpyAllocator() {}
  215. ~NumpyAllocator() {}
  216. - void allocate(int dims, const int* sizes, int type, int*& refcount,
  217. + void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
  218. uchar*& datastart, uchar*& data, size_t* step)
  219. {
  220. PyEnsureGIL gil;
  221. @@ -206,7 +206,7 @@ public:
  222. datastart = data = (uchar*)PyArray_DATA((PyArrayObject*) o);
  223. }
  224. - void deallocate(int* refcount, uchar*, uchar*)
  225. + void deallocate(_Atomic_word* refcount, uchar*, uchar*)
  226. {
  227. PyEnsureGIL gil;
  228. if( !refcount )
  229. --
  230. 2.10.2