From 8f868bc0875c28affdfde1336e268a6f2c17f00c Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 28 Sep 2023 14:34:14 -0500 Subject: [PATCH] Propagate exceptions correctly from setSLMImage() --- pymmcore/pymmcore_swig.i | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pymmcore/pymmcore_swig.i b/pymmcore/pymmcore_swig.i index 2e2d6b4..fea2f71 100755 --- a/pymmcore/pymmcore_swig.i +++ b/pymmcore/pymmcore_swig.i @@ -185,10 +185,14 @@ import_array(); %rename(setSLMImage) setSLMImage_pywrap; %apply (char *STRING, int LENGTH) { (char *pixels, int receivedLength) }; %extend CMMCore { -PyObject *setSLMImage_pywrap(const char* slmLabel, char *pixels, int receivedLength) +void setSLMImage_pywrap(const char* slmLabel, char *pixels, int receivedLength) throw (CMMError) { + // TODO This size check is done here (instead of in MMCore) because the + // CMMCore::setSLMImage() interface is deficient: it does not include a + // length parameter. It will be better to change the CMMCore functions to + // require a length and move this check there. + long expectedLength = self->getSLMWidth(slmLabel) * self->getSLMHeight(slmLabel); - //printf("expected: %d -- received: %d\n",expectedLength,receivedLength); if (receivedLength == expectedLength) { @@ -200,10 +204,8 @@ PyObject *setSLMImage_pywrap(const char* slmLabel, char *pixels, int receivedLen } else { - PyErr_SetString(PyExc_TypeError, "Image dimensions are wrong for this SLM."); - return (PyObject *) NULL; + throw CMMError("Image dimensions are wrong for this SLM"); } - return PyInt_FromLong(0); } } %ignore setSLMImage;