From 839c22a7a9eacf43983003121bc50c5f692b4fbb Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 9 May 2024 14:20:15 +0200 Subject: [PATCH] Don't assume pointers are auto-dereferenced Fixes a regression introduced in commit bf6b7b5. --- src/NetVips/Image.cs | 8 +++++--- src/NetVips/Internal/Vips.cs | 4 ++-- src/NetVips/Introspect.cs | 8 ++++---- src/NetVips/VipsProgress.cs | 10 ++++++++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/NetVips/Image.cs b/src/NetVips/Image.cs index 24266805..2bf58e2f 100644 --- a/src/NetVips/Image.cs +++ b/src/NetVips/Image.cs @@ -30,7 +30,7 @@ public partial class Image : VipsObject /// Internal marshaller delegate for . /// [SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void EvalMarshalDelegate(IntPtr imagePtr, VipsProgress progress, IntPtr userDataPtr); + internal delegate void EvalMarshalDelegate(IntPtr imagePtr, IntPtr progressPtr, IntPtr userDataPtr); /// internal Image(IntPtr pointer) @@ -2103,9 +2103,9 @@ public void SetKill(bool kill) /// If it failed to connect the signal. public ulong SignalConnect(Enums.Signals signal, EvalDelegate callback, IntPtr data = default) { - void EvalMarshal(IntPtr imagePtr, VipsProgress progress, IntPtr userDataPtr) + void EvalMarshal(IntPtr imagePtr, IntPtr progressPtr, IntPtr userDataPtr) { - if (imagePtr == IntPtr.Zero) + if (imagePtr == IntPtr.Zero || progressPtr == IntPtr.Zero) { return; } @@ -2113,6 +2113,8 @@ void EvalMarshal(IntPtr imagePtr, VipsProgress progress, IntPtr userDataPtr) using var image = new Image(imagePtr); image.ObjectRef(); + var progress = Marshal.PtrToStructure(progressPtr); + callback.Invoke(image, progress); } diff --git a/src/NetVips/Internal/Vips.cs b/src/NetVips/Internal/Vips.cs index ecd355ad..4f28f4a5 100644 --- a/src/NetVips/Internal/Vips.cs +++ b/src/NetVips/Internal/Vips.cs @@ -17,8 +17,8 @@ internal static class Vips internal delegate IntPtr TypeMap2Fn(IntPtr type, IntPtr a, IntPtr b); [SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr ArgumentMapFn(IntPtr @object, GParamSpec.Struct pspec, VipsArgumentClass argumentClass, - VipsArgumentInstance argumentInstance, IntPtr a, IntPtr b); + internal delegate IntPtr ArgumentMapFn(IntPtr @object, IntPtr pspec, IntPtr argumentClass, + IntPtr argumentInstance, IntPtr a, IntPtr b); [SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int CallbackFn(IntPtr a, IntPtr b); diff --git a/src/NetVips/Introspect.cs b/src/NetVips/Introspect.cs index e329af14..b7fd9539 100644 --- a/src/NetVips/Introspect.cs +++ b/src/NetVips/Introspect.cs @@ -189,16 +189,16 @@ void AddArg(string name, Enums.ArgumentFlags flags) } else { - IntPtr AddConstruct(IntPtr self, GParamSpec.Struct pspec, VipsArgumentClass argumentClass, - VipsArgumentInstance argumentInstance, IntPtr a, IntPtr b) + IntPtr AddConstruct(IntPtr self, IntPtr pspec, IntPtr argumentClass, IntPtr argumentInstance, + IntPtr a, IntPtr b) { - var flags = argumentClass.Flags; + var flags = Marshal.PtrToStructure(argumentClass).Flags; if ((flags & Enums.ArgumentFlags.CONSTRUCT) == 0) { return IntPtr.Zero; } - var name = Marshal.PtrToStringAnsi(pspec.Name); + var name = Marshal.PtrToStringAnsi(Marshal.PtrToStructure(pspec).Name); AddArg(name, flags); diff --git a/src/NetVips/VipsProgress.cs b/src/NetVips/VipsProgress.cs index 1346aaf4..a086d224 100644 --- a/src/NetVips/VipsProgress.cs +++ b/src/NetVips/VipsProgress.cs @@ -22,7 +22,8 @@ public struct GTimer /// /// Is the timer currently active? /// - public int Active; + [MarshalAs(UnmanagedType.I1)] + public bool Active; } /// @@ -65,6 +66,11 @@ public struct VipsProgress /// /// Start time. /// - public GTimer Start; + private IntPtr StartPtr; + + /// + /// Start time. + /// + public GTimer Start => Marshal.PtrToStructure(StartPtr); } } \ No newline at end of file