nareshmlx/opencv-pr huggingface dataset:
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...
**Review Line:** 9

**Code Changes:**
```diff
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
+#define dprintf(x) printf x
+static void print_matrix(const Mat& x){
+    print(x);
+    printf("\n");
+}
```

Review comment:
unused parameter warnings can be eliminated by commenting off parameter names.
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...
**Review Line:** 9

**Code Changes:**
```diff
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
+#define dprintf(x) printf x
+static void print_matrix(const Mat& x){
+    print(x);
+    printf("\n");
+}
```

Review comment:
Do something like this <pre> #ifdef ALEX_DEBUG static void print_matrix(const Mat& x) { ... } #else static void print_matrix(const Mat& /*x*/) {} #endif </pre>
**File:** modules/optim/include/opencv2/optim.hpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,62 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
this and the next line should be removed from the file. #define should be moved to .cpp file. #include "opencv2/core.hpp" should be added
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
ts.hpp may not be used in OpenCV modules, only in tests; #include "precomp.hpp" should be the very first #include directive
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
parentheses around x are not needed since it's not a macro anymore. CV_Assert(x.type() == CV_64F); would be very useful in this function
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
some compilers may issue warning about while(0) statements (constant condition in while); I'd suggest to make just the empty macros
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
converting from Func to bigC using a loop looks too complex. Use <pre>Func.t().convertTo(bigC.colRange(...), CV_64FC1);</pre>
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
fflush(stdout) should not be always called
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
I'd suggest to try to use <pre>std::cout &lt;&lt; mat</pre> one more time. You print not only double-precision, but also integer matrices. The built-in OpenCV operator could do all of this.
**File:** modules/optim/src/precomp.hpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,48 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
#include "opencv2/core.hpp" should be moved to the external header, otherwise #include "opencv2/optim.hpp" in user's code will fail.
**File:** modules/optim/src/precomp.hpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,48 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
apparently, mat.hpp is included from core.hpp, so there is no need to include this header either
**File:** modules/optim/src/precomp.hpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,48 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
Sorry for being idiot... do you mean that I have to move "#include opencv2/core.hpp" line to optim.hpp header?
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
Vadim, are you sure this line works? It gives me an error, stating that Func.t() is of type cv::MatExpr (Mat) and as such does not have .convertTo() method. The simple solution would be to do something like Mat FuncT=Func.t(); Func.convertTo(bigC.colRange(...),CV_64FC1); Now, while I've been thinking about this, I did not employ this solution because as far as I understand openCV matrix management system, the "Mat FuncT=Func.t();" line will make a DEEP copy of Func and I'm simply too greedy to let this happen:) Anyway, that's a minor issue and I will do as you say, if you insist.
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
It does not work... I've tried for about 4 hours, but it still doesn't... Strangely enough, operator<< works in tests and when I compile my other programs with opencv I've built and installed. But it simply does not want to work inside this .cpp. I will continue the investigation. Interestingly enough, after inspecting the other opencv code I did not find anyone, who'd try to print matrix via operator<< from the .cpp files in src/ folders. And even more interesting, I did not find the implementation of operator<< for matrices (although it exists). Some people say, it's in modules/core/include/opencv2/core/operations.hpp, but I haven't seen it there.
**File:** modules/optim/src/lpsolver.cpp
**Change Type:** added
**Context:** PR #1108: Optim lp - I'm working on generic numerical optimization module for openCV within the Google Summer of Code 2013 initiative (mentor: Vadim P...

**Code Changes:**
```diff
@@ -0,0 +1,322 @@
+#include "precomp.hpp"
+#include <climits>
+#include <algorithm>
+#include <cstdarg>
+
+namespace cv{namespace optim{
+using std::vector;
+
+#ifdef ALEX_DEBUG
```

Review comment:
ok, try <pre> cv::print(your_mat); </pre>
**File:** modules/core/include/opencv2/core/opencl/ocl_defs.hpp
**Change Type:** modified
**Context:** PR #2408: T-API: core opt
**Review Line:** 8

**Code Changes:**
```diff
@@ -5,7 +5,7 @@
 // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
 // Third party copyrights are property of their respective owners.
 
-//#define CV_OPENCL_RUN_VERBOSE
+//#define CV_OPENCL_RUN_ASSERT
 
 #ifdef HAVE_OPENCL
 
```

Review comment:
Why removed commented `VERBOSE` flag?
**File:** modules/imgproc/doc/histograms.rst
**Change Type:** modified
**Context:** PR #1248: Introduce CV_COMP_CHISQR_ALT, an alternative method to calculate ChiSqua... - ...re Histogram comparison There's some disagreement about the...

**Code Changes:**
```diff
@@ -173,6 +173,8 @@ Compares two histograms.
 
             * **CV_COMP_CHISQR**     Chi-Square
 
+            * **CV_COMP_CHISQR_ALT**     Alternative Chi-Square
+
             * **CV_COMP_INTERSECT**     Intersection
 
             * **CV_COMP_BHATTACHARYYA**     Bhattacharyya distance
@@ -202,6 +204,14 @@ The functions ``compareHist`` compare two dense or two sparse histograms using t
```

Review comment:
I think you meant `CV_COMP_CHISQR_ALT`.
**File:** modules/imgproc/src/color.cpp
**Change Type:** modified
**Context:** PR #1213: Add IPP support in cvtColor function

**Code Changes:**
```diff
@@ -93,6 +93,13 @@
 #include <limits>
 #include <iostream>
 
+#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
+#define MAX_IPP8u   255
+#define MAX_IPP16u  65535
+#define MAX_IPP32f  1.0
+static IppStatus sts = ippInit();
+#endif
```

Review comment:
please, replace ...type## with type, i.e. remove two # characters after type, otherwise the code does not build with some compilers.
**File:** modules/imgproc/src/color.cpp
**Change Type:** modified
**Context:** PR #1213: Add IPP support in cvtColor function

**Code Changes:**
```diff
@@ -93,6 +93,13 @@
 #include <limits>
 #include <iostream>
 
+#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
+#define MAX_IPP8u   255
+#define MAX_IPP16u  65535
+#define MAX_IPP32f  1.0
+static IppStatus sts = ippInit();
+#endif
```

Review comment:
I would prefer the code to be written using templates rather than macros. If possible and if you have time, please, rework the code to avoid excessive use of macros.
**File:** samples/cpp/Qt_sample/qt_opengl.cpp
**Change Type:** modified
**Context:** PR #2412: Fixed Bug #3568: Build fails with WITH_OPENGL=ON - Fixes this bug: http://code.opencv.org/issues/3568 Missing c header file calib3d_c.h adde...
**Review Line:** 8

**Code Changes:**
```diff
@@ -5,6 +5,7 @@
 #include <vector>
 
 #include <opencv2/calib3d/calib3d.hpp>
+#include <opencv2/calib3d/calib3d_c.h>
 #include <opencv2/core/core.hpp>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
@@ -213,8 +214,8 @@ int main(void)
     Mat source, grayImage;
```

Review comment:
As I can see from sources this include is not needed. All constants without CV_ prefix are defined in highgui.hpp
**File:** samples/cpp/Qt_sample/qt_opengl.cpp
**Change Type:** modified
**Context:** PR #2412: Fixed Bug #3568: Build fails with WITH_OPENGL=ON - Fixes this bug: http://code.opencv.org/issues/3568 Missing c header file calib3d_c.h adde...
**Review Line:** 8

**Code Changes:**
```diff
@@ -5,6 +5,7 @@
 #include <vector>
 
 #include <opencv2/calib3d/calib3d.hpp>
+#include <opencv2/calib3d/calib3d_c.h>
 #include <opencv2/core/core.hpp>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
@@ -213,8 +214,8 @@ int main(void)
     Mat source, grayImage;
```

Review comment:
this include is for `cvCreatePOSITObject`, etc stuff
**File:** modules/core/src/system.cpp
**Change Type:** modified
**Context:** PR #1818: Update system.cpp - Fixed to use native C++ instead of C++/CX although it does require significantly more code, it goes along with the spiri...

**Code Changes:**
```diff
@@ -87,10 +87,41 @@
 
 #ifdef HAVE_WINRT
 #include <wrl/client.h>
+#ifndef __cplusplus_winrt
+#include <windows.storage.h>
+#pragma comment(lib, "runtimeobject.lib")
+#endif
 
 std::wstring GetTempPathWinRT()
```

Review comment:
MSDN says: > Return value > Type: PCWSTR > A pointer to the buffer that provides the backing store for string, or the empty string if string is NULL or the empty string. > > Remarks > Use the WindowsGetStringRawBuffer function to obtain a pointer to the backing buffer of an HSTRING. > Do not change the contents of the buffer as all HSTRINGs are required to be immutable. If I understand correctly, it means that WindowsGetStringRawBuffer returns pointer on iternal buffer. In this case lpStr in invalid after WindowsDeleteString.
**File:** modules/core/src/system.cpp
**Change Type:** modified
**Context:** PR #1818: Update system.cpp - Fixed to use native C++ instead of C++/CX although it does require significantly more code, it goes along with the spiri...

**Code Changes:**
```diff
@@ -87,10 +87,41 @@
 
 #ifdef HAVE_WINRT
 #include <wrl/client.h>
+#ifndef __cplusplus_winrt
+#include <windows.storage.h>
+#pragma comment(lib, "runtimeobject.lib")
+#endif
 
 std::wstring GetTempPathWinRT()
```

Review comment:
I think we need to have #ifdef __cplusplus_winrt here too.
**File:** modules/core/src/stat.cpp
**Change Type:** modified
**Context:** PR #2266: eliminate crash in ipp-accelerated norm and mean functions - thanks to Matt Curfman and Aaron Kunze for the patch

**Code Changes:**
```diff
@@ -548,25 +548,31 @@ cv::Scalar cv::sum( InputArray _src )
     {
         IppiSize sz = { cols, rows };
         int type = src.type();
-        typedef IppStatus (CV_STDCALL* ippiSumFunc)(const void*, int, IppiSize, double *, int);
-        ippiSumFunc ippFunc =
-            type == CV_8UC1 ? (ippiSumFunc)ippiSum_8u_C1R :
-            type == CV_8UC3 ? (ippiSumFunc)ippiSum_8u_C3R :
-            type == CV_8UC4 ? (ippiSumFunc)ippiSum_8u_C4R :
-            type == CV_16UC1 ? (ippiSumFunc)ippiSum_16u_C1R :
```

Review comment:
That last int should probably be `IppHintAlgorithm` (here and everywhere below).
**File:** modules/core/src/ocl.cpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...
**Review Line:** 2276

**Code Changes:**
```diff
+        size_t val = _localsize ? _localsize[i] :
+            dims == 1 ? 64 : dims == 2 ? (16>>i) : dims == 3 ? (8>>(int)(i>0)) : 1;
+        CV_Assert( val > 0 );
+        total *= _globalsize[i];
+        globalsize[i] = ((_globalsize[i] + val - 1)/val)*val;
+    }
+    if( total == 0 )
+        return true;
+    if( p->haveTempDstUMats )
+        sync = true;
     cl_int retval = clEnqueueNDRangeKernel(qq, p->handle, (cl_uint)dims,
```

Review comment:
You should not create custom localsize here. There are many kernels which work with fixed work group size.
**File:** modules/imgproc/src/color.cpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -2695,6 +2695,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
     UMat src = _src.getUMat(), dst;
     Size sz = src.size(), dstSz = sz;
     int scn = src.channels(), depth = src.depth(), bidx;
+    int dims = 2, stripeSize = 1;
     size_t globalsize[] = { src.cols, src.rows };
     ocl::Kernel k;
 
@@ -2765,7 +2766,9 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
         bidx = code == COLOR_BGR2GRAY || code == COLOR_BGRA2GRAY ? 0 : 2;
```

Review comment:
Is 32 from CUDA warpsize?
**File:** modules/imgproc/src/opencl/cvtcolor.cl
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -75,6 +75,10 @@
     #error "invalid depth: should be 0 (CV_8U), 2 (CV_16U) or 5 (CV_32F)"
 #endif
 
+#ifndef STRIPE_SIZE
+#define STRIPE_SIZE 1
+#endif
+
 #define CV_DESCALE(x,n) (((x) + (1 << ((n)-1))) >> (n))
 
```

Review comment:
What is about x_min and x_max names?
**File:** modules/core/test/test_umat.cpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -200,3 +200,40 @@ void CV_UMatTest::run( int /* start_from */)
 }
 
 TEST(Core_UMat, base) { CV_UMatTest test; test.safe_run(); }
+
+TEST(Core_UMat, getUMat)
+{
+    {
+    int a[3] = { 1, 2, 3 };
+    Mat m = Mat(1, 1, CV_32SC3, a);
```

Review comment:
I see here two tests: Mat_getUMat (or Mat_getUMat_NotEmptyResult) and UMatDestructionSync.
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -279,21 +279,21 @@ class CV_EXPORTS MatAllocator
     //virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
     //                      uchar*& datastart, uchar*& data, size_t* step) = 0;
     //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
-    virtual UMatData* allocate(int dims, const int* sizes,
-                               int type, size_t* step) const = 0;
+    virtual UMatData* allocate(int dims, const int* sizes, int type,
+                               void* data, size_t* step, int flags) const = 0;
     virtual bool allocate(UMatData* data, int accessflags) const = 0;
     virtual void deallocate(UMatData* data) const = 0;
```

Review comment:
In what direction will we sync? Why body of this method can't be merged with deallocate?
**File:** modules/core/src/ocl.cpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -612,7 +612,7 @@ static void* initOpenCLAndLoad(const char* funcname)
             return 0;
     }
 
-    return funcname ? dlsym(handle, funcname) : 0;
+    return funcname && handle ? dlsym(handle, funcname) : 0;
 }
 
 #elif defined WIN32 || defined _WIN32
@@ -2002,7 +2002,7 @@ void* Queue::ptr() const
```

Review comment:
Why is `clFinish` here?
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -279,21 +279,21 @@ class CV_EXPORTS MatAllocator
     //virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
     //                      uchar*& datastart, uchar*& data, size_t* step) = 0;
     //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
-    virtual UMatData* allocate(int dims, const int* sizes,
-                               int type, size_t* step) const = 0;
+    virtual UMatData* allocate(int dims, const int* sizes, int type,
+                               void* data, size_t* step, int flags) const = 0;
     virtual bool allocate(UMatData* data, int accessflags) const = 0;
     virtual void deallocate(UMatData* data) const = 0;
```

Review comment:
because sometimes we need to synchronize content of clmem and its CPU copy without reallocating any of them. Ilya's test on getUMat + set demonstrated this effect
**File:** modules/core/src/ocl.cpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -612,7 +612,7 @@ static void* initOpenCLAndLoad(const char* funcname)
             return 0;
     }
 
-    return funcname ? dlsym(handle, funcname) : 0;
+    return funcname && handle ? dlsym(handle, funcname) : 0;
 }
 
 #elif defined WIN32 || defined _WIN32
@@ -2002,7 +2002,7 @@ void* Queue::ptr() const
```

Review comment:
without it the test Core_UMat.simple (to be renamed) fails sometimes because of data races
**File:** modules/core/test/test_umat.cpp
**Change Type:** modified
**Context:** PR #1901: [T-API] bug fixes in the base OCL layer; improved (?) performance of cvtcolor BGR=>Gray - fixed many bugs related to Mat::getUMat(), asynchr...

**Code Changes:**
```diff
@@ -200,3 +200,40 @@ void CV_UMatTest::run( int /* start_from */)
 }
 
 TEST(Core_UMat, base) { CV_UMatTest test; test.safe_run(); }
+
+TEST(Core_UMat, getUMat)
+{
+    {
+    int a[3] = { 1, 2, 3 };
+    Mat m = Mat(1, 1, CV_32SC3, a);
```

Review comment:
I retained one test, but renamed it to Core_UMat.getUMat