-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompileResultSafe.cs
More file actions
53 lines (44 loc) · 1.22 KB
/
CompileResultSafe.cs
File metadata and controls
53 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Runtime.InteropServices;
using CsBindgen;
internal class CompileResultSafe
{
private readonly CompileResult _inner;
internal CompileResultSafe(CompileResult x)
{
_inner = x;
}
public string? Error
{
get
{
unsafe
{
return _inner.error == null ? null : Marshal.PtrToStringUTF8((nint)_inner.error);
}
}
}
public List<byte[]> Buffers
{
get
{
unsafe
{
var managedBuffers = new List<byte[]>((int)_inner.buffers_len);
if (_inner.buffers == null) return managedBuffers;
for (nuint i = 0; i < _inner.buffers_len; i++)
{
var buffer = _inner.buffers[i];
var managed = new byte[checked((int)buffer.len)];
if (buffer.len > 0 && buffer.ptr != null)
Marshal.Copy((IntPtr)buffer.ptr, managed, 0, managed.Length);
managedBuffers.Add(managed);
}
return managedBuffers;
}
}
}
~CompileResultSafe()
{
NativeMethods.free_compile_result(_inner);
}
}