Skip to content

Commit 5852152

Browse files
committed
Fixed a memory leak when generating the wrappers.
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
1 parent 722ad5a commit 5852152

File tree

7 files changed

+48
-30
lines changed

7 files changed

+48
-30
lines changed

QtSharp.CLI/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,13 @@ public static int Main(string[] args)
120120
}
121121
libFiles = libFiles.TopologicalSort(l => dependencies.ContainsKey(l) ? dependencies[l] : Enumerable.Empty<string>());
122122
var wrappedModules = new List<KeyValuePair<string, string>>(modules.Count);
123-
var astContexts = new List<ASTContext>(libFiles.Count);
124123
foreach (var libFile in libFiles.Where(l => modules.Any(m => m == Path.GetFileNameWithoutExtension(l))))
125124
{
126125
logredirect.SetLogFile(libFile.Replace(".dll", "") + "Log.txt");
127126
logredirect.Start();
128127

129-
var qtSharp = new QtSharp(new QtModuleInfo(qmake, make, headers, libs, libFile, target, systemIncludeDirs, docs),
130-
astContexts);
128+
var qtSharp = new QtSharp(new QtModuleInfo(qmake, make, headers, libs, libFile, target, systemIncludeDirs, docs));
131129
ConsoleDriver.Run(qtSharp);
132-
astContexts.Add(qtSharp.AST);
133130
if (File.Exists(qtSharp.LibraryName) && File.Exists(Path.Combine("release", qtSharp.InlinesLibraryName)))
134131
{
135132
wrappedModules.Add(new KeyValuePair<string, string>(qtSharp.LibraryName, qtSharp.InlinesLibraryName));

QtSharp.CLI/QtSharp.CLI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>QtSharp.CLI</RootNamespace>
1212
<AssemblyName>QtSharp.CLI</AssemblyName>
13-
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1414
<TargetFrameworkProfile>
1515
</TargetFrameworkProfile>
1616
<FileAlignment>512</FileAlignment>

QtSharp.CLI/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>
3+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>

QtSharp/Documentation.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,14 @@ public void DocumentProperty(Property property)
309309
{
310310
comment.BriefText = ((Class) property.Namespace).GetBaseProperty(property).Comment.BriefText;
311311
}
312-
if (!string.IsNullOrEmpty(comment.BriefText))
312+
if (string.IsNullOrEmpty(comment.BriefText))
313313
{
314-
comment.BriefText += Environment.NewLine;
314+
comment.BriefText += setter.Comment.BriefText;
315+
}
316+
else
317+
{
318+
comment.BriefText += Environment.NewLine + setter.Comment.BriefText;
315319
}
316-
comment.BriefText += setter.Comment.BriefText;
317320
}
318321
}
319322
if (!string.IsNullOrEmpty(comment.BriefText))
@@ -661,6 +664,5 @@ private static void AddObsoleteAttribute(Declaration function)
661664
private readonly List<XElement> classNodes;
662665
private readonly List<XElement> enumNodes;
663666
private readonly List<XElement> variableNodes;
664-
665667
}
666668
}

QtSharp/GetCommentsFromQtDocsPass.cs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ namespace QtSharp
77
{
88
public class GetCommentsFromQtDocsPass : TranslationUnitPass
99
{
10-
public GetCommentsFromQtDocsPass(string docsPath, string module, List<ASTContext> dependencies)
10+
public GetCommentsFromQtDocsPass(string docsPath, string module)
1111
{
12-
this.dependencies = dependencies;
1312
this.documentation = new Documentation(docsPath, module);
1413
this.Options.VisitFunctionReturnType = false;
1514
this.Options.VisitFunctionParameters = false;
@@ -86,11 +85,10 @@ public override bool VisitFunctionDecl(Function function)
8685
var @class = function.OriginalNamespace as Class;
8786
if (@class != null && @class.IsInterface && @class.GenerationKind == GenerationKind.Link)
8887
{
89-
function.Comment = (from dependency in this.dependencies
90-
from found in dependency.FindClass(@class.Name)
91-
from method in found.Methods
92-
where method.USR == function.USR
93-
select method.Comment).FirstOrDefault();
88+
if (functionsComments.ContainsKey(function.Mangled))
89+
{
90+
function.Comment = new RawComment { BriefText = functionsComments[function.Mangled] };
91+
}
9492
}
9593
else
9694
{
@@ -115,17 +113,36 @@ public override bool VisitProperty(Property property)
115113
where @class != null && @class.IsInterface && @class.GenerationKind == GenerationKind.Link
116114
select @class)
117115
{
118-
property.Comment = (from dependency in this.dependencies
119-
from found in dependency.FindClass(@class.Name)
120-
from prop in found.Properties
121-
where prop.OriginalName == property.OriginalName
122-
select prop.Comment).FirstOrDefault();
116+
RawComment comment = null;
117+
if (property.GetMethod != null && functionsComments.ContainsKey(property.GetMethod.Mangled))
118+
{
119+
comment = new RawComment { BriefText = functionsComments[property.GetMethod.Mangled] };
120+
}
121+
if (comment == null && property.SetMethod != null && functionsComments.ContainsKey(property.SetMethod.Mangled))
122+
{
123+
comment = new RawComment { BriefText = functionsComments[property.SetMethod.Mangled] };
124+
}
125+
property.Comment = comment;
123126
if (property.Comment != null)
124127
{
125128
return true;
126129
}
127130
}
128131
this.documentation.DocumentProperty(property);
132+
if (property.Comment != null)
133+
{
134+
if (property.GetMethod != null)
135+
{
136+
functionsComments[property.GetMethod.Mangled] = property.Comment.BriefText;
137+
}
138+
else
139+
{
140+
if (property.SetMethod != null)
141+
{
142+
functionsComments[property.SetMethod.Mangled] = property.Comment.BriefText;
143+
}
144+
}
145+
}
129146
return true;
130147
}
131148
return false;
@@ -177,10 +194,15 @@ private void DocumentFunction(Function function)
177194
{
178195
this.documentation.DocumentFunction(function);
179196
}
197+
if (function.Comment != null)
198+
{
199+
functionsComments[function.Mangled] = function.Comment.BriefText;
200+
}
180201
}
181202
}
182203

204+
private static readonly Dictionary<string, string> functionsComments = new Dictionary<string, string>();
205+
183206
private readonly Documentation documentation;
184-
private readonly List<ASTContext> dependencies;
185207
}
186208
}

QtSharp/QtSharp.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ namespace QtSharp
1414
{
1515
public class QtSharp : ILibrary
1616
{
17-
public QtSharp(QtModuleInfo qtModuleInfo, List<ASTContext> dependencies)
17+
public QtSharp(QtModuleInfo qtModuleInfo)
1818
{
19-
this.dependencies = dependencies;
2019
this.qmake = qtModuleInfo.Qmake;
2120
this.includePath = qtModuleInfo.IncludePath.Replace('/', Path.DirectorySeparatorChar);
2221
this.module = Regex.Match(qtModuleInfo.Library, @"Qt\d?(?<module>\w+?)d?\.\w+$").Groups["module"].Value;
@@ -30,7 +29,6 @@ public QtSharp(QtModuleInfo qtModuleInfo, List<ASTContext> dependencies)
3029

3130
public string LibraryName { get; set; }
3231
public string InlinesLibraryName { get; set; }
33-
public ASTContext AST { get; set; }
3432

3533
public void Preprocess(Driver driver, ASTContext lib)
3634
{
@@ -129,7 +127,7 @@ private static void IgnorePrivateDeclaration(Declaration declaration)
129127
public void Postprocess(Driver driver, ASTContext lib)
130128
{
131129
new ClearCommentsPass().VisitLibrary(driver.ASTContext);
132-
new GetCommentsFromQtDocsPass(this.docs, this.module, this.dependencies).VisitLibrary(driver.ASTContext);
130+
new GetCommentsFromQtDocsPass(this.docs, this.module).VisitLibrary(driver.ASTContext);
133131
new CaseRenamePass(
134132
RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate |
135133
RenameTargets.Field | RenameTargets.Variable,
@@ -146,7 +144,6 @@ public void Postprocess(Driver driver, ASTContext lib)
146144
.ExplicitlyIgnore();
147145
break;
148146
}
149-
this.AST = lib;
150147
}
151148

152149
public void Setup(Driver driver)
@@ -214,6 +211,5 @@ public void SetupPasses(Driver driver)
214211
private readonly IEnumerable<string> systemIncludeDirs;
215212
private readonly string target;
216213
private readonly string docs;
217-
private readonly List<ASTContext> dependencies;
218214
}
219215
}

QtSharp/QtSharp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>QtSharp</RootNamespace>
1212
<AssemblyName>QtSharp</AssemblyName>
13-
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<TargetFrameworkProfile />
1616
</PropertyGroup>
@@ -23,6 +23,7 @@
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
2525
<Prefer32Bit>false</Prefer32Bit>
26+
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
2627
</PropertyGroup>
2728
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2829
<DebugType>pdbonly</DebugType>

0 commit comments

Comments
 (0)