S
Silk.NET2mo ago
Curin

Thread for Generation Issues (To keep

Thread for Generation Issues (To keep nice and contained)
1 Reply
Curin
CurinOP2mo ago
1. we are seeing in generation is the rgbyData span in MIB_OPAQUE_INFO looks like this:
public Span<byte> rgbyData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return Anonymous.rgbyData.AsSpan(); }
}
public Span<byte> rgbyData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return Anonymous.rgbyData.AsSpan(); }
}
Where AsSpan requires a length argument which isn't supplied TerraFX has the following:
public Span<byte> rgbyData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return Anonymous.rgbyData.AsSpan(1);
}
}
public Span<byte> rgbyData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return Anonymous.rgbyData.AsSpan(1);
}
}
There are a few other cases like this where a length variable does exist but isn't named clearly (NumberEntries or some such), likely leading to a similar scenario of the generator not knowing what to do. TerraFX in each of these cases has an appropriate value filled. --------------------------------------- 2.An example of a class where the IID was missing with generation:
namespace ABI {
namespace Windows {
namespace ApplicationModel {
namespace Background {
MIDL_INTERFACE("80b47b17-ec8b-5653-850b-7508a01f52e7")
IBackgroundTaskBuilder6 : public IInspectable
{
public:
virtual HRESULT STDMETHODCALLTYPE get_AllowRunningTaskInStandby(
boolean* value
) = 0;
virtual HRESULT STDMETHODCALLTYPE put_AllowRunningTaskInStandby(
boolean value
) = 0;
virtual HRESULT STDMETHODCALLTYPE Validate(
boolean* result
) = 0;
virtual HRESULT STDMETHODCALLTYPE Register(
HSTRING taskName,
ABI::Windows::ApplicationModel::Background::IBackgroundTaskRegistration** result
) = 0;
};

MIDL_CONST_ID IID& IID_IBackgroundTaskBuilder6 = __uuidof(IBackgroundTaskBuilder6);
} /* Background */
} /* ApplicationModel */
} /* Windows */
} /* ABI */
namespace ABI {
namespace Windows {
namespace ApplicationModel {
namespace Background {
MIDL_INTERFACE("80b47b17-ec8b-5653-850b-7508a01f52e7")
IBackgroundTaskBuilder6 : public IInspectable
{
public:
virtual HRESULT STDMETHODCALLTYPE get_AllowRunningTaskInStandby(
boolean* value
) = 0;
virtual HRESULT STDMETHODCALLTYPE put_AllowRunningTaskInStandby(
boolean value
) = 0;
virtual HRESULT STDMETHODCALLTYPE Validate(
boolean* result
) = 0;
virtual HRESULT STDMETHODCALLTYPE Register(
HSTRING taskName,
ABI::Windows::ApplicationModel::Background::IBackgroundTaskRegistration** result
) = 0;
};

MIDL_CONST_ID IID& IID_IBackgroundTaskBuilder6 = __uuidof(IBackgroundTaskBuilder6);
} /* Background */
} /* ApplicationModel */
} /* Windows */
} /* ABI */
Out of curiosity is the MIDL_INTERFACE not something you can pull from clang? as all the IIDs I had to add had this, which does expand to struct __declspec(uuid("80b47b17-ec8b-5653-850b-7508a01f52e7")) __declspec(novtable) ------------------------------------------------------------ 3. There is a couple functions (in Windows\shared\ws2ipdef\Windows.gen.cs) which generate like this
public static void IN6_SET_ADDR_UNSPECIFIED([NativeTypeName("PIN6_ADDR")] IN6_ADDR* a)
{
NativeMemory.Fill(a->u.Byte, (uint)(sizeof(IN6_ADDR)), 0);
}
public static void IN6_SET_ADDR_UNSPECIFIED([NativeTypeName("PIN6_ADDR")] IN6_ADDR* a)
{
NativeMemory.Fill(a->u.Byte, (uint)(sizeof(IN6_ADDR)), 0);
}
Byte is _Byte_eFixedBuffer but Fill expects a void* TerraFX has the following:
public static void IN6_SET_ADDR_UNSPECIFIED([NativeTypeName("PIN6_ADDR")] IN6_ADDR* a)
{
NativeMemory.Fill(&a->u.Byte, (uint)(sizeof(IN6_ADDR)), 0);
}
public static void IN6_SET_ADDR_UNSPECIFIED([NativeTypeName("PIN6_ADDR")] IN6_ADDR* a)
{
NativeMemory.Fill(&a->u.Byte, (uint)(sizeof(IN6_ADDR)), 0);
}
This is a valid solution for the instances in Silk as well, not sure what is happening here. ---------------------------------------------- 4. We have some ambiguous cref in generated comments (PR already in clangsharp)
/// <inheritdoc cref = "IDWriteFontSet1.GetFilteredFonts"/>

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(17)]
public HRESULT GetFilteredFonts(
[NativeTypeName("const DWRITE_FONT_PROPERTY *")] DWRITE_FONT_PROPERTY* properties,
[NativeTypeName("UINT32")] uint propertyCount,
BOOL selectAnyProperty,
IDWriteFontSet1* filteredFontSet
)
/// <inheritdoc cref = "IDWriteFontSet1.GetFilteredFonts"/>

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(17)]
public HRESULT GetFilteredFonts(
[NativeTypeName("const DWRITE_FONT_PROPERTY *")] DWRITE_FONT_PROPERTY* properties,
[NativeTypeName("UINT32")] uint propertyCount,
BOOL selectAnyProperty,
IDWriteFontSet1* filteredFontSet
)
Anytime there are two overrides with the same name we get this issue
public HRESULT GetFilteredFonts(
[NativeTypeName("const DWRITE_FONT_AXIS_RANGE *")] DWRITE_FONT_AXIS_RANGE* fontAxisRanges,
[NativeTypeName("UINT32")] uint fontAxisRangeCount,
BOOL selectAnyRange,
IDWriteFontSet1* filteredFontSet
)
public HRESULT GetFilteredFonts(
[NativeTypeName("const DWRITE_FONT_AXIS_RANGE *")] DWRITE_FONT_AXIS_RANGE* fontAxisRanges,
[NativeTypeName("UINT32")] uint fontAxisRangeCount,
BOOL selectAnyRange,
IDWriteFontSet1* filteredFontSet
)
---------------------------------------------------- 5. INativeGuid, that get attached to classes with Guids but a definition for it isn't given anywhere as far as I could find. It is easy enough to replicate but still would be nice even if it is a clangsharp class that we have to reference or copy to our project. -------------------------------------------------- 6. Some defaultParameterValue attributes are trying to cast causing failure
public HRESULT SetStatus(
ushort statusCode,
[NativeTypeName("PCSTR")] sbyte* pszReason,
[Optional] ushort uSubStatus,
[Optional, DefaultParameterValue(((HRESULT)(0)))] HRESULT hrErrorToReport,
[Optional] IAppHostConfigException pException,
[Optional] BOOL fTrySkipCustomErrors
)
{
public HRESULT SetStatus(
ushort statusCode,
[NativeTypeName("PCSTR")] sbyte* pszReason,
[Optional] ushort uSubStatus,
[Optional, DefaultParameterValue(((HRESULT)(0)))] HRESULT hrErrorToReport,
[Optional] IAppHostConfigException pException,
[Optional] BOOL fTrySkipCustomErrors
)
{
(HRESULT)(0) isn't valid but just 0 is. I believe it is looking for a compile-time constant here, but not exactly sure. -------------------------------------------------- 7. No clue what happened here but it is very upset (Windows/um/WinUser/Windows.gen.cs)
[DllImport("""""", ExactSpelling = true)] public static extern uint GetCurrentMonitorTopologyId();
[DllImport("""""", ExactSpelling = true)] public static extern uint GetCurrentMonitorTopologyId();
The DllImport is where the problem exists. The triple set of quotes is causing problems TerraFX just doesn't include this function so here is the original C
WINUSERAPI
UINT
WINAPI
GetCurrentMonitorTopologyId();
WINUSERAPI
UINT
WINAPI
GetCurrentMonitorTopologyId();
-------------------------------------------------- 8. There are a few functions like this but they are all the same issue (in Windows/Shared/strsafe/Windows.gen.cs) ``` public static HRESULT StringCchPrintfA([NativeTypeName("STRSAFE_LPSTR")] sbyte* pszDest, [NativeTypeName("size_t")] nuint cchDest, [NativeTypeName("STRSAFE_LPCSTR")] sbyte* pszFormat,
arglist) { HRESULT hr; hr = StringValidateDestA(pszDest, cchDest, 2147483647); if ((((HRESULT)(hr)) >= 0)) { sbyte* argList; ((void)(new vcrt_assert_va_start_is_not_reference(), ((void)(va_start(&argList, pszFormat))))); hr = StringVPrintfWorkerA(pszDest, cchDest, null, pszFormat, argList); (unchecked((void)(argList = (sbyte*)(0)))); } else if (cchDest > 0) { pszDest = (sbyte)('\0'); } return hr; }
specifically
specifically
((void)(new vcrt_assert_va_start_is_not_reference(), ((void)(va_start(&argList, pszFormat))))); hr = StringVPrintfWorkerA(pszDest, cchDest, null, pszFormat, argList); (unchecked((void)(argList = (sbyte
)(0))));
converting to void is making everything not happy

original C
converting to void is making everything not happy

original C
STRSAFEAPI StringCchPrintfA( _Outwrites(cchDest) Always(_Postz) STRSAFE_LPSTR pszDest, In size_t cchDest, In _Printf_formatstring STRSAFE_LPCSTR pszFormat, ...) { HRESULT hr; hr = StringValidateDestA(pszDest, cchDest, STRSAFE_MAX_CCH); if (SUCCEEDED(hr)) { va_list argList; va_start(argList, pszFormat); hr = StringVPrintfWorkerA(pszDest, cchDest, NULL, pszFormat, argList); va_end(argList); } else if (cchDest > 0) { pszDest = '\0'; } return hr; } #define crt_va_start(ap, x) ((void)(vcrt_assert_va_start_is_not_reference<decltype(x)>(), crt_va_start_a(ap, x))) #define crt_va_end(ap) ((void)(ap = (va_list)0))
va_start and va_end being the problematic lines. Not sure the purpose of the (void) here but likely for C# this needs to be handled some other way
--------------------------------------------------
9. Duplicate implementation (in Windows/um/httpserv/CHttpModule.gen.cs
va_start and va_end being the problematic lines. Not sure the purpose of the (void) here but likely for C# this needs to be handled some other way
--------------------------------------------------
9. Duplicate implementation (in Windows/um/httpserv/CHttpModule.gen.cs
[MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(29)] public void Dispose() { ((delegate
unmanaged<CHttpModule, void>)((lpVtbl)[29]))( (CHttpModule)Unsafe.AsPointer(ref this) ); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(30)] public void Dispose() { ((delegate unmanaged<CHttpModule, void>)((lpVtbl)[30]))( (CHttpModule)Unsafe.AsPointer(ref this) ); }
only one definition in C
only one definition in C
virtual VOID Dispose( VOID ) { delete this; }
----------------------------------------------
10. Duplicate IID Guids (in WinRT/winrt/windows.security.authentication.web.core/IID.gen.cs)
----------------------------------------------
10. Duplicate IID Guids (in WinRT/winrt/windows.security.authentication.web.core/IID.gen.cs)
[NativeTypeName("const IID &")] public static Guid
IID_IWebAuthenticationAddAccountResponse = typeof(IWebAuthenticationAddAccountResponse).GUID; public static ref readonly Guid IID_IWebAuthenticationAddAccountResponse { get { ReadOnlySpan<byte> data = [ 0xE8, 0x13, 0xB0, 0x7F, 0xD8, 0x0B, 0x2B, 0x54, 0xB4, 0x86, 0x83, 0x23, 0x16, 0x3A, 0x4B, 0x85, ]; Debug.Assert(data.Length == Unsafe.SizeOf<Guid>()); return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data)); } }
---------------------------------------
11. Missing using for System.Numerics (in WinRT/winrt/windows.perception.spatial/ISpatialCoordinateSystem.gen.cs)
---------------------------------------
11. Missing using for System.Numerics (in WinRT/winrt/windows.perception.spatial/ISpatialCoordinateSystem.gen.cs)
[MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(6)] public HRESULT TryGetTransformTo( [NativeTypeName("ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem ")] ISpatialCoordinateSystem target, [NativeTypeName( "ABI::Windows::Foundation::FIReference_1_WindowsCFoundationCNumericsCMatrix4x4_t " )] IReference<Matrix4x4> value ) { return ( (delegate unmanaged< ISpatialCoordinateSystem, ISpatialCoordinateSystem, IReference<Matrix4x4>*, int>)((lpVtbl)[6]) )(this, target, value); } ``` uses Matrix4x4 but it isn't defined without System.Numerics @tannergooding These are the issues we had during generation. Most were fixed via pulling TerraFX versions as our base but it would be nice to generate correctly. The only outstanding issue is #4 which I already put in a PR for and it is only generating a warning.

Did you find this page helpful?