Description: Fix type from int to _Atomic_word
Author:  Aurelien Jarno <aurel32@debian.org>
Forwarded: not yet
Bug-Debian: http://bugs.debian.org/714923
Last-Update: <2013-07-12>

diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp
index 7caf753..4843b5d 100644
--- a/modules/core/include/opencv2/core/core.hpp
+++ b/modules/core/include/opencv2/core/core.hpp
@@ -1293,7 +1293,7 @@ public:
     operator const _Tp*() const;
 
     _Tp* obj; //< the object pointer.
-    int* refcount; //< the associated reference counter
+    _Atomic_word* refcount; //< the associated reference counter
 };
 
 
@@ -1460,9 +1460,9 @@ class CV_EXPORTS MatAllocator
 public:
     MatAllocator() {}
     virtual ~MatAllocator() {}
-    virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
+    virtual void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
                           uchar*& datastart, uchar*& data, size_t* step) = 0;
-    virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
+    virtual void deallocate(_Atomic_word* refcount, uchar* datastart, uchar* data) = 0;
 };
 
 /*!
@@ -1957,7 +1957,7 @@ public:
 
     //! pointer to the reference counter;
     // when matrix points to user-allocated data, the pointer is NULL
-    int* refcount;
+    _Atomic_word* refcount;
 
     //! helper fields used in locateROI and adjustROI
     uchar* datastart;
@@ -3342,7 +3342,7 @@ public:
     {
         Hdr(int _dims, const int* _sizes, int _type);
         void clear();
-        int refcount;
+        _Atomic_word refcount;
         int dims;
         int valueOffset;
         size_t nodeSize;
diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp
index 1170fc4..e7eb8d7 100644
--- a/modules/core/include/opencv2/core/operations.hpp
+++ b/modules/core/include/opencv2/core/operations.hpp
@@ -2279,7 +2279,7 @@ public:
         Hdr() : data(0), datastart(0), refcount(0), size(0), capacity(0) {};
         _Tp* data;
         _Tp* datastart;
-        int* refcount;
+        _Atomic_word* refcount;
         size_t size;
         size_t capacity;
     };
@@ -2586,7 +2586,7 @@ template<typename _Tp> inline Ptr<_Tp>::Ptr(_Tp* _obj) : obj(_obj)
 {
     if(obj)
     {
-        refcount = (int*)fastMalloc(sizeof(*refcount));
+        refcount = (_Atomic_word*)fastMalloc(sizeof(*refcount));
         *refcount = 1;
     }
     else
@@ -2623,7 +2623,7 @@ template<typename _Tp> inline Ptr<_Tp>::Ptr(const Ptr<_Tp>& _ptr)
 
 template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _ptr)
 {
-    int* _refcount = _ptr.refcount;
+    _Atomic_word* _refcount = _ptr.refcount;
     if( _refcount )
         CV_XADD(_refcount, 1);
     release();
diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp
index 7acb0e0..820d45c 100644
--- a/modules/core/src/matrix.cpp
+++ b/modules/core/src/matrix.cpp
@@ -213,7 +213,7 @@ void Mat::create(int d, const int* _sizes, int _type)
         {
             size_t totalsize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
             data = datastart = (uchar*)fastMalloc(totalsize + (int)sizeof(*refcount));
-            refcount = (int*)(data + totalsize);
+            refcount = (_Atomic_word*)(data + totalsize);
             *refcount = 1;
         }
         else
@@ -228,7 +228,7 @@ void Mat::create(int d, const int* _sizes, int _type)
                 allocator = 0;
                 size_t totalSize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
                 data = datastart = (uchar*)fastMalloc(totalSize + (int)sizeof(*refcount));
-                refcount = (int*)(data + totalSize);
+                refcount = (_Atomic_word*)(data + totalSize);
                 *refcount = 1;
             }
 #else
diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp
index e2fc99b..64c4330 100644
--- a/modules/gpu/include/opencv2/gpu/gpu.hpp
+++ b/modules/gpu/include/opencv2/gpu/gpu.hpp
@@ -125,7 +125,7 @@ public:
     size_t step;
 
     uchar* data;
-    int* refcount;
+    _Atomic_word* refcount;
 
     uchar* datastart;
     uchar* dataend;
diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp
index 308eb42..d68c554 100644
--- a/modules/python/src2/cv2.cpp
+++ b/modules/python/src2/cv2.cpp
@@ -150,14 +150,14 @@ static PyObject* failmsgp(const char *fmt, ...)
 static size_t REFCOUNT_OFFSET = (size_t)&(((PyObject*)0)->ob_refcnt) +
     (0x12345678 != *(const size_t*)"\x78\x56\x34\x12\0\0\0\0\0")*sizeof(int);
 
-static inline PyObject* pyObjectFromRefcount(const int* refcount)
+static inline PyObject* pyObjectFromRefcount(const _Atomic_word* refcount)
 {
     return (PyObject*)((size_t)refcount - REFCOUNT_OFFSET);
 }
 
 static inline int* refcountFromPyObject(const PyObject* obj)
 {
-    return (int*)((size_t)obj + REFCOUNT_OFFSET);
+    return (_Atomic_word*)((size_t)obj + REFCOUNT_OFFSET);
 }
 
 class NumpyAllocator : public MatAllocator
@@ -166,7 +166,7 @@ public:
     NumpyAllocator() {}
     ~NumpyAllocator() {}
 
-    void allocate(int dims, const int* sizes, int type, int*& refcount,
+    void allocate(int dims, const int* sizes, int type, _Atomic_word*& refcount,
                   uchar*& datastart, uchar*& data, size_t* step)
     {
         PyEnsureGIL gil;
@@ -199,7 +199,7 @@ public:
         datastart = data = (uchar*)PyArray_DATA(o);
     }
 
-    void deallocate(int* refcount, uchar*, uchar*)
+    void deallocate(_Atomic_word* refcount, uchar*, uchar*)
     {
         PyEnsureGIL gil;
         if( !refcount )
