Skip to content

Fix DevEncoded attributes and commands

Yury Matveyev requested to merge 510-devencoded-attributes-broken into develop

Closes #510 (closed) and #501 (closed)

The origin of these problems is that for DevEncoded attributes we passed data as a ref, but we do not notify python's garbage collector, that object is still needed, so it deallocate memory as soon as we get out of scope. If we send a small data - it just may result in corrupted data (like in #510 (closed)), but if data > 1 Mb and memory was allowed from heap - we get instantly segfault

Sometime ago it was mentioned by Tiago about boost borrowed reference, but in our bindings there are no traces of it, instead we do copy data and then do set_value with release=true.

So we decided to implement data copying also for DevEncoded attributes. It will affect performance, when somebody will try to send big dataset, but make it reliable.

I also found, that there is asymmetry - we can return str, bytes and bytesarray for DevEncoded attribute, but write only str, bytes. And for DevEncoded commands, we accept only bytes. This I also fixed.

Then I found, that in contrast to what is said in docs, we decoded strings with latin-1, not with utf-8 - fixed.

And I modified the test to check all types, all ExtractAs, check for memory leak, and check for wrong encoding.

This is another potential problem, which still is not fixed - when we write to devencoded attribute from DeviceProxy we may end up in the same problem. But to fix it, we first need to get a control over release parameter in cppTango. So this will be fixed in separate MR.

Edited by Yury Matveyev

Merge request reports