Skip to content

Commit

Permalink
fixup! bindings/blst.{hpp,swg}: shift memory management to JVM GC.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-asm committed Jan 31, 2021
1 parent 3dab8e9 commit e04f148
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bindings/blst.swg
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,24 @@
%typemap(javaout) SWIGTYPE, SWIGTYPE&, SWIGTYPE* {
return new $javaclassname($jnicall);
}
%typemap(newfree) SWIGTYPE* "delete $1;"
%typemap(in) SWIGTYPE&, SWIGTYPE* %{
$1 = ($1_ltype)JCALL(GetLongArrayElements, $input, 0);
%}
%typemap(out) SWIGTYPE&, SWIGTYPE* {
size_t sz = (sizeof($*1_ltype)+sizeof(jlong)-1)/sizeof(jlong);
$result = JCALL(NewLongArray, sz);
if ($result != $null)
JCALL(SetLongArrayRegion, $result, 0, sz, (const jlong *)$1);
}
%typemap(out) SWIGTYPE&, SWIGTYPE* %{
if ($1 != $null) {
size_t sz = (sizeof($1_basetype)+sizeof(jlong)-1)/sizeof(jlong);
$result = JCALL(NewLongArray, sz);
if ($result != $null)
JCALL(SetLongArrayRegion, $result, 0, sz, (const jlong *)$1);
}
%}
%typemap(out) SWIGTYPE {
size_t sz = (sizeof($1_ltype)+sizeof(jlong)-1)/sizeof(jlong);
size_t sz = (sizeof($1_basetype)+sizeof(jlong)-1)/sizeof(jlong);
$result = JCALL(NewLongArray, sz);
if ($result != $null)
JCALL(SetLongArrayRegion, $result, 0, sz, (const jlong *)&$1);
}
%typemap(newfree) SWIGTYPE* "delete $1;"
%typemap(freearg) SWIGTYPE&, SWIGTYPE* %{
JCALL(ReleaseLongArrayElements, $input, (jlong *)$1, 0);
%}
Expand All @@ -233,14 +235,14 @@
}
~Pairing() { free($self); }
};
%typemap(newfree) blst::Pairing* "free($1);"
%typemap(out) blst::Pairing* {
size_t sz = blst_pairing_sizeof();
size_t SZ = (sz + arg2->size() + sizeof(jlong) - 1)/sizeof(jlong);
$result = JCALL(NewLongArray, SZ);
if ($result != $null)
JCALL(SetLongArrayRegion, $result, 0, SZ, (const jlong *)$1);
}
%typemap(newfree) blst::Pairing* "free($1);"
#endif

%typemap(throws) BLST_ERROR %{
Expand Down

0 comments on commit e04f148

Please sign in to comment.