mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.14k stars 517 forks source link

Null reference exception when parsing header #66

Closed mydogisbox closed 11 years ago

mydogisbox commented 11 years ago

I'm happy to help debug the below error, I'm just not sure where to start.

I'm trying to generate wrappers for the octave libraries (). I'm getting the null reference exception below. The null is generated on line 505 of parser.cpp (VTLayout is null):

auto& VTLayout = VTContext.getVFTableLayout(RD, VFPtrInfo.VFPtrOffset);

Here is the exception:

System.NullReferenceException occurred HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=CppSharp.Parser StackTrace: at llvm.OwningArrayPtrclang::VTableComponent.get(OwningArrayPtrclang::VTableComponent* ) in c:\cppsharp\cppsharp\deps\llvm\include\llvm\adt\owningptr.h:line 135 InnerException:

Here is my setup code:

    public void Setup(Driver driver)
    {
        var options = driver.Options;
        options.LibraryName = "OctaveSharp";
        options.Headers.Add("oct.h");
        options.IncludeDirs.Add(@"C:\Octave-class\3.2.4_gcc-4.4.0\include\octave-3.2.4\octave");
        options.LibraryDirs.Add(@"C:\Software\Octave-3.6.4\lib\octave\3.6.4");
        options.Libraries.Add(@"octave.lib");
        options.OutputDir = @"C:\CppSharp\CppSharp\OctaveSharp";
    }

Octave was installed using: http://sourceforge.net/projects/octave/files/Octave%20Windows%20binaries/Octave%203.6.4%20for%20Windows%20Microsoft%20Visual%20Studio/

tritao commented 11 years ago

Since this is a parser error, you'll have a much better experience debugging this with the debug version of Clang and CppSharp (and don't forget to check "Enable native code debugging" in your project's debug options).

Anyway, I've now fixed the cause of this. The header is not being correctly parsed but due to a flaw in the diagnostic processing CppSharp was failing to report this and also tried to process the invalid ASTs.

I'll upload a new binary release shortly with this fix.