diff --git a/src/Generation/Generator/Generator/Internal/OpaqueRecordHandle.cs b/src/Generation/Generator/Generator/Internal/OpaqueRecordHandle.cs new file mode 100644 index 000000000..70ce81df9 --- /dev/null +++ b/src/Generation/Generator/Generator/Internal/OpaqueRecordHandle.cs @@ -0,0 +1,32 @@ +using Generator.Model; + +namespace Generator.Generator.Internal; + +internal class OpaqueRecordHandle : Generator +{ + private readonly Publisher _publisher; + + public OpaqueRecordHandle(Publisher publisher) + { + _publisher = publisher; + } + + public void Generate(GirModel.Record obj) + { + if (!obj.Opaque) + return; + + if (obj.TypeFunction is null) + return; + + var source = Renderer.Internal.OpaqueRecordHandle.Render(obj); + var codeUnit = new CodeUnit( + Project: Namespace.GetCanonicalName(obj.Namespace), + Name: Model.OpaqueRecord.GetInternalBoxedHandle(obj), + Source: source, + IsInternal: true + ); + + _publisher.Publish(codeUnit); + } +} diff --git a/src/Generation/Generator/Model/OpaqueRecord.cs b/src/Generation/Generator/Model/OpaqueRecord.cs index e04cfc0b5..b95e49094 100644 --- a/src/Generation/Generator/Model/OpaqueRecord.cs +++ b/src/Generation/Generator/Model/OpaqueRecord.cs @@ -2,15 +2,33 @@ internal static class OpaqueRecord { - public static string GetBoxedHandle(GirModel.Record record) - => $"GLib.Internal.BoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>"; + public static string GetPublicClassName(GirModel.Record record) + => record.Name; - public static string GetOwnedBoxedHandle(GirModel.Record record) - => $"GLib.Internal.OwnedBoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>"; + public static string GetFullyQualifiedPublicClassName(GirModel.Record record) + => Namespace.GetPublicName(record.Namespace) + "." + GetPublicClassName(record); - public static string GetInitiallyUnownedBoxedHandle(GirModel.Record record) - => $"GLib.Internal.InitiallyUnownedBoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>"; + public static string GetFullyQualifiedInternalClassName(GirModel.Record record) + => Namespace.GetInternalName(record.Namespace) + "." + record.Name; + + public static string GetInternalBoxedHandle(GirModel.Record record) + => $"{Type.GetName(record)}BoxedHandle"; + + public static string GetInternalOwnedBoxedHandle(GirModel.Record record) + => $"{Type.GetName(record)}OwnedBoxedHandle"; + + public static string GetInternalInitiallyUnownedBoxedHandle(GirModel.Record record) + => $"{Type.GetName(record)}InitiallyUnownedBoxedHandle"; + + public static string GetFullyQuallifiedInternalBoxedHandle(GirModel.Record record) + => $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalBoxedHandle(record)}"; + + public static string GetFullyQuallifiedOwnedBoxedHandle(GirModel.Record record) + => $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalOwnedBoxedHandle(record)}"; + + public static string GetFullyQuallifiedInitiallyUnownedBoxedHandle(GirModel.Record record) + => $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalInitiallyUnownedBoxedHandle(record)}"; - public static string GetNullBoxedHandle(GirModel.Record record) - => $"GLib.Internal.BoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>.NullHandle"; + public static string GetFullyQuallifiedNullBoxedHandle(GirModel.Record record) + => $"{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}BoxedHandle.NullHandle"; } diff --git a/src/Generation/Generator/Records.cs b/src/Generation/Generator/Records.cs index df314ccbb..eae3e9e58 100644 --- a/src/Generation/Generator/Records.cs +++ b/src/Generation/Generator/Records.cs @@ -14,6 +14,7 @@ public static void Generate(IEnumerable records, string path) { //Opaque records new Generator.Internal.OpaqueRecord(publisher), + new Generator.Internal.OpaqueRecordHandle(publisher), new Generator.Public.OpaqueRecord(publisher), //Regular records diff --git a/src/Generation/Generator/Renderer/Internal/InstanceParameter/Converter/OpaqueRecord.cs b/src/Generation/Generator/Renderer/Internal/InstanceParameter/Converter/OpaqueRecord.cs index dea09a0c2..c591bd36f 100644 --- a/src/Generation/Generator/Renderer/Internal/InstanceParameter/Converter/OpaqueRecord.cs +++ b/src/Generation/Generator/Renderer/Internal/InstanceParameter/Converter/OpaqueRecord.cs @@ -13,7 +13,7 @@ public RenderableInstanceParameter Convert(GirModel.InstanceParameter instancePa return new RenderableInstanceParameter( Name: Model.InstanceParameter.GetName(instanceParameter), - NullableTypeName: Model.OpaqueRecord.GetBoxedHandle(type) + NullableTypeName: Model.OpaqueRecord.GetFullyQuallifiedInternalBoxedHandle(type) ); } } diff --git a/src/Generation/Generator/Renderer/Internal/OpaqueRecordHandle.cs b/src/Generation/Generator/Renderer/Internal/OpaqueRecordHandle.cs new file mode 100644 index 000000000..5b2f31395 --- /dev/null +++ b/src/Generation/Generator/Renderer/Internal/OpaqueRecordHandle.cs @@ -0,0 +1,67 @@ +using Generator.Model; + +namespace Generator.Renderer.Internal; + +internal static class OpaqueRecordHandle +{ + public static string Render(GirModel.Record record) + { + var typeName = Model.OpaqueRecord.GetInternalBoxedHandle(record); + var initiallyUnownedBoxedHandleTypeName = Model.OpaqueRecord.GetInternalInitiallyUnownedBoxedHandle(record); + var ownedBoxedHandleTypeName = Model.OpaqueRecord.GetInternalOwnedBoxedHandle(record); + var getGType = Model.OpaqueRecord.GetFullyQualifiedInternalClassName(record) + ".GetGType()"; + + return $@"using System; +using GObject; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; + +#nullable enable + +namespace {Namespace.GetInternalName(record.Namespace)}; + +// AUTOGENERATED FILE - DO NOT MODIFY + +{PlatformSupportAttribute.Render(record as GirModel.PlatformDependent)} +public partial class {typeName} : SafeHandle +{{ + public static readonly {typeName} NullHandle = new (IntPtr.Zero, false); + + public sealed override bool IsInvalid => handle == IntPtr.Zero; + + public {typeName}(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, true) + {{ + if (!ownsHandle) + handle = GLib.Internal.Functions.BoxedCopy({getGType}, handle); + + SetHandle(handle); + }} + + public {typeName}(bool ownsHandle) : base(IntPtr.Zero, ownsHandle) + {{ + throw new Exception(""How to free??""); + }} + + public {typeName} Copy() + {{ + return new (handle, false); + }} + + protected override bool ReleaseHandle() + {{ + GLib.Internal.Functions.BoxedFree({getGType}, handle); + return true; + }} +}} + +public class {initiallyUnownedBoxedHandleTypeName} : {typeName} +{{ + public {initiallyUnownedBoxedHandleTypeName}() : base(false) {{ }} +}} + +public class {ownedBoxedHandleTypeName} : {typeName} +{{ + public {ownedBoxedHandleTypeName}() : base(true) {{ }} +}}"; + } +} diff --git a/src/Generation/Generator/Renderer/Internal/Parameter/Converter/OpaqueRecord.cs b/src/Generation/Generator/Renderer/Internal/Parameter/Converter/OpaqueRecord.cs index 2c28bd225..b1f9fad2a 100644 --- a/src/Generation/Generator/Renderer/Internal/Parameter/Converter/OpaqueRecord.cs +++ b/src/Generation/Generator/Renderer/Internal/Parameter/Converter/OpaqueRecord.cs @@ -23,8 +23,10 @@ private static string GetNullableTypeName(GirModel.Parameter parameter) var type = (GirModel.Record) parameter.AnyTypeOrVarArgs.AsT0.AsT0; return parameter switch { - { Direction: GirModel.Direction.In, Transfer: GirModel.Transfer.None } => Model.OpaqueRecord.GetBoxedHandle(type) + Nullable.Render(parameter), - { Direction: GirModel.Direction.In, Transfer: GirModel.Transfer.Full } => Model.OpaqueRecord.GetBoxedHandle(type) + Nullable.Render(parameter), + { Direction: GirModel.Direction.In, Transfer: GirModel.Transfer.None } => Model.OpaqueRecord.GetFullyQuallifiedInternalBoxedHandle(type) + Nullable.Render(parameter), + { Direction: GirModel.Direction.In, Transfer: GirModel.Transfer.Full } => Model.OpaqueRecord.GetFullyQuallifiedInternalBoxedHandle(type) + Nullable.Render(parameter), + { Direction: GirModel.Direction.Out, Transfer: GirModel.Transfer.Full } => Model.OpaqueRecord.GetFullyQuallifiedInternalBoxedHandle(type) + Nullable.Render(parameter), + { Direction: GirModel.Direction.Out, Transfer: GirModel.Transfer.None } => Model.OpaqueRecord.GetFullyQuallifiedInternalBoxedHandle(type) + Nullable.Render(parameter), _ => throw new System.Exception($"Can't detect opaque record parameter type {parameter.Name}: CallerAllocates={parameter.CallerAllocates} Direction={parameter.Direction} Transfer={parameter.Transfer}") }; } diff --git a/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/OpaqueRecord.cs b/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/OpaqueRecord.cs new file mode 100644 index 000000000..e3122e534 --- /dev/null +++ b/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/OpaqueRecord.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace Generator.Renderer.Internal.ParameterToManagedExpressions; + +internal class OpaqueRecord : ToManagedParameterConverter +{ + public bool Supports(GirModel.AnyType type) + => type.Is(out var record) && record is { Opaque: true, TypeFunction: not null }; + + public void Initialize(ParameterToManagedData parameterData, IEnumerable parameters) + { + if (parameterData.Parameter.Direction != GirModel.Direction.In) + throw new NotImplementedException($"{parameterData.Parameter.AnyTypeOrVarArgs}: opaque record with direction != in not yet supported"); + + var record = (GirModel.Record) parameterData.Parameter.AnyTypeOrVarArgs.AsT0.AsT0; + var variableName = Model.Parameter.GetConvertedName(parameterData.Parameter); + + var signatureName = Model.Parameter.GetName(parameterData.Parameter); + + parameterData.SetSignatureName(signatureName); + parameterData.SetExpression($"var {variableName} = new {Model.OpaqueRecord.GetFullyQualifiedPublicClassName(record)}({signatureName});"); + parameterData.SetCallName(variableName); + } +} diff --git a/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/ParameterToManagedExpression.cs b/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/ParameterToManagedExpression.cs index ea56385fc..58e25de31 100644 --- a/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/ParameterToManagedExpression.cs +++ b/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/ParameterToManagedExpression.cs @@ -13,6 +13,7 @@ internal static class ParameterToManagedExpression new ParameterToManagedExpressions.Class(), new ParameterToManagedExpressions.Enumeration(), new ParameterToManagedExpressions.Interface(), + new ParameterToManagedExpressions.OpaqueRecord(), new ParameterToManagedExpressions.Pointer(), new ParameterToManagedExpressions.PointerAlias(), new ParameterToManagedExpressions.PrimitiveValueType(), diff --git a/src/Generation/Generator/Renderer/Internal/ReturnType/Converter/OpaqueRecord.cs b/src/Generation/Generator/Renderer/Internal/ReturnType/Converter/OpaqueRecord.cs index d767b5fc7..181eb26ec 100644 --- a/src/Generation/Generator/Renderer/Internal/ReturnType/Converter/OpaqueRecord.cs +++ b/src/Generation/Generator/Renderer/Internal/ReturnType/Converter/OpaqueRecord.cs @@ -15,8 +15,8 @@ public RenderableReturnType Convert(GirModel.ReturnType returnType) var typeName = returnType switch { - {Transfer: Transfer.Full} => Model.OpaqueRecord.GetOwnedBoxedHandle(type), - _ => Model.OpaqueRecord.GetInitiallyUnownedBoxedHandle(type) + {Transfer: Transfer.Full} => Model.OpaqueRecord.GetFullyQuallifiedOwnedBoxedHandle(type), + _ => Model.OpaqueRecord.GetFullyQuallifiedInitiallyUnownedBoxedHandle(type) }; return new RenderableReturnType(typeName + Nullable.Render(returnType)); diff --git a/src/Generation/Generator/Renderer/Internal/ReturnType/Converter/OpaqueRecordCallback.cs b/src/Generation/Generator/Renderer/Internal/ReturnType/Converter/OpaqueRecordCallback.cs new file mode 100644 index 000000000..8424e6e81 --- /dev/null +++ b/src/Generation/Generator/Renderer/Internal/ReturnType/Converter/OpaqueRecordCallback.cs @@ -0,0 +1,19 @@ +using GirModel; + +namespace Generator.Renderer.Internal.ReturnType; + +internal class OpaqueRecordCallback : ReturnTypeConverter +{ + public bool Supports(GirModel.ReturnType returnType) + { + return returnType.AnyType.Is(out var record) && record is { Opaque: true, TypeFunction: not null }; + } + + public RenderableReturnType Convert(GirModel.ReturnType returnType) + { + var type = (GirModel.Record) returnType.AnyType.AsT0; + var typeName = Model.OpaqueRecord.GetFullyQuallifiedInternalBoxedHandle(type); + + return new RenderableReturnType(typeName + Nullable.Render(returnType)); + } +} diff --git a/src/Generation/Generator/Renderer/Internal/ReturnType/ReturnTypeRendererCallback.cs b/src/Generation/Generator/Renderer/Internal/ReturnType/ReturnTypeRendererCallback.cs index fb98eb764..0deb41e75 100644 --- a/src/Generation/Generator/Renderer/Internal/ReturnType/ReturnTypeRendererCallback.cs +++ b/src/Generation/Generator/Renderer/Internal/ReturnType/ReturnTypeRendererCallback.cs @@ -12,6 +12,7 @@ internal static class ReturnTypeRendererCallback new ReturnType.Enumeration(), new ReturnType.Interface(), new ReturnType.InterfaceGLibPtrArray(), + new ReturnType.OpaqueRecordCallback(), new ReturnType.PlatformStringInCallback(), new ReturnType.Pointer(), new ReturnType.PrimitiveValueType(), diff --git a/src/Generation/Generator/Renderer/Internal/ReturnTypeToNativeExpression/Converter/OpaqueRecord.cs b/src/Generation/Generator/Renderer/Internal/ReturnTypeToNativeExpression/Converter/OpaqueRecord.cs new file mode 100644 index 000000000..1a8650724 --- /dev/null +++ b/src/Generation/Generator/Renderer/Internal/ReturnTypeToNativeExpression/Converter/OpaqueRecord.cs @@ -0,0 +1,12 @@ +using GirModel; + +namespace Generator.Renderer.Internal.ReturnTypeToNativeExpressions; + +internal class OpaqueRecord : ReturnTypeConverter +{ + public bool Supports(AnyType type) + => type.Is(out var record) && record is { Opaque: true, TypeFunction: not null }; + + public string GetString(GirModel.ReturnType returnType, string fromVariableName) + => fromVariableName + ".Handle"; +} diff --git a/src/Generation/Generator/Renderer/Internal/ReturnTypeToNativeExpression/ReturnTypeToNativeExpression.cs b/src/Generation/Generator/Renderer/Internal/ReturnTypeToNativeExpression/ReturnTypeToNativeExpression.cs index db050aa1f..1b2408ca8 100644 --- a/src/Generation/Generator/Renderer/Internal/ReturnTypeToNativeExpression/ReturnTypeToNativeExpression.cs +++ b/src/Generation/Generator/Renderer/Internal/ReturnTypeToNativeExpression/ReturnTypeToNativeExpression.cs @@ -10,6 +10,7 @@ internal static class ReturnTypeToNativeExpression new ReturnTypeToNativeExpressions.Class(), new ReturnTypeToNativeExpressions.Enumeration(), new ReturnTypeToNativeExpressions.Interface(), + new ReturnTypeToNativeExpressions.OpaqueRecord(), new ReturnTypeToNativeExpressions.Pointer(), new ReturnTypeToNativeExpressions.PrimitiveValueType(), new ReturnTypeToNativeExpressions.PrimitiveValueTypeAlias(), diff --git a/src/Generation/Generator/Renderer/Public/OpaqueRecord.cs b/src/Generation/Generator/Renderer/Public/OpaqueRecord.cs index 8fb19b3a5..21eaacc65 100644 --- a/src/Generation/Generator/Renderer/Public/OpaqueRecord.cs +++ b/src/Generation/Generator/Renderer/Public/OpaqueRecord.cs @@ -8,11 +8,12 @@ internal static class OpaqueRecord { public static string Render(GirModel.Record record) { - var name = Record.GetPublicClassName(record); - var internalHandleName = $"{Namespace.GetInternalName(record.Namespace)}.{Model.Type.GetName(record)}"; + var name = Model.OpaqueRecord.GetPublicClassName(record); + var internalHandleName = Model.OpaqueRecord.GetFullyQuallifiedInternalBoxedHandle(record); return $@" using System; +using System.Linq; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -25,9 +26,9 @@ namespace {Namespace.GetPublicName(record.Namespace)}; {PlatformSupportAttribute.Render(record as GirModel.PlatformDependent)} public partial class {name} {{ - public GLib.Internal.BoxedHandle<{internalHandleName}> Handle {{ get; }} + public {internalHandleName} Handle {{ get; }} - public {name}(GLib.Internal.BoxedHandle<{internalHandleName}> handle) + public {name}({internalHandleName} handle) {{ Handle = handle; Initialize(); diff --git a/src/Generation/Generator/Renderer/Public/ParameterToNativeExpression/Converter/OpaqueRecord.cs b/src/Generation/Generator/Renderer/Public/ParameterToNativeExpression/Converter/OpaqueRecord.cs index a8061128e..6f08b584f 100644 --- a/src/Generation/Generator/Renderer/Public/ParameterToNativeExpression/Converter/OpaqueRecord.cs +++ b/src/Generation/Generator/Renderer/Public/ParameterToNativeExpression/Converter/OpaqueRecord.cs @@ -19,9 +19,9 @@ public void Initialize(ParameterToNativeData parameter, IEnumerable signatureName + "?.Handle ?? " + Model.OpaqueRecord.GetNullBoxedHandle(record), + { Nullable: true, Transfer: GirModel.Transfer.None } => signatureName + "?.Handle ?? " + Model.OpaqueRecord.GetFullyQuallifiedNullBoxedHandle(record), { Nullable: false, Transfer: GirModel.Transfer.None} => signatureName + ".Handle", - { Nullable: true, Transfer: GirModel.Transfer.Full } => signatureName + "?.Handle.Copy() ?? " + Model.OpaqueRecord.GetNullBoxedHandle(record), + { Nullable: true, Transfer: GirModel.Transfer.Full } => signatureName + "?.Handle.Copy() ?? " + Model.OpaqueRecord.GetFullyQuallifiedNullBoxedHandle(record), { Nullable: false, Transfer: GirModel.Transfer.Full } => signatureName + ".Handle.Copy()", _ => throw new Exception($"Can't detect call name for parameter opaque parameter {parameter.Parameter.Name}") }; diff --git a/src/Generation/Generator/Renderer/Public/ReturnType/ReturnTypeRendererCallback.cs b/src/Generation/Generator/Renderer/Public/ReturnType/ReturnTypeRendererCallback.cs index 44b6a2de4..0b1a85c76 100644 --- a/src/Generation/Generator/Renderer/Public/ReturnType/ReturnTypeRendererCallback.cs +++ b/src/Generation/Generator/Renderer/Public/ReturnType/ReturnTypeRendererCallback.cs @@ -10,6 +10,7 @@ internal static class ReturnTypeRendererCallback new ReturnType.Class(), new ReturnType.Enumeration(), new ReturnType.Interface(), + new ReturnType.OpaqueRecord(), new ReturnType.Pointer(), new ReturnType.PointerAlias(), new ReturnType.PrimitiveValueType(), diff --git a/src/Libs/GLib-2.0/Internal/BoxedHandle.cs b/src/Libs/GLib-2.0/Internal/BoxedHandle.cs index 24e6a595f..d8f69f156 100644 --- a/src/Libs/GLib-2.0/Internal/BoxedHandle.cs +++ b/src/Libs/GLib-2.0/Internal/BoxedHandle.cs @@ -45,6 +45,7 @@ public class InitiallyUnownedBoxedHandle : BoxedHandle where T : NativeGTy { public InitiallyUnownedBoxedHandle(IntPtr handle) : base(handle, false) { + throw new Exception("TEST IF CALLED"); } } @@ -52,5 +53,6 @@ public class OwnedBoxedHandle : BoxedHandle where T : NativeGTypeProvider { public OwnedBoxedHandle(IntPtr handle) : base(handle, true) { + throw new Exception("TEST IF CALLED"); } } diff --git a/src/Libs/GLib-2.0/Public/Variant.cs b/src/Libs/GLib-2.0/Public/Variant.cs index 7f814569d..c0357be90 100644 --- a/src/Libs/GLib-2.0/Public/Variant.cs +++ b/src/Libs/GLib-2.0/Public/Variant.cs @@ -1,5 +1,4 @@ using System; -using GLib.Internal; namespace GLib; @@ -42,7 +41,7 @@ public static Variant CreateEmptyDictionary(VariantType key, VariantType value) return new Variant(Internal.Variant.NewArray(childType, new IntPtr[0], 0)); } - private void Init(out BoxedHandle handle, params Variant[] children) + private void Init(out GLib.Internal.VariantBoxedHandle handle, params Variant[] children) { _children = children; diff --git a/src/Libs/GLib-2.0/Public/VariantType.cs b/src/Libs/GLib-2.0/Public/VariantType.cs index cefc6d6af..1105e4400 100644 --- a/src/Libs/GLib-2.0/Public/VariantType.cs +++ b/src/Libs/GLib-2.0/Public/VariantType.cs @@ -5,30 +5,12 @@ namespace GLib; public partial class VariantType : IDisposable { - #region Static Member - - public static readonly VariantType String = new VariantType("s"); - public static readonly VariantType Variant = new VariantType("v"); - - #endregion - - #region Constructors - - public VariantType(string type) : this(Internal.VariantType.New(Internal.NonNullableUtf8StringOwnedHandle.Create(type))) { } - - #endregion - - #region Methods + public static readonly VariantType String = New("s"); + public static readonly VariantType Variant = New("v"); public override string ToString() => Internal.VariantType.PeekString(Handle).ConvertToString(); - #endregion - - #region IDisposable Implementation - public void Dispose() => Handle.Dispose(); - - #endregion } diff --git a/src/Libs/Gio-2.0/Public/DBusConnection.cs b/src/Libs/Gio-2.0/Public/DBusConnection.cs index ee60066d5..617542d6e 100644 --- a/src/Libs/Gio-2.0/Public/DBusConnection.cs +++ b/src/Libs/Gio-2.0/Public/DBusConnection.cs @@ -40,18 +40,18 @@ public Task CallAsync(string busName, string objectPath, string interfa Internal.DBusConnection.Call(Handle, GLib.Internal.NullableUtf8StringOwnedHandle.Create(busName), GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(objectPath), GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(interfaceName), GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(methodName), - parameters.GetSafeHandle(), GLib.Internal.VariantTypeNullHandle.Instance, DBusCallFlags.None, -1, IntPtr.Zero, callbackHandler.NativeCallback, IntPtr.Zero); + parameters?.Handle, null, DBusCallFlags.None, -1, IntPtr.Zero, callbackHandler.NativeCallback, IntPtr.Zero); return tcs.Task; } public Variant Call(string busName, string objectPath, string interfaceName, string methodName, Variant? parameters = null) { - var parameterHandle = parameters?.Handle ?? GLib.Internal.VariantNullHandle.Instance; + var parameterHandle = parameters?.Handle; var ret = Internal.DBusConnection.CallSync(Handle, GLib.Internal.NullableUtf8StringOwnedHandle.Create(busName), GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(objectPath), GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(interfaceName), GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(methodName), - parameterHandle, GLib.Internal.VariantTypeNullHandle.Instance, DBusCallFlags.None, 9999, IntPtr.Zero, out var error); + parameterHandle, null, DBusCallFlags.None, 9999, IntPtr.Zero, out var error); if (!error.IsInvalid) throw new GException(error); diff --git a/src/Native/GirTestLib/girtest-opaque-record-tester.c b/src/Native/GirTestLib/girtest-opaque-record-tester.c index a16775362..6ff6e112f 100644 --- a/src/Native/GirTestLib/girtest-opaque-record-tester.c +++ b/src/Native/GirTestLib/girtest-opaque-record-tester.c @@ -99,4 +99,21 @@ void girtest_opaque_record_tester_take_and_unref_func(int dummy, GirTestOpaqueRecordTester *data) { girtest_opaque_record_tester_take_and_unref(data); +} + +/** + * girtest_opaque_record_tester_run_return_opaque_record_tester_none_callback: + * @callback: (scope call): a callback + * + * Calls the callback and returns the newly created instance. + * + * Returns: A pointer to the opaque record + **/ +gpointer +girtest_opaque_record_tester_run_return_opaque_record_tester_none_callback(GirTestReturnOpaqueRecordTesterNone callback) +{ + GirTestOpaqueRecordTester* result = callback(); + girtest_opaque_record_tester_ref(result); + + return (gpointer) result; } \ No newline at end of file diff --git a/src/Native/GirTestLib/girtest-opaque-record-tester.h b/src/Native/GirTestLib/girtest-opaque-record-tester.h index 8bd4c0767..835f7ca54 100644 --- a/src/Native/GirTestLib/girtest-opaque-record-tester.h +++ b/src/Native/GirTestLib/girtest-opaque-record-tester.h @@ -9,10 +9,18 @@ typedef struct _GirTestOpaqueRecordTester GirTestOpaqueRecordTester; GType girtest_opaque_record_tester_get_type (void) G_GNUC_CONST; +/** + * GirTestReturnOpaqueRecordTesterNone: + * + * Returns: (transfer none): a new OpaqueRecordTester. + */ +typedef GirTestOpaqueRecordTester* (*GirTestReturnOpaqueRecordTesterNone) (); + GirTestOpaqueRecordTester * girtest_opaque_record_tester_new (); GirTestOpaqueRecordTester * girtest_opaque_record_tester_ref (GirTestOpaqueRecordTester *self); void girtest_opaque_record_tester_unref(GirTestOpaqueRecordTester *self); int girtest_opaque_record_tester_get_ref_count(GirTestOpaqueRecordTester *self); void girtest_opaque_record_tester_take_and_unref(GirTestOpaqueRecordTester *self); void girtest_opaque_record_tester_take_and_unref_func(int dummy, GirTestOpaqueRecordTester *data); +gpointer girtest_opaque_record_tester_run_return_opaque_record_tester_none_callback(GirTestReturnOpaqueRecordTesterNone callback); G_END_DECLS diff --git a/src/Tests/Libs/GLib-2.0.Tests/Records/VariantTypeTest.cs b/src/Tests/Libs/GLib-2.0.Tests/Records/VariantTypeTest.cs index fb5134235..2251c23b2 100644 --- a/src/Tests/Libs/GLib-2.0.Tests/Records/VariantTypeTest.cs +++ b/src/Tests/Libs/GLib-2.0.Tests/Records/VariantTypeTest.cs @@ -21,7 +21,7 @@ public class VariantTypeTest : Test [DataRow("v")] public void CanCreateTypeFromString(string type) { - var variantType = new VariantType(type); + var variantType = VariantType.New(type); variantType.ToString().Should().Be(type); } diff --git a/src/Tests/Libs/Gio-2.0.Tests/SimpleActionTest.cs b/src/Tests/Libs/Gio-2.0.Tests/SimpleActionTest.cs index c8c3e49f1..3220de0be 100644 --- a/src/Tests/Libs/Gio-2.0.Tests/SimpleActionTest.cs +++ b/src/Tests/Libs/Gio-2.0.Tests/SimpleActionTest.cs @@ -11,10 +11,10 @@ public void TestActivate() { var action = SimpleAction.NewStateful("myname", GLib.VariantType.String, GLib.Variant.NewString("foo")); - string result = action.GetState().GetString(); + var result = action.GetState()?.GetString(out _); action.OnActivate += (_, args) => { - result = args.Parameter!.GetString(); + result = args.Parameter!.GetString(out var length); }; action.Activate(GLib.Variant.NewString("bar")); diff --git a/src/Tests/Libs/GirTest-0.1.Tests/OpaqueRecordTest.cs b/src/Tests/Libs/GirTest-0.1.Tests/OpaqueRecordTest.cs index 2f1c66088..06966f229 100644 --- a/src/Tests/Libs/GirTest-0.1.Tests/OpaqueRecordTest.cs +++ b/src/Tests/Libs/GirTest-0.1.Tests/OpaqueRecordTest.cs @@ -43,4 +43,19 @@ public void CanTransferOwnershipFunc() OpaqueRecordTester.TakeAndUnrefFunc(0, recordTester); recordTester.GetRefCount().Should().Be(1); } + + [TestMethod] + public void CanRunReturnOpaqueRecordTesterNoneCallback() + { + var recordTester = OpaqueRecordTester.New(); + + OpaqueRecordTester Create() + { + return recordTester; + } + + var ptr = OpaqueRecordTester.RunReturnOpaqueRecordTesterNoneCallback(Create); + + ptr.Should().Be(recordTester.Handle.DangerousGetHandle()); + } }