calibration: fix Python-to-caldac cast in CalibrationSetting._caldacs_set.
authorW. Trevor King <wking@tremily.us>
Wed, 17 Oct 2012 17:12:31 +0000 (13:12 -0400)
committerW. Trevor King <wking@tremily.us>
Wed, 17 Oct 2012 17:12:31 +0000 (13:12 -0400)
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
pycomedi/calibration.pyx

index cbd827b27e07595e3ecb05f5a727eafb00cbb0c0..ca0b302d017a519a35c4d4a60721a1770126f90a 100644 (file)
@@ -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)
 
 
index 67eed07ba69309caead052db90b1ccedf57613a7..f68eb96ff25d9fd727796796a65cf5b56cc1c865 100644 (file)
@@ -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):