Skip to content

Commit 0da9c46

Browse files
committed
Pass native pointers to bases in the generated C#
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent c214b10 commit 0da9c46

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ private void GenerateNativeConstructor(Class @class)
21862186

21872187
var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType;
21882188
if (hasBaseClass)
2189-
WriteLineIndent(": base((void*) null)", @class.BaseClass.Visit(TypePrinter));
2189+
WriteLineIndent(": base((void*) native)", @class.BaseClass.Visit(TypePrinter));
21902190

21912191
WriteOpenBraceAndIndent();
21922192

@@ -2195,15 +2195,15 @@ private void GenerateNativeConstructor(Class @class)
21952195
if (@class.BaseClass?.Layout.HasSubclassAtNonZeroOffset == true)
21962196
WriteLine("{0} = {1};", Helpers.PrimaryBaseOffsetIdentifier,
21972197
GetOffsetToBase(@class, @class.BaseClass));
2198-
if (!@class.IsAbstractImpl)
2198+
var hasVTables = @class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count > 0;
2199+
if (!hasBaseClass || hasVTables)
21992200
{
22002201
WriteLine("if (native == null)");
22012202
WriteLineIndent("return;");
2203+
if (!hasBaseClass)
2204+
WriteLine($"{Helpers.InstanceIdentifier} = new global::System.IntPtr(native);");
22022205
}
2203-
2204-
WriteLine("{0} = new global::System.IntPtr(native);", Helpers.InstanceIdentifier);
22052206
var dtor = @class.Destructors.FirstOrDefault();
2206-
var hasVTables = @class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count > 0;
22072207
var setupVTables = !@class.IsAbstractImpl && hasVTables && dtor?.IsVirtual == true;
22082208
if (setupVTables)
22092209
{
@@ -2223,7 +2223,7 @@ private void GenerateNativeConstructor(Class @class)
22232223
Unindent();
22242224
}
22252225
}
2226-
else
2226+
else if (!hasBaseClass)
22272227
{
22282228
WriteLine($"{Helpers.InstanceField} = *({TypePrinter.PrintNative(@class)}*) native;");
22292229
}

0 commit comments

Comments
 (0)