Crash when writing numpy.array to DeviceProxy string array attributes
It seems that there is a memory management error for handling numpy string arrays in the DeviceProxies:
from tango.server import Device, attribute, AttrWriteType
from tango.test_context import DeviceTestContext
import numpy
class test_device(Device):
A = attribute(dtype=(str,), max_dim_x=3, access=AttrWriteType.READ_WRITE)
def read_A(self):
return ["foo", "bar", "baz"]
def write_A(self, value):
print(f"Attribute A is written! value={value}")
with DeviceTestContext(test_device) as proxy:
print("Writing a list[str]")
proxy.A = ["list[str]"]
print("Writing a numpy.array")
proxy.A = numpy.array(["numpy.array"])
Results in
$ python3 test_device.py
Can't create notifd event supplier. Notifd event not available
Ready to accept request
Writing a list[str]
Attribute A is written! value=['list[str]']
Writing a numpy.array
Attribute A is written! value=['numpy.array']
free(): invalid pointer
Aborted
A backtrace in gdb
shows this happens in PyDeviceProxy::write_attribute
, when it destructs its DeviceAttribute
:
#1 0x00007ffff7c5f537 in __GI_abort () at abort.c:79
(...)
#8 _CORBA_Sequence_String::~_CORBA_Sequence_String (this=<optimized out>, __in_chrg=<optimized out>) at /usr/include/omniORB4/stringtypes.h:654
#9 0x00007ffff6c61ea5 in Tango::DeviceAttribute::~DeviceAttribute() () from /usr/lib/x86_64-linux-gnu/libtango.so.9
#10 0x00007ffff768ecad in PyDeviceProxy::write_attribute (self=..., attr_name=..., py_value=...)
Since list
works and numpy.array
does not, the problem may well be in marshalling the numpy
into a Tango::DeviceAttribute
, maybe at https://gitlab.com/tango-controls/pytango/-/blob/develop/ext/device_attribute.cpp#L713?
Tested using PyTango 9.3.3 + cppTango 9.3.5 as well as PyTango 9.3.4 + cppTango 9.3.4.
Edited by Jan David Mol