From 31b24aac5102335f6029c035212271bd8d09fdf6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 17 Oct 2012 13:12:31 -0400 Subject: [PATCH] calibration: fix Python-to-caldac cast in CalibrationSetting._caldacs_set. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Pointed out by Éric Piel using Cython 0.15.1: Error compiling Cython file: ------------------------------------------------------------ ... raise MemoryError() self.setting.num_caldacs = length for i,x in enumerate(value): if i >= length: raise ValueError((i, length)) self.setting.caldacs[i] = x ^ ------------------------------------------------------------ pycomedi/calibration.pyx:505:39: Cannot convert Python object to 'comedi_caldac_t' --- pycomedi/calibration.pxd | 1 + pycomedi/calibration.pyx | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pycomedi/calibration.pxd b/pycomedi/calibration.pxd index cbd827b..ca0b302 100644 --- a/pycomedi/calibration.pxd +++ b/pycomedi/calibration.pxd @@ -42,6 +42,7 @@ cdef class CalibrationSetting (object): cdef _comedilib_h.comedi_calibration_setting_t *setting cdef public _Subdevice subdevice + cdef _caldacs_set_single(self, index, Caldac caldac) cpdef _soft_calibration_set(self, CalibratedConverter value) diff --git a/pycomedi/calibration.pyx b/pycomedi/calibration.pyx index 67eed07..f68eb96 100644 --- a/pycomedi/calibration.pyx +++ b/pycomedi/calibration.pyx @@ -545,6 +545,8 @@ cdef class CalibrationSetting (object): c.caldac = &self.setting.caldacs[i] ret.append(c) return ret + cdef _caldacs_set_single(self, index, Caldac caldac): + self.setting.caldacs[index] = caldac.caldac[0] def _caldacs_set(self, value): assert self.setting is not NULL, 'load setting first' if self.setting.caldacs is not NULL: @@ -559,7 +561,7 @@ cdef class CalibrationSetting (object): for i,x in enumerate(value): if i >= length: raise ValueError((i, length)) - self.setting.caldacs[i] = x + self._caldacs_set_single(i, x) caldacs = property(fget=_caldacs_get, fset=_caldacs_set) def _soft_calibration_get(self): -- 2.26.2