#345, cvmat() now caught and exception raised

This commit is contained in:
James Bowman 2010-05-13 00:39:13 +00:00
parent 26b7ed6901
commit 8bcdb56ca9
2 changed files with 11 additions and 3 deletions

View File

@ -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)

View File

@ -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)