Skip to content

Commit f82cf3a

Browse files
committed
Fix operand order for NativeMemory.Copy
1 parent dc417d9 commit f82cf3a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,28 @@ private void VisitCallExpr(CallExpr callExpr)
191191
{
192192
case "memcpy":
193193
{
194+
var args = callExpr.Args;
195+
194196
if (Config.GenerateLatestCode)
195197
{
196198
outputBuilder.AddUsingDirective("System.Runtime.InteropServices");
197199
outputBuilder.Write("NativeMemory.Copy");
200+
201+
if (args.Count == 3)
202+
{
203+
// Swap the operands around:
204+
// * NativeMemory.Copy takes: source, dest, count
205+
// * memcpy takes: dest, source, count
206+
args = [args[1], args[0], args[2]];
207+
}
198208
}
199209
else
200210
{
201211
outputBuilder.AddUsingDirective("System.Runtime.CompilerServices");
202212
outputBuilder.Write("Unsafe.CopyBlockUnaligned");
203213
}
204214

205-
VisitArgs(callExpr);
215+
VisitArgs(callExpr, args);
206216
break;
207217
}
208218

0 commit comments

Comments
 (0)