Feature/bug with DevEncoded attribute
We have in pytango batch of issues related to DevEncoded attribute (pytango#147 (closed), pytango#510 (closed), pytango#501 (closed) )
The problem is, that python`s garbage collector can destroy data, set to DevEncoded attribute, before it will be transmitted, if we do not store data in the server instance. This results in either data corruption, either segfault.
E.g., if we do something like:
@attribute(dtype=DevEncoded, access=AttrWriteType.READ)
def attr_encoded(self):
return "example", "aaaaaa"
in our bindings we copy reference to the data to with set_value:
att.set_value(&val_str_real, (Tango::DevUChar*)val_real, (long)len(data));
but then, as soon as we get out from read function python`s garbage collector deallocate memory, since it doesn't know it is needed. We have somehow to protect it, namely increase ref.counts. The question it - how to learn, that data is not needed anymore and we can trow data set away. Any ideas?
To test such a behavior directly in cpp @jkotan made a simple cpp server, doing the same, python does - creating local dataset, passing it to set_value and then delete it in server instance - so the transmitted value is corrupted.
You can switch behavior between local/global dataset by comment/uncomment blocks in https://github.com/jkotan/testenc/blob/main/EncTest.cpp#L189