Browse Source

Fixed a crasher in delegates pass when processing libraries with no declarations.

This is admittedly a pretty unusual case but still a valid one.

Also adds a new test to make sure we do not regress.
pull/621/merge
Joao Matos 10 years ago
parent
commit
9133c389ca
  1. 6
      src/Generator/Passes/DelegatesPass.cs
  2. 10
      tests/Empty/Empty.Tests.cs
  3. 1
      tests/Empty/Empty.cpp
  4. 34
      tests/Empty/Empty.cs
  5. 2
      tests/Empty/Empty.h
  6. 2
      tests/Empty/premake4.lua

6
src/Generator/Passes/DelegatesPass.cs

@ -40,8 +40,12 @@ namespace CppSharp.Passes @@ -40,8 +40,12 @@ namespace CppSharp.Passes
foreach (var library in Driver.Options.Libraries.Where(l => !libsDelegates.ContainsKey(l)))
libsDelegates.Add(library, new Dictionary<string, DelegateDefinition>());
var unit = context.TranslationUnits.Last(u => u.IsValid && u.IsGenerated &&
var unit = context.TranslationUnits.LastOrDefault(u => u.IsValid && u.IsGenerated &&
!u.IsSystemHeader && u.HasDeclarations);
if (unit == null)
return false;
namespaceDelegates = new Namespace { Name = DelegatesNamespace, Namespace = unit };
var result = base.VisitLibrary(context);

10
tests/Empty/Empty.Tests.cs

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
using System;
using EmptyTest;
using CppSharp.Utils;
using NUnit.Framework;
[TestFixture]
public class EmptyTests : GeneratorTestFixture
{
}

1
tests/Empty/Empty.cpp

@ -0,0 +1 @@ @@ -0,0 +1 @@
#include "Empty.h"

34
tests/Empty/Empty.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Utils;
namespace CppSharp.Tests
{
public class EmptyTestsGenerator : GeneratorTest
{
public EmptyTestsGenerator(GeneratorKind kind)
: base("Empty", kind)
{
}
public override void Setup(Driver driver)
{
base.Setup(driver);
driver.Options.OutputNamespace = "EmptyTest";
}
public override void SetupPasses(Driver driver)
{
}
public override void Preprocess(Driver driver, ASTContext ctx)
{
}
public static void Main(string[] args)
{
ConsoleDriver.Run(new EmptyTestsGenerator(GeneratorKind.CSharp));
ConsoleDriver.Run(new EmptyTestsGenerator(GeneratorKind.CLI));
}
}
}

2
tests/Empty/Empty.h

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
#include "../Tests.h"

2
tests/Empty/premake4.lua

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
group "Tests/Empty"
SetupTestProject("Empty")
Loading…
Cancel
Save