Skip to content

Commit 8125cbd

Browse files
committed
Fix issue #78 by ensuring _read_value() returns true copy
It turns out that the value returned by record.read_val() can be a shared reference to the value in the underlying EPICS record. This means that this value can change unexpectedly! The fix is simply to apply the same logic as already done for string records, and take a true copy instead.
1 parent f34bde6 commit 8125cbd

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

softioc/device.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def _compare_values(self, value1, value2):
5454
# This method is called during Out record processing to return the
5555
# underlying value in EPICS format.
5656
def _read_value(self, record):
57-
return record.read_val()
57+
# Take a true copy of the value read to avoid accidental sharing
58+
result = self._ctype_()
59+
result.value = record.read_val().value
60+
return result
5861

5962
# This method is called during In record processing to update the
6063
# underlying value (the value must be in EPICS compatible format). This is
@@ -270,12 +273,6 @@ def _value_to_epics(self, value):
270273
def _epics_to_value(self, epics):
271274
return _string_at(epics, 40)
272275

273-
def _read_value(self, record):
274-
# For strings we need to take a copy of the value read
275-
result = self._ctype_()
276-
result.value = record.read_val().value
277-
return result
278-
279276

280277
class stringin(EpicsString, ProcessDeviceSupportIn):
281278
_record_type_ = 'stringin'

0 commit comments

Comments
 (0)