Last active
June 8, 2025 15:27
-
-
Save atifaziz/823bce2f9197d1873128bdf60b60cfd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Buffer | |
def test(length: int = 10000000, fill: int = 42) -> Buffer: | |
return bytearray([42] * length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>net9.0</TargetFramework> | |
<OutputType>Exe</OutputType> | |
</PropertyGroup> | |
<ItemGroup> | |
<None Remove="*.py" /> | |
</ItemGroup> | |
<ItemGroup> | |
<AdditionalFiles Include="*.py"> | |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |
</AdditionalFiles> | |
</ItemGroup> | |
<ItemGroup> | |
<PackageReference Include="CSnakes.Runtime" Version="1.0.35" /> | |
</ItemGroup> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using CSnakes.Runtime; | |
using CSnakes.Runtime.Locators; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
var builder = Host.CreateApplicationBuilder(); | |
_ = builder.Services | |
.WithPython() | |
.FromRedistributable(RedistributablePythonVersion.Python3_12); | |
builder.Logging.SetMinimumLevel(LogLevel.Debug); | |
var app = builder.Build(); | |
using var env = app.Services.GetRequiredService<IPythonEnvironment>(); | |
using var test = env.BufferTest(); | |
Span<byte> GetBufferSpan(byte fill) | |
{ | |
using var buffer = test.Test(fill: fill); | |
return buffer.AsSpan<byte>(); | |
} | |
const byte fill = 42; | |
var span = GetBufferSpan(fill); | |
if (span.IndexOfAnyExcept(fill) is var i and >= 0) | |
throw new($"Buffer contains unexpected value at index {i} (expected {fill}, but was {span[i]})."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment