0001-atomic.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. Bug#714923: opencv FTBFS on sparc64
  2. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=714923
  3. opencv uses functions from <ext/atomicity.h>, but it wrongly assumes
  4. this functions apply to an int type. While it is true for some
  5. architectures, some architectures are using a long type there. The
  6. correct type to use is _Atomic_word.
  7. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
  8. diff -Nur opencv-2.4.12.3.orig/modules/core/include/opencv2/core/core.hpp opencv-2.4.12.3/modules/core/include/opencv2/core/core.hpp
  9. --- opencv-2.4.12.3.orig/modules/core/include/opencv2/core/core.hpp 2015-10-26 08:56:34.000000000 +0100
  10. +++ opencv-2.4.12.3/modules/core/include/opencv2/core/core.hpp 2016-04-03 00:10:50.455774144 +0200
  11. @@ -1290,7 +1290,7 @@
  12. operator const _Tp*() const;
  13. _Tp* obj; //< the object pointer.
  14. - int* refcount; //< the associated reference counter
  15. + _Atomic_word* refcount; //< the associated reference counter
  16. };
  17. template<typename T>
  18. @@ -1490,9 +1490,9 @@
  19. public:
  20. MatAllocator() {}
  21. virtual ~MatAllocator() {}
  22. - virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
  23. + virtual void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
  24. uchar*& datastart, uchar*& data, size_t* step) = 0;
  25. - virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
  26. + virtual void deallocate(_Atomic_word* refcount, uchar* datastart, uchar* data) = 0;
  27. };
  28. /*!
  29. @@ -1985,7 +1985,7 @@
  30. //! pointer to the reference counter;
  31. // when matrix points to user-allocated data, the pointer is NULL
  32. - int* refcount;
  33. + _Atomic_word* refcount;
  34. //! helper fields used in locateROI and adjustROI
  35. uchar* datastart;
  36. @@ -3408,7 +3408,7 @@
  37. {
  38. Hdr(int _dims, const int* _sizes, int _type);
  39. void clear();
  40. - int refcount;
  41. + _Atomic_word refcount;
  42. int dims;
  43. int valueOffset;
  44. size_t nodeSize;
  45. diff -Nur opencv-2.4.12.3.orig/modules/core/include/opencv2/core/gpumat.hpp opencv-2.4.12.3/modules/core/include/opencv2/core/gpumat.hpp
  46. --- opencv-2.4.12.3.orig/modules/core/include/opencv2/core/gpumat.hpp 2015-10-26 08:56:34.000000000 +0100
  47. +++ opencv-2.4.12.3/modules/core/include/opencv2/core/gpumat.hpp 2016-04-02 23:08:58.116874218 +0200
  48. @@ -301,7 +301,7 @@
  49. //! pointer to the reference counter;
  50. // when GpuMatrix points to user-allocated data, the pointer is NULL
  51. - int* refcount;
  52. + _Atomic_word* refcount;
  53. //! helper fields used in locateROI and adjustROI
  54. uchar* datastart;
  55. diff -Nur opencv-2.4.12.3.orig/modules/core/include/opencv2/core/operations.hpp opencv-2.4.12.3/modules/core/include/opencv2/core/operations.hpp
  56. --- opencv-2.4.12.3.orig/modules/core/include/opencv2/core/operations.hpp 2015-10-26 08:56:34.000000000 +0100
  57. +++ opencv-2.4.12.3/modules/core/include/opencv2/core/operations.hpp 2016-04-02 23:12:59.148385306 +0200
  58. @@ -2589,7 +2589,7 @@
  59. {
  60. if(obj)
  61. {
  62. - refcount = (int*)fastMalloc(sizeof(*refcount));
  63. + refcount = (_Atomic_word*)fastMalloc(sizeof(*refcount));
  64. *refcount = 1;
  65. }
  66. else
  67. @@ -2628,7 +2628,7 @@
  68. {
  69. if (this != &_ptr)
  70. {
  71. - int* _refcount = _ptr.refcount;
  72. + _Atomic_word* _refcount = _ptr.refcount;
  73. if( _refcount )
  74. CV_XADD(_refcount, 1);
  75. release();
  76. diff -Nur opencv-2.4.12.3.orig/modules/core/src/gpumat.cpp opencv-2.4.12.3/modules/core/src/gpumat.cpp
  77. --- opencv-2.4.12.3.orig/modules/core/src/gpumat.cpp 2015-10-26 08:56:34.000000000 +0100
  78. +++ opencv-2.4.12.3/modules/core/src/gpumat.cpp 2016-04-02 23:14:38.894804300 +0200
  79. @@ -716,7 +716,7 @@
  80. datastart = data = static_cast<uchar*>(devPtr);
  81. dataend = data + nettosize;
  82. - refcount = static_cast<int*>(fastMalloc(sizeof(*refcount)));
  83. + refcount = static_cast<_Atomic_word*>(fastMalloc(sizeof(*refcount)));
  84. *refcount = 1;
  85. }
  86. }
  87. diff -Nur opencv-2.4.12.3.orig/modules/core/src/matrix.cpp opencv-2.4.12.3/modules/core/src/matrix.cpp
  88. --- opencv-2.4.12.3.orig/modules/core/src/matrix.cpp 2015-10-26 08:56:34.000000000 +0100
  89. +++ opencv-2.4.12.3/modules/core/src/matrix.cpp 2016-04-02 23:59:53.405491031 +0200
  90. @@ -213,7 +213,7 @@
  91. {
  92. size_t totalsize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
  93. data = datastart = (uchar*)fastMalloc(totalsize + (int)sizeof(*refcount));
  94. - refcount = (int*)(data + totalsize);
  95. + refcount = (_Atomic_word*)(data + totalsize);
  96. *refcount = 1;
  97. }
  98. else
  99. @@ -228,7 +228,7 @@
  100. allocator = 0;
  101. size_t totalSize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
  102. data = datastart = (uchar*)fastMalloc(totalSize + (int)sizeof(*refcount));
  103. - refcount = (int*)(data + totalSize);
  104. + refcount = (_Atomic_word*)(data + totalSize);
  105. *refcount = 1;
  106. }
  107. #else
  108. diff -Nur opencv-2.4.12.3.orig/modules/core/src/system.cpp opencv-2.4.12.3/modules/core/src/system.cpp
  109. --- opencv-2.4.12.3.orig/modules/core/src/system.cpp 2015-10-26 08:56:34.000000000 +0100
  110. +++ opencv-2.4.12.3/modules/core/src/system.cpp 2016-04-02 23:33:19.298905578 +0200
  111. @@ -892,7 +892,7 @@
  112. void unlock() { LeaveCriticalSection(&cs); }
  113. CRITICAL_SECTION cs;
  114. - int refcount;
  115. + _Atomic_word refcount;
  116. };
  117. #ifndef __GNUC__
  118. @@ -920,7 +920,7 @@
  119. void unlock() { OSSpinLockUnlock(&sl); }
  120. OSSpinLock sl;
  121. - int refcount;
  122. + _Atomic_word refcount;
  123. };
  124. #elif defined __linux__ && !defined ANDROID && !defined __LINUXTHREADS_OLD__
  125. @@ -935,7 +935,7 @@
  126. void unlock() { pthread_spin_unlock(&sl); }
  127. pthread_spinlock_t sl;
  128. - int refcount;
  129. + _Atomic_word refcount;
  130. };
  131. #else
  132. @@ -950,7 +950,7 @@
  133. void unlock() { pthread_mutex_unlock(&sl); }
  134. pthread_mutex_t sl;
  135. - int refcount;
  136. + _Atomic_word refcount;
  137. };
  138. #endif
  139. diff -Nur opencv-2.4.12.3.orig/modules/gpu/include/opencv2/gpu/gpu.hpp opencv-2.4.12.3/modules/gpu/include/opencv2/gpu/gpu.hpp
  140. --- opencv-2.4.12.3.orig/modules/gpu/include/opencv2/gpu/gpu.hpp 2015-10-26 08:56:34.000000000 +0100
  141. +++ opencv-2.4.12.3/modules/gpu/include/opencv2/gpu/gpu.hpp 2016-04-02 23:16:19.737293785 +0200
  142. @@ -125,7 +125,7 @@
  143. size_t step;
  144. uchar* data;
  145. - int* refcount;
  146. + _Atomic_word* refcount;
  147. uchar* datastart;
  148. uchar* dataend;
  149. diff -Nur opencv-2.4.12.3.orig/modules/ocl/include/opencv2/ocl/ocl.hpp opencv-2.4.12.3/modules/ocl/include/opencv2/ocl/ocl.hpp
  150. --- opencv-2.4.12.3.orig/modules/ocl/include/opencv2/ocl/ocl.hpp 2015-10-26 08:56:34.000000000 +0100
  151. +++ opencv-2.4.12.3/modules/ocl/include/opencv2/ocl/ocl.hpp 2016-04-02 23:18:55.715331443 +0200
  152. @@ -404,7 +404,7 @@
  153. //! pointer to the reference counter;
  154. // when oclMatrix points to user-allocated data, the pointer is NULL
  155. - int *refcount;
  156. + _Atomic_word *refcount;
  157. //! helper fields used in locateROI and adjustROI
  158. //datastart and dataend are not used in current version
  159. diff -Nur opencv-2.4.12.3.orig/modules/ocl/src/matrix_operations.cpp opencv-2.4.12.3/modules/ocl/src/matrix_operations.cpp
  160. --- opencv-2.4.12.3.orig/modules/ocl/src/matrix_operations.cpp 2015-10-26 08:56:34.000000000 +0100
  161. +++ opencv-2.4.12.3/modules/ocl/src/matrix_operations.cpp 2016-04-02 23:19:23.633128033 +0200
  162. @@ -591,7 +591,7 @@
  163. datastart = data = (uchar *)dev_ptr;
  164. dataend = data + nettosize;
  165. - refcount = (int *)fastMalloc(sizeof(*refcount));
  166. + refcount = (_Atomic_word *)fastMalloc(sizeof(*refcount));
  167. *refcount = 1;
  168. }
  169. }
  170. diff -Nur opencv-2.4.12.3.orig/modules/python/src2/cv2.cpp opencv-2.4.12.3/modules/python/src2/cv2.cpp
  171. --- opencv-2.4.12.3.orig/modules/python/src2/cv2.cpp 2015-10-26 08:56:34.000000000 +0100
  172. +++ opencv-2.4.12.3/modules/python/src2/cv2.cpp 2016-04-02 23:18:34.897991791 +0200
  173. @@ -157,12 +157,12 @@
  174. static size_t REFCOUNT_OFFSET = (size_t)&(((PyObject*)0)->ob_refcnt) +
  175. (0x12345678 != *(const size_t*)"\x78\x56\x34\x12\0\0\0\0\0")*sizeof(int);
  176. -static inline PyObject* pyObjectFromRefcount(const int* refcount)
  177. +static inline PyObject* pyObjectFromRefcount(const _Atomic_word* refcount)
  178. {
  179. return (PyObject*)((size_t)refcount - REFCOUNT_OFFSET);
  180. }
  181. -static inline int* refcountFromPyObject(const PyObject* obj)
  182. +static inline _Atomic_word* refcountFromPyObject(const PyObject* obj)
  183. {
  184. return (int*)((size_t)obj + REFCOUNT_OFFSET);
  185. }
  186. @@ -173,7 +173,7 @@
  187. NumpyAllocator() {}
  188. ~NumpyAllocator() {}
  189. - void allocate(int dims, const int* sizes, int type, int*& refcount,
  190. + void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
  191. uchar*& datastart, uchar*& data, size_t* step)
  192. {
  193. PyEnsureGIL gil;
  194. @@ -206,7 +206,7 @@
  195. datastart = data = (uchar*)PyArray_DATA((PyArrayObject*) o);
  196. }
  197. - void deallocate(int* refcount, uchar*, uchar*)
  198. + void deallocate(_Atomic_word* refcount, uchar*, uchar*)
  199. {
  200. PyEnsureGIL gil;
  201. if( !refcount )