-
Notifications
You must be signed in to change notification settings - Fork 2
Add a managed, safer API #16
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
base: main
Are you sure you want to change the base?
Changes from all commits
3e58af8
d5205dd
6850ea6
21b2463
7cb64ff
fb85730
32cd1b9
6f19cff
4e0c333
d230ceb
f7d0703
e88fe4a
2e6f681
e915aba
075d05b
eb18670
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "version": 1, | ||
| "isRoot": true, | ||
| "tools": { | ||
| "dotnet-t4": { | ||
| "version": "3.0.0", | ||
| "commands": [ | ||
| "t4" | ||
| ], | ||
| "rollForward": false | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <RuntimeIdentifier>linux-x64</RuntimeIdentifier> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\src\DynamicProbes.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| namespace DynamicProbes; | ||
|
|
||
| public enum ArgType // NOTE! Keep in sync with Libstapsdt.ArgType! | ||
| { | ||
| NoArg = Libstapsdt.ArgType.NoArg, | ||
| #pragma warning disable CA1720 // Identifier contains type name (by-design for familiarity) | ||
| UInt8 = Libstapsdt.ArgType.UInt8, | ||
| Int8 = Libstapsdt.ArgType.Int8, | ||
| UInt16 = Libstapsdt.ArgType.UInt16, | ||
| Int16 = Libstapsdt.ArgType.Int16, | ||
| UInt32 = Libstapsdt.ArgType.UInt32, | ||
| Int32 = Libstapsdt.ArgType.Int32, | ||
| UInt64 = Libstapsdt.ArgType.UInt64, | ||
| Int64 = Libstapsdt.ArgType.Int64, | ||
| #pragma warning disable CA1720 // Identifier contains type name | ||
| } | ||
|
|
||
| public interface IArgType | ||
| { | ||
| static abstract ArgType ArgType { get; } | ||
| } | ||
|
|
||
| public interface IFireArgLong | ||
| { | ||
| long UncheckedValue { get; } | ||
| } | ||
|
|
||
| #pragma warning disable CA2225 // Operator overloads have named alternates (not needed) | ||
|
|
||
| /// <summary> | ||
| /// <see langword="byte"/> as <see cref="ArgType.UInt8"/>. | ||
| /// </summary> | ||
| public readonly record struct UInt8Arg(byte Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.UInt8; | ||
| public static implicit operator UInt8Arg(byte value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="sbyte"/> as <see cref="ArgType.Int8"/>. | ||
| /// </summary> | ||
| public readonly record struct Int8Arg(sbyte Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.Int8; | ||
| public static implicit operator Int8Arg(sbyte value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="ushort"/> as <see cref="ArgType.UInt16"/>. | ||
| /// </summary> | ||
| public readonly record struct UInt16Arg(ushort Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.UInt16; | ||
| public static implicit operator UInt16Arg(ushort value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="short"/> as <see cref="ArgType.Int16"/>. | ||
| /// </summary> | ||
| public readonly record struct Int16Arg(short Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.Int16; | ||
| public static implicit operator Int16Arg(short value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="uint"/> as <see cref="ArgType.UInt32"/>. | ||
| /// </summary> | ||
| public readonly record struct UInt32Arg(uint Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.UInt32; | ||
| public static implicit operator UInt32Arg(uint value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="int"/> as <see cref="ArgType.Int32"/>. | ||
| /// </summary> | ||
| public readonly record struct Int32Arg(int Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.Int32; | ||
| public static implicit operator Int32Arg(int value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="ulong"/> as <see cref="ArgType.UInt64"/>. | ||
| /// </summary> | ||
| public readonly record struct UInt64Arg(ulong Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.UInt64; | ||
| public static implicit operator UInt64Arg(ulong value) => new(value); | ||
| long IFireArgLong.UncheckedValue => unchecked((long)Value); | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="long"/> as <see cref="ArgType.Int64"/>. | ||
| /// </summary> | ||
| public readonly record struct Int64Arg(long Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.Int64; | ||
| public static implicit operator Int64Arg(long value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| public override string ToString() => $"{Value}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="nint"/> as an argument of type <see cref="ArgType.UInt64"/>. | ||
| /// </summary> | ||
| public readonly record struct IntPtrArg(nint Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.UInt64; | ||
| public static implicit operator IntPtrArg(nint value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see langword="bool"/> as an argument of type <see cref="ArgType.Int32"/>. | ||
| /// </summary> | ||
| public readonly record struct BoolArg(bool Value) : IArgType, IFireArgLong | ||
| { | ||
| public static ArgType ArgType => ArgType.Int32; | ||
| public static implicit operator BoolArg(bool value) => new(value); | ||
| long IFireArgLong.UncheckedValue => Value ? 1 : 0; | ||
| public override string ToString() => Value.ToString(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <RuntimeIdentifier>linux-x64</RuntimeIdentifier> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
|
|
@@ -21,4 +20,35 @@ | |
| <Compile Remove="$(GeneratedFolder)/**/*.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="Probes.g.tt"> | ||
| <Generator>TextTemplatingFileGenerator</Generator> | ||
| <LastGenOutput>Probes.g.cs</LastGenOutput> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Update="Probes.g.cs"> | ||
| <DesignTime>True</DesignTime> | ||
| <AutoGen>True</AutoGen> | ||
| <DependentUpon>Probes.g.tt</DependentUpon> | ||
| </Compile> | ||
| </ItemGroup> | ||
|
Comment on lines
+30
to
+47
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, this is metainformation about the sources for the build task, but it won't regenerate if the template changes. At least on my Ubuntu, One could define a pre-build task to do exactly that. But it will be noisy if we keep the CI can still check if the generated source is in sync with the template by making an exception for What do you think? Is there a best practice for keeping T4 templates in sync with the generated files? |
||
|
|
||
| <ItemGroup> | ||
| <AdditionalFiles Include="PublicAPI.Shipped.txt" /> | ||
| <AdditionalFiles Include="PublicAPI.Unshipped.txt" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always call the function from the C library with the
longarguments, even if the probe was registered asProbe<Int8, Int8>.I wonder if it's safe to pass the function parameters to C as 4-byte types; and if yes, why allow registering the probe as unit8 in the first place?