Browse Source

Generate valid C# for base types with public fields of const char*

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1376/head
Dimitar Dobrev 4 years ago
parent
commit
f97ad43ce4
  1. 4
      src/AST/ClassExtensions.cs
  2. 18
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs
  3. 18
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs
  4. 18
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs
  5. 18
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  6. 18
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  7. 18
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs
  8. 39
      src/Generator/Generators/CSharp/CSharpSources.cs

4
src/AST/ClassExtensions.cs

@ -242,6 +242,10 @@ namespace CppSharp.AST @@ -242,6 +242,10 @@ namespace CppSharp.AST
b => b.Class).Any(HasDependentValueFieldInLayout);
}
public static IEnumerable<Property> GetConstCharFieldProperties(this Class @class) =>
@class.Properties.Where(p => p.HasGetter && p.HasSetter &&
p.Field?.QualifiedType.Type.IsConstCharString() == true);
private static bool IsValueDependent(Type type)
{
var desugared = type.Desugar();

18
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs

@ -16620,6 +16620,7 @@ namespace CppSharp @@ -16620,6 +16620,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __name_OwnsNativeMemory = false;
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new LabelStmt(native.ToPointer(), skipVTables);
@ -16677,6 +16678,8 @@ namespace CppSharp @@ -16677,6 +16678,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
if (_0.__name_OwnsNativeMemory)
this.Name = _0.Name;
}
public global::CppSharp.Parser.SourceLocation IdentLoc
@ -16715,6 +16718,9 @@ namespace CppSharp @@ -16715,6 +16718,9 @@ namespace CppSharp
set
{
if (__name_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
__name_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@ -25167,6 +25173,7 @@ namespace CppSharp @@ -25167,6 +25173,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castKindName_OwnsNativeMemory = false;
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CastExpr(native.ToPointer(), skipVTables);
@ -25233,6 +25240,8 @@ namespace CppSharp @@ -25233,6 +25240,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
if (_0.__castKindName_OwnsNativeMemory)
this.CastKindName = _0.CastKindName;
}
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -25276,6 +25285,9 @@ namespace CppSharp @@ -25276,6 +25285,9 @@ namespace CppSharp
set
{
if (__castKindName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
__castKindName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@ -30958,6 +30970,7 @@ namespace CppSharp @@ -30958,6 +30970,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castName_OwnsNativeMemory = false;
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@ -31024,6 +31037,8 @@ namespace CppSharp @@ -31024,6 +31037,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
if (_0.__castName_OwnsNativeMemory)
this.CastName = _0.CastName;
}
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -31040,6 +31055,9 @@ namespace CppSharp @@ -31040,6 +31055,9 @@ namespace CppSharp
set
{
if (__castName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
__castName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

18
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

@ -16622,6 +16622,7 @@ namespace CppSharp @@ -16622,6 +16622,7 @@ namespace CppSharp
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __name_OwnsNativeMemory = false;
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new LabelStmt(native.ToPointer(), skipVTables);
@ -16679,6 +16680,8 @@ namespace CppSharp @@ -16679,6 +16680,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
if (_0.__name_OwnsNativeMemory)
this.Name = _0.Name;
}
public global::CppSharp.Parser.SourceLocation IdentLoc
@ -16717,6 +16720,9 @@ namespace CppSharp @@ -16717,6 +16720,9 @@ namespace CppSharp
set
{
if (__name_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
__name_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@ -25171,6 +25177,7 @@ namespace CppSharp @@ -25171,6 +25177,7 @@ namespace CppSharp
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castKindName_OwnsNativeMemory = false;
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CastExpr(native.ToPointer(), skipVTables);
@ -25237,6 +25244,8 @@ namespace CppSharp @@ -25237,6 +25244,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
if (_0.__castKindName_OwnsNativeMemory)
this.CastKindName = _0.CastKindName;
}
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -25280,6 +25289,9 @@ namespace CppSharp @@ -25280,6 +25289,9 @@ namespace CppSharp
set
{
if (__castKindName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
__castKindName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@ -30963,6 +30975,7 @@ namespace CppSharp @@ -30963,6 +30975,7 @@ namespace CppSharp
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castName_OwnsNativeMemory = false;
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@ -31029,6 +31042,8 @@ namespace CppSharp @@ -31029,6 +31042,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
if (_0.__castName_OwnsNativeMemory)
this.CastName = _0.CastName;
}
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -31045,6 +31060,9 @@ namespace CppSharp @@ -31045,6 +31060,9 @@ namespace CppSharp
set
{
if (__castName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
__castName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

18
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

@ -16619,6 +16619,7 @@ namespace CppSharp @@ -16619,6 +16619,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __name_OwnsNativeMemory = false;
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new LabelStmt(native.ToPointer(), skipVTables);
@ -16676,6 +16677,8 @@ namespace CppSharp @@ -16676,6 +16677,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
if (_0.__name_OwnsNativeMemory)
this.Name = _0.Name;
}
public global::CppSharp.Parser.SourceLocation IdentLoc
@ -16714,6 +16717,9 @@ namespace CppSharp @@ -16714,6 +16717,9 @@ namespace CppSharp
set
{
if (__name_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
__name_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@ -25166,6 +25172,7 @@ namespace CppSharp @@ -25166,6 +25172,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castKindName_OwnsNativeMemory = false;
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CastExpr(native.ToPointer(), skipVTables);
@ -25232,6 +25239,8 @@ namespace CppSharp @@ -25232,6 +25239,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
if (_0.__castKindName_OwnsNativeMemory)
this.CastKindName = _0.CastKindName;
}
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -25275,6 +25284,9 @@ namespace CppSharp @@ -25275,6 +25284,9 @@ namespace CppSharp
set
{
if (__castKindName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
__castKindName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@ -30957,6 +30969,7 @@ namespace CppSharp @@ -30957,6 +30969,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castName_OwnsNativeMemory = false;
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@ -31023,6 +31036,8 @@ namespace CppSharp @@ -31023,6 +31036,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
if (_0.__castName_OwnsNativeMemory)
this.CastName = _0.CastName;
}
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -31039,6 +31054,9 @@ namespace CppSharp @@ -31039,6 +31054,9 @@ namespace CppSharp
set
{
if (__castName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
__castName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

18
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

@ -16619,6 +16619,7 @@ namespace CppSharp @@ -16619,6 +16619,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __name_OwnsNativeMemory = false;
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new LabelStmt(native.ToPointer(), skipVTables);
@ -16676,6 +16677,8 @@ namespace CppSharp @@ -16676,6 +16677,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
if (_0.__name_OwnsNativeMemory)
this.Name = _0.Name;
}
public global::CppSharp.Parser.SourceLocation IdentLoc
@ -16714,6 +16717,9 @@ namespace CppSharp @@ -16714,6 +16717,9 @@ namespace CppSharp
set
{
if (__name_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
__name_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@ -25166,6 +25172,7 @@ namespace CppSharp @@ -25166,6 +25172,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castKindName_OwnsNativeMemory = false;
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CastExpr(native.ToPointer(), skipVTables);
@ -25232,6 +25239,8 @@ namespace CppSharp @@ -25232,6 +25239,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
if (_0.__castKindName_OwnsNativeMemory)
this.CastKindName = _0.CastKindName;
}
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -25275,6 +25284,9 @@ namespace CppSharp @@ -25275,6 +25284,9 @@ namespace CppSharp
set
{
if (__castKindName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
__castKindName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@ -30957,6 +30969,7 @@ namespace CppSharp @@ -30957,6 +30969,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castName_OwnsNativeMemory = false;
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@ -31023,6 +31036,8 @@ namespace CppSharp @@ -31023,6 +31036,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
if (_0.__castName_OwnsNativeMemory)
this.CastName = _0.CastName;
}
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -31039,6 +31054,9 @@ namespace CppSharp @@ -31039,6 +31054,9 @@ namespace CppSharp
set
{
if (__castName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
__castName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

18
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

@ -16619,6 +16619,7 @@ namespace CppSharp @@ -16619,6 +16619,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __name_OwnsNativeMemory = false;
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new LabelStmt(native.ToPointer(), skipVTables);
@ -16676,6 +16677,8 @@ namespace CppSharp @@ -16676,6 +16677,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
if (_0.__name_OwnsNativeMemory)
this.Name = _0.Name;
}
public global::CppSharp.Parser.SourceLocation IdentLoc
@ -16714,6 +16717,9 @@ namespace CppSharp @@ -16714,6 +16717,9 @@ namespace CppSharp
set
{
if (__name_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
__name_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@ -25166,6 +25172,7 @@ namespace CppSharp @@ -25166,6 +25172,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castKindName_OwnsNativeMemory = false;
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CastExpr(native.ToPointer(), skipVTables);
@ -25232,6 +25239,8 @@ namespace CppSharp @@ -25232,6 +25239,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
if (_0.__castKindName_OwnsNativeMemory)
this.CastKindName = _0.CastKindName;
}
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -25275,6 +25284,9 @@ namespace CppSharp @@ -25275,6 +25284,9 @@ namespace CppSharp
set
{
if (__castKindName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
__castKindName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@ -30957,6 +30969,7 @@ namespace CppSharp @@ -30957,6 +30969,7 @@ namespace CppSharp
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castName_OwnsNativeMemory = false;
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@ -31023,6 +31036,8 @@ namespace CppSharp @@ -31023,6 +31036,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
if (_0.__castName_OwnsNativeMemory)
this.CastName = _0.CastName;
}
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -31039,6 +31054,9 @@ namespace CppSharp @@ -31039,6 +31054,9 @@ namespace CppSharp
set
{
if (__castName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
__castName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

18
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs

@ -16623,6 +16623,7 @@ namespace CppSharp @@ -16623,6 +16623,7 @@ namespace CppSharp
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __name_OwnsNativeMemory = false;
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new LabelStmt(native.ToPointer(), skipVTables);
@ -16680,6 +16681,8 @@ namespace CppSharp @@ -16680,6 +16681,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
if (_0.__name_OwnsNativeMemory)
this.Name = _0.Name;
}
public global::CppSharp.Parser.SourceLocation IdentLoc
@ -16718,6 +16721,9 @@ namespace CppSharp @@ -16718,6 +16721,9 @@ namespace CppSharp
set
{
if (__name_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
__name_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@ -25181,6 +25187,7 @@ namespace CppSharp @@ -25181,6 +25187,7 @@ namespace CppSharp
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castKindName_OwnsNativeMemory = false;
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CastExpr(native.ToPointer(), skipVTables);
@ -25247,6 +25254,8 @@ namespace CppSharp @@ -25247,6 +25254,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
if (_0.__castKindName_OwnsNativeMemory)
this.CastKindName = _0.CastKindName;
}
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -25290,6 +25299,9 @@ namespace CppSharp @@ -25290,6 +25299,9 @@ namespace CppSharp
set
{
if (__castKindName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
__castKindName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@ -30986,6 +30998,7 @@ namespace CppSharp @@ -30986,6 +30998,7 @@ namespace CppSharp
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
}
private bool __castName_OwnsNativeMemory = false;
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@ -31052,6 +31065,8 @@ namespace CppSharp @@ -31052,6 +31065,8 @@ namespace CppSharp
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
if (_0.__castName_OwnsNativeMemory)
this.CastName = _0.CastName;
}
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@ -31068,6 +31083,9 @@ namespace CppSharp @@ -31068,6 +31083,9 @@ namespace CppSharp
set
{
if (__castName_OwnsNativeMemory)
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
__castName_OwnsNativeMemory = true;
if (value == null)
{
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

39
src/Generator/Generators/CSharp/CSharpSources.cs

@ -455,16 +455,16 @@ namespace CppSharp.Generators.CSharp @@ -455,16 +455,16 @@ namespace CppSharp.Generators.CSharp
var dict = $@"global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, {
printedClass}>";
WriteLine("internal static readonly {0} NativeToManagedMap = new {0}();", dict);
// Add booleans to track who owns unmanaged memory for string fields
foreach (var field in @class.Layout.Fields.Where(f => f.QualifiedType.Type.IsConstCharString()))
{
WriteLine($"private bool __{field.Name}_OwnsNativeMemory = false;");
}
}
PopBlock(NewLineKind.BeforeNextBlock);
}
// Add booleans to track who owns unmanaged memory for string fields
foreach (var prop in @class.GetConstCharFieldProperties())
{
WriteLine($"private bool __{prop.Field.OriginalName}_OwnsNativeMemory = false;");
}
GenerateClassConstructors(@class);
GenerateClassMethods(@class.Methods);
@ -2302,7 +2302,7 @@ namespace CppSharp.Generators.CSharp @@ -2302,7 +2302,7 @@ namespace CppSharp.Generators.CSharp
// }
//
// IDisposable.Dispose() and Object.Finalize() set callNativeDtor = Helpers.OwnsNativeInstanceIdentifier
WriteLine($"if (callNativeDtor)");
WriteLine("if (callNativeDtor)");
if (@class.IsDependent || dtor.IsVirtual)
WriteOpenBraceAndIndent();
else
@ -2325,10 +2325,11 @@ namespace CppSharp.Generators.CSharp @@ -2325,10 +2325,11 @@ namespace CppSharp.Generators.CSharp
// unmanaged memory isn't always initialized and/or a reference may be owned by the
// native side.
//
foreach (var field in @class.Layout.Fields.Where(f => f.QualifiedType.Type.IsConstCharString()))
foreach (var prop in @class.GetConstCharFieldProperties())
{
var ptr = $"(({Helpers.InternalStruct}*){Helpers.InstanceIdentifier})->{field.Name}";
WriteLine($"if (__{field.Name}_OwnsNativeMemory)");
string name = prop.Field.OriginalName;
var ptr = $"(({Helpers.InternalStruct}*){Helpers.InstanceIdentifier})->{name}";
WriteLine($"if (__{name}_OwnsNativeMemory)");
WriteLineIndent($"Marshal.FreeHGlobal({ptr});");
}
@ -2978,17 +2979,13 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty @@ -2978,17 +2979,13 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
// Copy any string references owned by the source to the new instance so we
// don't have to ref count them.
foreach (var field in @class.Fields.Where(f => f.QualifiedType.Type.IsConstCharString()))
// If there is no property or no setter then this instance can never own the native
// memory. Worry about the case where there's only a setter (write-only) when we
// understand the use case and how it can occur.
foreach (var prop in @class.GetConstCharFieldProperties())
{
var prop = @class.Properties.Where(p => p.Field == field).FirstOrDefault();
// If there is no property or no setter then this instance can never own the native
// memory. Worry about the case where there's only a setter (write-only) when we
// understand the use case and how it can occur.
if (prop != null && prop.HasGetter && prop.HasSetter)
{
WriteLine($"if ({method.Parameters[0].Name}.__{field.OriginalName}_OwnsNativeMemory)");
WriteLineIndent($@"this.{prop.Name} = {method.Parameters[0].Name}.{prop.Name};");
}
WriteLine($"if ({method.Parameters[0].Name}.__{prop.Field.OriginalName}_OwnsNativeMemory)");
WriteLineIndent($"this.{prop.Name} = {method.Parameters[0].Name}.{prop.Name};");
}
}
}
@ -3005,7 +3002,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty @@ -3005,7 +3002,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
}
public void GenerateInternalFunctionCall(Function function,
QualifiedType returnType = default(QualifiedType))
QualifiedType returnType = default)
{
var @class = function.Namespace as Class;

Loading…
Cancel
Save