Skip to content

NullReferenceException generating code for Apache Arrow library #1246

Open
@eerhardt

Description

@eerhardt
Brief Description

I am attempting to use CppSharp to generate C# bindings for https://github.com/apache/arrow/blob/master/cpp/src/arrow/api.h. However, I am getting a NRE coming from CppTypePrinter.VisitPointerType.

From debugging CppSharp, I narrowed it down to the following code:

var qual = GetStringQuals(quals, false);
var pointeeType = pointee.Visit(this, pointer.QualifiedPointee.Qualifiers);
var mod = PrintTypeModifiers ? ConvertModifierToString(pointer.Modifier) : string.Empty;
return $"{pointeeType}{mod}{(string.IsNullOrEmpty(qual) ? string.Empty : " ")}{qual}";

In this case, pointee on line 95 is null. This is because pointer.Pointee is null above it.

Doing some more digging, I found that it looks like the PointerType it is trying to visit is coming from the vendored/variant.hpp header file. You can see the file, and code, that is causing the problem here:

https://github.com/apache/arrow/blob/05bc63c3b76a5fc865434f596c63ff0f26388f69/cpp/src/arrow/vendored/variant.hpp#L2417-L2419

I can repro the NRE by just trying to generate code for that vendored/variant.hpp file. That variant.hpp file appears to be coming from https://github.com/mpark/variant.

OS: Windows 10

Used headers

https://github.com/apache/arrow/blob/05bc63c3b76a5fc865434f596c63ff0f26388f69/cpp/src/arrow/vendored/variant.hpp#L2417-L2419

Used settings
public void Setup(Driver driver)
{
    driver.Options.GeneratorKind = GeneratorKind.CSharp;
    //driver.Options.GenerateInternalImports = true;

    var module = driver.Options.AddModule("Sample");
    module.IncludeDirs.Add(@"C:\temp\pyarrow\include\");
    //module.Headers.Add(@"arrow\vendored\variant.hpp");
    module.Headers.Add(@"arrow\api.h");
    module.LibraryDirs.Add(@"C:\temp\pyarrow");
            
    module.Defines.Add("WIN32");
    module.Defines.Add("_WINDOWS");
    module.Defines.Add("NDEBUG");
            
    module.Libraries.Add("arrow.dll");
}

Target: MSVC/GCC/Clang

Other settings

Stack trace or incompilable generated code
Parsed 'arrow\api.h'
Processing code...
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at CppSharp.Generators.C.CppTypePrinter.VisitPointerType(PointerType pointer, TypeQualifiers quals)
   at CppSharp.AST.PointerType.Visit[T](ITypeVisitor`1 visitor, TypeQualifiers quals)
   at CppSharp.Types.TypeMapDatabase.FindTypeMap(Type type, TypeMap& typeMap)
   at CppSharp.Passes.CheckIgnoredDeclsPass.IsTypeComplete(Type type)
   at CppSharp.Passes.CheckIgnoredDeclsPass.HasInvalidType(Type type, Declaration decl, String& msg)
   at CppSharp.Passes.CheckIgnoredDeclsPass.VisitFunctionDecl(Function function)
   at CppSharp.AST.AstVisitor.VisitMethodDecl(Method method)
   at CppSharp.Passes.CheckIgnoredDeclsPass.VisitMethodDecl(Method method)
   at CppSharp.AST.AstVisitor.VisitClassDecl(Class class)
   at CppSharp.Passes.CheckIgnoredDeclsPass.VisitClassDecl(Class class)
   at CppSharp.AST.Class.Visit[T](IDeclVisitor`1 visitor)
   at CppSharp.AST.AstVisitor.VisitDeclarationContext(DeclarationContext context)
   at CppSharp.AST.AstVisitor.VisitNamespace(Namespace namespace)
   at CppSharp.AST.Namespace.Visit[T](IDeclVisitor`1 visitor)
   at CppSharp.AST.AstVisitor.VisitDeclarationContext(DeclarationContext context)
   at CppSharp.AST.AstVisitor.VisitNamespace(Namespace namespace)
   at CppSharp.AST.Namespace.Visit[T](IDeclVisitor`1 visitor)
   at CppSharp.AST.AstVisitor.VisitDeclarationContext(DeclarationContext context)
   at CppSharp.Passes.TranslationUnitPass.VisitTranslationUnit(TranslationUnit unit)
   at CppSharp.Passes.TranslationUnitPass.VisitASTContext(ASTContext context)
   at CppSharp.Passes.CheckIgnoredDeclsPass.VisitASTContext(ASTContext c)
   at CppSharp.Generators.BindingContext.<RunPasses>b__29_0(TranslationUnitPass pass)
   at CppSharp.PassBuilder`1.RunPasses(Action`1 action)
   at CppSharp.Generators.BindingContext.RunPasses()
   at CppSharp.Driver.ProcessCode()
   at CppSharp.ConsoleDriver.Run(ILibrary library)
   at PlasmaGenerator.Program.Main(String[] args)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions