Skip to content

3.0 - Simple IHandle interface for XYZHandle structs - #2504

Open
aquagoose wants to merge 1 commit into
dotnet:develop/3.0from
aquagoose:3.0-ihandle
Open

3.0 - Simple IHandle interface for XYZHandle structs#2504
aquagoose wants to merge 1 commit into
dotnet:develop/3.0from
aquagoose:3.0-ihandle

Conversation

@aquagoose

Copy link
Copy Markdown
Collaborator

Summary of the PR

Adds a simple IHandle struct for XYZHandle structs, and implements an IsNull property.

Related issues, Discord discussions, or proposals

https://discord.com/channels/521092042781229087/587346162802229298/1443561471245291592

Further Comments

Only tested locally with SDL.


namespace Silk.NET.Core;

public interface IHandle

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs comments are resulting in compilation failure.

Comment on lines +719 to +720
CastExpression(IdentifierName("IntPtr"), IdentifierName("Handle")),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this == default to make it agnostic to non-pointer-sized handles?


namespace Silk.NET.Core;

public interface IHandle

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm on second thought, maybe we could do IHandle<TSelf> : IEquatable<TSelf>, IEqualityOperators<TSelf, TSelf, bool>? At this point we totally negate the need for IsNull as users generalising over T: IHandle<T>>? Could maybe keep this non-generic interface and DIM it in the generic one if we want (is that a thing?) If we go that route no changes will be required to TransformHandles other than the base list.

@Exanite Exanite Aug 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently worked on some unofficial HarfBuzz bindings using Silk 3 and HarfBuzz uses a null object pattern, which can be exposed as an IsNullOrEmpty(IHarfBuzz) or IsEmpty(IHarfBuzz) method on the HarfBuzz handles. This means having the IsNull property would be nice for consistency.

To be clear, not asking for the methods to be added to the IHandle interface. There likely will need to be a HarfBuzz-specific handle interface.

https://harfbuzz.github.io/object-model-lifecycle.html

Finally, object constructors (and, indeed, as much of the shaping API as possible) will never return NULL. Instead, if there is an allocation error, each constructor will return an “empty” object singleton.

HarfBuzz exposes these "empty" singletons as *GetEmpty() functions:
image

This matters more if we ever add HarfBuzz bindings officially to Silk, but does represent a potential edge case.

Also, open to having both the equality interfaces and the property/methods, but I have to give it some more thought.

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Silk.NET Development Tracker Nov 29, 2025
@Perksey

Perksey commented Aug 22, 2026

Copy link
Copy Markdown
Member

Is this still being worked on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants