SWIG pickling improvements (and other cleanup) (#6133)

* wip

* - avoid leaking memory after instantiating UChar_Vect
- fix some indentation
- make it easier to read/write pickles as native byte arrays from Java and C#
- add tests

---------

Co-authored-by: Tosco, Paolo <paolo.tosco@novartis.com>
This commit is contained in:
Paolo Tosco
2023-03-01 05:00:56 +01:00
committed by GitHub
parent ec5d922eee
commit ab980bca44
6 changed files with 223 additions and 37 deletions

View File

@@ -52,14 +52,21 @@
%template(UChar_Vect) std::vector<unsigned char>;
%typemap(javacode) RDKit::SubstructLibrary %{
public static SubstructLibrary Deserialize(byte[] b) {
UChar_Vect vec = new UChar_Vect();
vec.reserve(b.length);
for (int size=0;size<b.length;++size) {
vec.add((short)b[size]);
}
return new SubstructLibrary(vec);
}
public static SubstructLibrary Deserialize(byte[] b) {
UChar_Vect vec = null;
try {
vec = new UChar_Vect();
vec.reserve(b.length);
for (int size=0;size<b.length;++size) {
vec.add((short)b[size]);
}
return new SubstructLibrary(vec);
} finally {
if (vec != null) {
vec.delete();
}
}
}
%}
%extend RDKit::SubstructLibrary {