- 
                Notifications
    You must be signed in to change notification settings 
- Fork 73
Closed
Description
I have something like this in my C header (similar to #58):
typedef union secretunion SECRET;
When I try to wrap this, I actually get an error:
[ Info: Error thrown. Last cursor available in Clang.wrap_c.debug_cursors
ERROR: LoadError: BoundsError: attempt to access 0-element Array{Clang.cindex.CLCursor,1} at index [0]
Stacktrace:
 [1] getindex at ./array.jl:731 [inlined]
 [2] largestfield(::Clang.cindex.UnionDecl) at Clang/src/wrap_c.jl:312
 [...]
 [5] wrap(::Clang.wrap_c.WrapContext, ::OrderedCollections.OrderedDict{Symbol,Clang.wrap_c.ExprUnit}, ::Clang.cindex.UnionDecl) at Clang/src/wrap_c.jl:436
 [6] wrap_header(::Clang.wrap_c.WrapContext, ::Clang.cindex.TranslationUnit, ::String, ::Array{Any,1}) at Clang/src/wrap_c.jl:685
 [...]
The problem seems to be that largestfield tries to return access fields[0] while fields is actually empty:
function largestfield(cu::UnionDecl)
    maxsize,maxelem = 0,0
    fields = children(cu)
    for i in 1:length(fields)
        field_size = typesize(cu_type(fields[i]))
        if field_size > maxsize
            maxsize = field_size
            maxelem = i
        end
    end
    fields[maxelem]
end
Metadata
Metadata
Assignees
Labels
No labels