From 8bcdb56ca9fafa848bdab9f3a458558721c364ba Mon Sep 17 00:00:00 2001 From: James Bowman Date: Thu, 13 May 2010 00:39:13 +0000 Subject: [PATCH] #345, cvmat() now caught and exception raised --- modules/python/cv.cpp | 11 ++++++++++- tests/python/test.py | 3 +-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/python/cv.cpp b/modules/python/cv.cpp index 87dcb9c822..5abc188276 100644 --- a/modules/python/cv.cpp +++ b/modules/python/cv.cpp @@ -380,7 +380,9 @@ static int is_iplimage(PyObject *o) static void cvmat_dealloc(PyObject *self) { cvmat_t *pc = (cvmat_t*)self; - Py_DECREF(pc->data); + if (pc->data) { + Py_DECREF(pc->data); + } cvFree(&pc->a); PyObject_Del(self); } @@ -656,6 +658,12 @@ static PyTypeObject cvmat_Type = { sizeof(cvmat_t), /*basicsize*/ }; +static int illegal_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyErr_SetString(opencv_error, "Cannot create cvmat directly; use CreateMat() instead"); + return -1; +} + static void cvmat_specials(void) { cvmat_Type.tp_dealloc = cvmat_dealloc; @@ -663,6 +671,7 @@ static void cvmat_specials(void) cvmat_Type.tp_repr = cvmat_repr; cvmat_Type.tp_methods = cvmat_methods; cvmat_Type.tp_getset = cvmat_getseters; + cvmat_Type.tp_init = illegal_init; } static int is_cvmat(PyObject *o) diff --git a/tests/python/test.py b/tests/python/test.py index c81542159c..296d523d7d 100644 --- a/tests/python/test.py +++ b/tests/python/test.py @@ -342,8 +342,7 @@ class FunctionTests(OpenCVTests): self.assertEqual(m.type, t) self.assertRaises(cv.error, lambda: cv.CreateMat(0, 100, cv.CV_8SC4)) self.assertRaises(cv.error, lambda: cv.CreateMat(100, 0, cv.CV_8SC4)) - # Uncomment when ticket #100 is fixed - # self.assertRaises(cv.error, lambda: cv.CreateMat(100, 100, 666666)) + self.assertRaises(cv.error, lambda: cv.cvmat()) def test_DrawChessboardCorners(self): im = cv.CreateImage((512,512), cv.IPL_DEPTH_8U, 3)