Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Apr 14, 2023
1 parent 35eb4e4 commit 48df73e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 12 additions & 0 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1849,13 +1849,25 @@ public MarshaledString(string input)
}
else
{
#if NETSTANDARD1_1
var valueBytes = (input.Length != 0) ? Encoding.UTF8.GetBytes(input) : EmptyArray<byte>.Value;
length = valueBytes.Length;
value = Marshal.AllocHGlobal(length + 1);

Span<byte> destination = new Span<byte>(value.ToPointer(), length + 1);
valueBytes.AsSpan(0, length).CopyTo(destination);
destination[length] = 0;
#else
length = Encoding.UTF8.GetMaxByteCount(input.Length);
value = Marshal.AllocHGlobal(length + 1);

fixed (char* pInput = input)
{
length = Encoding.UTF8.GetBytes(pInput, input.Length, (byte*)value.ToPointer(), length);
}

((byte*)value)[length] = 0;
#endif
}

Length = length;
Expand Down
6 changes: 0 additions & 6 deletions csharp/src/Microsoft.ML.OnnxRuntime/OrtValue.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,6 @@ private static OrtValue CreateStringTensor(Tensor<string> tensor)
throw new OnnxRuntimeException(ErrorCode.Fail, "Cast to Tensor<string> failed. BUG check!");
}

int totalLength = 0;
for (int i = 0; i < tensor.Length; i++)
{
totalLength += System.Text.Encoding.UTF8.GetByteCount(tensor.GetValue(i));
}

long[] shape = new long[tensor.Dimensions.Length];
for (int i = 0; i < tensor.Dimensions.Length; i++)
{
Expand Down

0 comments on commit 48df73e

Please sign in to comment.