Address PR feedback

This commit is contained in:
Andrii Kurdiumov 2021-07-21 00:38:34 +06:00
parent 2c54a7824c
commit 1b73bc8042
2 changed files with 8 additions and 3 deletions

View File

@ -31,7 +31,7 @@ namespace GLib {
), ),
new GLib.AbiField("is_setup" new GLib.AbiField("is_setup"
, -1 , -1
, (uint) sizeof (bool) // is_setup , (uint) sizeof(uint) // is_setup
, "hook_size" , "hook_size"
, "hooks" , "hooks"
, 1 , 1

View File

@ -237,6 +237,7 @@ namespace GtkSharp.Generation {
internal static string GetSizeOfExpression(string cstype) internal static string GetSizeOfExpression(string cstype)
{ {
// See https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types
bool isBlittable = cstype == "IntPtr" bool isBlittable = cstype == "IntPtr"
|| cstype == "UIntPtr" || cstype == "UIntPtr"
|| cstype == "ulong" || cstype == "ulong"
@ -247,11 +248,15 @@ namespace GtkSharp.Generation {
|| cstype == "short" || cstype == "short"
|| cstype == "byte" || cstype == "byte"
|| cstype == "sbyte" || cstype == "sbyte"
|| cstype == "char" || cstype == "float"
|| cstype == "byte"; || cstype == "double";
if (isBlittable) if (isBlittable)
return "sizeof( " + cstype + " )"; return "sizeof( " + cstype + " )";
// This is optimization based on https://github.com/GtkSharp/GtkSharp/pull/261#discussion_r673381869
if (cstype == "bool")
return "sizeof( uint )";
return "Marshal.SizeOf<" + cstype + ">()"; return "Marshal.SizeOf<" + cstype + ">()";
} }
} }