Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Removed:
Changed:

- `AsyncioDispatcher cleanup tasks atexit <../../pull/138>`_
- `Ensure returned numpy arrays are not writeable <../../pull/164>`_

Fixed:

Expand Down
7 changes: 6 additions & 1 deletion softioc/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ def _value_to_epics(self, value):
# common class of bug, at the cost of duplicated code and data, here we
# ensure a copy is taken of the value.
assert len(value) <= self._nelm, 'Value too long for waveform'
return numpy.copy(value)

value = numpy.copy(value)
# As we return a reference to the numpy array, ensure it cannot be
# modified under our noses
value.flags.writeable = False
return value

def _epics_to_value(self, value):
if self._dtype.char == 'S':
Expand Down
13 changes: 13 additions & 0 deletions tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,19 @@ def test_record_wrapper_str():
# If we never receive R it probably means an assert failed
select_and_recv(parent_conn, "R")

def test_waveform_values_not_modifiable():
"""Test that arrays returned from waveform records are not modifiable"""

wi = builder.WaveformIn("WI", [1, 2, 3])
wo = builder.WaveformOut("WO", [1, 2, 3])

with pytest.raises(ValueError):
wi.get()[0] = 5

with pytest.raises(ValueError):
wo.get()[0] = 5


def validate_fixture_names(params):
"""Provide nice names for the out_records fixture in TestValidate class"""
return params[0].__name__
Expand Down