Skip to content

testing #118048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

testing #118048

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.Buffers.Text
{
Expand All @@ -11,6 +12,8 @@ internal static bool IsValid<T, TBase64Validatable>(TBase64Validatable validatab
where TBase64Validatable : IBase64Validatable<T>
where T : struct
{
if (!base64Text.IsEmpty && Unsafe.IsNullRef(ref MemoryMarshal.GetReference(base64Text))) throw new InvalidOperationException("Base64Helper1: Span is empty or not initialized properly. " + base64Text.Length);

int length = 0, paddingCount = 0;
T lastChar = default;

Expand All @@ -19,6 +22,8 @@ internal static bool IsValid<T, TBase64Validatable>(TBase64Validatable validatab
#if NET
while (!base64Text.IsEmpty)
{
if (Unsafe.IsNullRef(ref MemoryMarshal.GetReference(base64Text))) throw new InvalidOperationException("Base64Helper2: Span is empty or not initialized properly. " + base64Text.Length+ " "+length);

int index = validatable.IndexOfAnyExcept(base64Text);
if ((uint)index >= (uint)base64Text.Length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ private static TResult IndexOfAnyCore<TResult, TNegator, TOptimizations, TUnique
where TUniqueLowNibble : struct, SearchValues.IRuntimeConst
where TResultMapper : struct, IResultMapper<short, TResult>
{
if (searchSpaceLength != 0 && Unsafe.IsNullRef(ref searchSpace)) throw new InvalidOperationException("Span is empty or not initialized properly. " + searchSpaceLength);

ref short currentSearchSpace = ref searchSpace;

if (searchSpaceLength < Vector128<ushort>.Count)
Expand Down
112 changes: 108 additions & 4 deletions src/mono/sample/wasm/browser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,124 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Buffers.Text;
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Sample
{
public interface IBase64Validatable<T>
{
}

public readonly struct Base64CharValidatable : IBase64Validatable<char>
{
private static readonly string s_validBase64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
}

public partial class Test
{
public static int Main(string[] args)
/*
public static bool IsValid<T, TBase64Validatable>(TBase64Validatable validatable, ReadOnlySpan<T> base64Text, out int decodedLength)
where TBase64Validatable : IBase64Validatable<T>
where T : struct
{
int length = 0, paddingCount = 0;
T lastChar = default;

if (!base64Text.IsEmpty)
{
if (Unsafe.IsNullRef(ref MemoryMarshal.GetReference(base64Text)))
{
decodedLength = 0;
return false;
}
}

decodedLength = base64Text.Length;
return true;
}

public static bool IsValid(ReadOnlySpan<char> base64Text, out int decodedLength) =>
IsValid(default(Base64CharValidatable), base64Text, out decodedLength);

public unsafe static int Main(string[] args)
{
DisplayMeaning(42);
try
{
var text = "YQ==";
var chars = text.ToArray();
var span = (ReadOnlySpan<char>)chars;
var t = IsValid(span, out int decodedLength);
Console.WriteLine($"{text} -> {t}:{decodedLength} {span.Length}");
}
catch (Exception ex)
{
Console.WriteLine(ex);
return -1;
}
return 0;
}*/

public unsafe static int Main(string[] args)
{
try
{
var text = "YQ==";
var chars = text.ToArray();
var span = (ReadOnlySpan<char>)chars;
var t = Base64.IsValid(span, out int decodedLength);
Console.WriteLine($"{text} -> {t}:{decodedLength} {span.Length}");
}
catch (Exception ex)
{
Console.WriteLine(ex);
return -1;
}
return 0;
}

[JSImport("Sample.Test.displayMeaning", "main.js")]
internal static partial void DisplayMeaning(int meaning);
/*
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Buffers.Text.Base64Helper", "System.Private.CoreLib")]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Buffers.Text.Base64", "System.Private.CoreLib")]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Buffers.IndexOfAnyAsciiSearcher", "System.Private.CoreLib")]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Buffers.IndexOfAnyAsciiSearcher.AsciiState", "System.Private.CoreLib")]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Buffers.IndexOfAnyAsciiSearcher.AnyByteState", "System.Private.CoreLib")]
public unsafe static int Main(string[] args)
{
try
{
Console.WriteLine("Hello from Sample.Test.Main 1");
var utf8WithByteToBeIgnored = "YQ==";
var expectedLength = 1;
var utf8BytesWithByteToBeIgnored = utf8WithByteToBeIgnored.ToArray();

//Console.WriteLine("Hello from Sample.Test.Main 2");
//Console.WriteLine(Base64.IsValid((ReadOnlySpan<char>)utf8BytesWithByteToBeIgnored));
//Console.WriteLine("Hello from Sample.Test.Main 3");
var utf8BytesWithByteToBeIgnored2 = utf8WithByteToBeIgnored.ToArray();
var utf8BytesWithByteToBeIgnored2RS = (ReadOnlySpan<char>)utf8BytesWithByteToBeIgnored2;
fixed (char* charsPtr = &MemoryMarshal.GetReference(utf8BytesWithByteToBeIgnored2RS))
{
Console.WriteLine($"Hello from Sample.Test.Main 4 {(IntPtr)charsPtr}");
Console.WriteLine(Base64.IsValid(utf8BytesWithByteToBeIgnored2RS, out int decodedLength));
Console.WriteLine($"expectedLength: {expectedLength}, decodedLength: {decodedLength} {utf8BytesWithByteToBeIgnored2.Length}");

Console.WriteLine("Hello from Sample.Test.Main E");
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex}");
Console.WriteLine($"Exception: {ex.Message}");
Console.WriteLine($"Exception: {ex.StackTrace}");
return -1;
}
return 0;
}*/
}
}
15 changes: 15 additions & 0 deletions src/mono/sample/wasm/browser/Wasm.Browser.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,19 @@
<ItemGroup>
<WasmExtraFilesToDeploy Include="main.js" />
</ItemGroup>

<PropertyGroup>
<!--
<PublishTrimmed>true</PublishTrimmed>
<PublishTrimmed>false</PublishTrimmed>
-->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ShouldILStrip>false</ShouldILStrip>
<WasmStripILAfterAOT>false</WasmStripILAfterAOT>
<RunAOTCompilation>true</RunAOTCompilation>
<EnableAggressiveTrimming>false</EnableAggressiveTrimming>
<WasmNativeDebugSymbols>true</WasmNativeDebugSymbols>
<WasmNativeStrip>false</WasmNativeStrip>
</PropertyGroup>

</Project>
19 changes: 5 additions & 14 deletions src/mono/sample/wasm/browser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@

import { dotnet, exit } from './_framework/dotnet.js'

function displayMeaning(meaning) {
document.getElementById("out").innerHTML = `${meaning}`;
}

try {
const { setModuleImports } = await dotnet
const { runMain } = await dotnet
.withElementOnExit()
.withDiagnosticTracing(true)
.withEnvironmentVariable("MONO_LOG_LEVEL", "debug")
.withEnvironmentVariable("MONO_LOG_MASK", "all")
.withExitOnUnhandledError()
.create();

setModuleImports("main.js", {
Sample: {
Test: {
displayMeaning
}
}
});

await dotnet.run();
await runMain();
}
catch (err) {
exit(2, err);
Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/build/WasmApp.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,6 @@
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier',$(RuntimeIdentifier)))</_MonoAotCrossCompilerPath>
</PropertyGroup>

<Error Condition="'$(RunAOTCompilation)' == 'true' and '$(PublishTrimmed)' != 'true'"
Text="AOT is not supported without IL trimming (PublishTrimmed=true required)." />
<Error Condition="'$(RunAOTCompilation)' == 'true' and '$(Configuration)' == 'Debug' and '$(_WasmAllowAOTDebug)' != 'true'"
Text="AOT is not supported in debug configuration (Configuration=Release required)." />
<Error Condition="'@(_WasmAssembliesInternal)' == ''" Text="Item _WasmAssembliesInternal is empty" />
Expand Down
Loading