mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user