Skip to content

Commit 4cb1c5b

Browse files
committed
Handle better native pointer
1 parent fc6e6bc commit 4cb1c5b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/digidoc.i

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ SWIGEXPORT void JNICALL Java_ee_ria_libdigidocpp_digidocJNI_initJava(JNIEnv *jen
115115
[global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="ByteVector_size")]
116116
public static extern int ByteVector_size(global::System.IntPtr data);
117117
[global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="ByteVector_to")]
118-
public static extern global::System.Runtime.InteropServices.HandleRef ByteVector_to(
118+
public static extern global::System.IntPtr ByteVector_to(
119119
[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]byte[] data, int size);
120120
%}
121121

@@ -142,10 +142,13 @@ SWIGEXPORT void JNICALL Java_ee_ria_libdigidocpp_digidocJNI_initJava(JNIEnv *jen
142142
return $jnicall;
143143
}
144144
%typemap(cstype) std::vector<unsigned char> "byte[]"
145-
%typemap(csin) std::vector<unsigned char> "$modulePINVOKE.ByteVector_to($csinput, $csinput.Length)"
146-
%typemap(csout) std::vector<unsigned char>
145+
%typemap(csin,
146+
pre= " global::System.IntPtr cPtr$csinput = (global::System.IntPtr)digidocPINVOKE.ByteVector_to($csinput, $csinput.Length);
147+
global::System.Runtime.InteropServices.HandleRef handleRef$csinput = new global::System.Runtime.InteropServices.HandleRef(this, cPtr$csinput);"
148+
) std::vector<unsigned char> "handleRef$csinput"
149+
%typemap(csout, excode=SWIGEXCODE) std::vector<unsigned char>
147150
{
148-
global::System.IntPtr data = $imcall;
151+
global::System.IntPtr data = $imcall;$excode
149152
byte[] result = new byte[$modulePINVOKE.ByteVector_size(data)];
150153
global::System.Runtime.InteropServices.Marshal.Copy($modulePINVOKE.ByteVector_data(data), result, 0, result.Length);
151154
return result;

0 commit comments

Comments
 (0)