Skip to content

Commit

Permalink
Don't assume pointers are auto-dereferenced
Browse files Browse the repository at this point in the history
Fixes a regression introduced in commit bf6b7b5.
  • Loading branch information
kleisauke committed May 9, 2024
1 parent 4fba0cf commit 839c22a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/NetVips/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class Image : VipsObject
/// Internal marshaller delegate for <see cref="EvalDelegate"/>.
/// </summary>
[SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void EvalMarshalDelegate(IntPtr imagePtr, VipsProgress progress, IntPtr userDataPtr);
internal delegate void EvalMarshalDelegate(IntPtr imagePtr, IntPtr progressPtr, IntPtr userDataPtr);

/// <inheritdoc cref="VipsObject"/>
internal Image(IntPtr pointer)
Expand Down Expand Up @@ -2103,16 +2103,18 @@ public void SetKill(bool kill)
/// <exception cref="T:System.ArgumentException">If it failed to connect the signal.</exception>
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;
}

using var image = new Image(imagePtr);
image.ObjectRef();

var progress = Marshal.PtrToStructure<VipsProgress>(progressPtr);

callback.Invoke(image, progress);
}

Expand Down
4 changes: 2 additions & 2 deletions src/NetVips/Internal/Vips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/NetVips/Introspect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<VipsArgumentClass>(argumentClass).Flags;
if ((flags & Enums.ArgumentFlags.CONSTRUCT) == 0)
{
return IntPtr.Zero;
}

var name = Marshal.PtrToStringAnsi(pspec.Name);
var name = Marshal.PtrToStringAnsi(Marshal.PtrToStructure<GParamSpec.Struct>(pspec).Name);

AddArg(name, flags);

Expand Down
10 changes: 8 additions & 2 deletions src/NetVips/VipsProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public struct GTimer
/// <summary>
/// Is the timer currently active?
/// </summary>
public int Active;
[MarshalAs(UnmanagedType.I1)]
public bool Active;
}

/// <summary>
Expand Down Expand Up @@ -65,6 +66,11 @@ public struct VipsProgress
/// <summary>
/// Start time.
/// </summary>
public GTimer Start;
private IntPtr StartPtr;

/// <summary>
/// Start time.
/// </summary>
public GTimer Start => Marshal.PtrToStructure<GTimer>(StartPtr);
}
}

0 comments on commit 839c22a

Please sign in to comment.