diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ea8f8bc..0e1cc7b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -10,7 +10,6 @@ jobs: fail-fast: false matrix: version: - - '1.5' - '1.6' - '1.7' - '1.8' @@ -25,10 +24,12 @@ jobs: # - windows-latest arch: - x64 - # - x86 + # - aarch64 exclude: - - os: macos-latest - version: '1.5' + # - os: ubuntu-latest + # arch: aarch64 + # - os: macos-latest + # arch: x64 steps: - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@latest diff --git a/Project.toml b/Project.toml index 505a126..23bda1e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CBinding" uuid = "d43a6710-96b8-4a2d-833c-c424785e5374" authors = ["Keith Rutkowski "] -version = "1.0.12" +version = "1.1.0" [deps] Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100" @@ -12,4 +12,4 @@ Scratch = "6c6a2e73-6563-6170-7368-637461726353" [compat] Clang_jll = "^9, ^11, ^12, ^13, ^14, ^15, ^16, ^18" Scratch = "^1" -julia = "^1.5" +julia = "^1.6" diff --git a/src/CBinding.jl b/src/CBinding.jl index d38e872..e009cb6 100644 --- a/src/CBinding.jl +++ b/src/CBinding.jl @@ -92,11 +92,11 @@ module CBinding bitstype(::Type{T}; raise::Bool = true) where {T} = isbitstype(T) ? T : raise ? error("Failure to obtain a bits-type") : nothing bitstype(::Type{CQ}; kwargs...) where {CQ<:Cqualifier} = bitstype(unqualifiedtype(CQ); kwargs...) - bitstype(::Type{CA}; kwargs...) where {T, N, CA<:Carray{T, N}} = bitstype(T; kwargs...) === nothing ? nothing : Carray{bitstype(T), N, sizeof(bitstype(T))*N} + bitstype(::Type{CA}; kwargs...) where {T, N, CA<:Carray{T, N}} = Carray{bitstype(T), N, sizeof(bitstype(T))*N} - values(::Type{CE}) where {CE<:Cenum} = bitstype(CE; raise = false) === nothing ? () : values(bitstype(CE)) + values(::Type{CE}) where {CE<:Cenum} = values(bitstype(CE)) - fields(::Type{CA}) where {CA<:Caggregate} = bitstype(CA; raise = false) === nothing ? () : fields(bitstype(CA)) + fields(::Type{CA}) where {CA<:Caggregate} = isnothing(bitstype(CA; raise = false)) ? () : fields(bitstype(CA)) include("longdouble.jl") diff --git a/src/context.jl b/src/context.jl index 7ea209d..8b67718 100644 --- a/src/context.jl +++ b/src/context.jl @@ -124,7 +124,7 @@ end -getexprs(ctx::Context) = getexprs(ctx, clang_getTranslationUnitCursor(ctx.tu[])) +getexprs(ctx::Context) = getexprs(ctx, clang_getTranslationUnitCursor(ctx.tu[]); path = CXCursor[]) function getexprs(ctx::Context, syms, blocks...) expr = filter(!isnothing, collect(blocks)) @@ -156,7 +156,7 @@ end -function getexprs_tu(ctx::Context, cursor::CXCursor) +function getexprs_tu(ctx::Context, cursor::CXCursor; path::Vector{CXCursor}) exprs = [] for child in children(cursor) @@ -168,7 +168,7 @@ function getexprs_tu(ctx::Context, cursor::CXCursor) first(range).file != header(ctx) || first(range).line > ctx.line || continue end - append!(exprs, filter(!isnothing, getexprs(ctx, child))) + append!(exprs, filter(!isnothing, getexprs(ctx, child; path = path))) end return exprs @@ -400,7 +400,8 @@ function wrap!(ctx::Context) end close(file) - libclang.Clang_jll.clang() do bin + withenv() do + bin = libclang.Clang_jll.clang() run(`$(bin) $(ctx.args[5:7]) -w -O2 -fPIC -shared -o $(getlib(ctx).value) $(path) $(ctx.args[8:end])`) # TODO: add -rpath for all ctx.libs? end end diff --git a/src/context_c.jl b/src/context_c.jl index b2b8d0e..d8d8c09 100644 --- a/src/context_c.jl +++ b/src/context_c.jl @@ -322,15 +322,15 @@ function gettype(ctx::Type{Context{:c}}, type::CXType; kwargs...) end - -function getexprs(ctx::Context{:c}, cursor::CXCursor) +function getexprs(ctx::Context{:c}, cursor::CXCursor; path::Vector{CXCursor}) + push!(path, cursor) exprs = [] getblock(ctx).flags.skip && return exprs getblock(ctx).flags.defer && return exprs if cursor.kind == CXCursor_TranslationUnit - append!(exprs, getexprs_tu(ctx, cursor)) + append!(exprs, getexprs_tu(ctx, cursor; path = path)) for (_, child) in ctx.macros append!(exprs, getexprs_macro(ctx, child)) @@ -349,11 +349,11 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor) CXCursor_EnumDecl, CXCursor_TypedefDecl, ) - append!(exprs, getexprs(ctx, child)) + append!(exprs, getexprs(ctx, child; path = path)) end end - append!(exprs, getexprs_opaque(ctx, cursor)) + append!(exprs, getexprs_opaque(ctx, cursor; path = path)) elseif cursor.kind in ( CXCursor_VarDecl, CXCursor_FunctionDecl, @@ -366,7 +366,7 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor) CXCursor_TypedefDecl, CXCursor_ParmDecl, ) - append!(exprs, getexprs(ctx, child)) + append!(exprs, getexprs(ctx, child; path = path)) end end @@ -379,7 +379,7 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor) CXCursor_EnumDecl, CXCursor_TypedefDecl, ) - append!(exprs, getexprs(ctx, child)) + append!(exprs, getexprs(ctx, child; path = path)) end end elseif cursor.kind == CXCursor_InclusionDirective @@ -443,7 +443,7 @@ end -function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor) +function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor; path::Vector{CXCursor}) exprs = [] getblock(ctx).flags.notype && return exprs @@ -465,6 +465,11 @@ function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor) (getjl(ctx, string(type)), nothing) : (nothing, getjl(ctx, string(type))) + # anonymous opaque function parameters (for function pointers, not function) appear as type definitions twice it seems, so ignore this occurrence + if isanon && length(path) >= 2 && path[end-1].kind == CXCursor_ParmDecl && !any(x -> x.kind == CXCursor_FunctionDecl, path) + return exprs + end + def = clang_getCursorDefinition(cursor) loc = getlocation(clang_getCursorLocation(def)) diff --git a/test/layout-tests.jl b/test/layout-tests.jl index 19a328d..09051d9 100644 --- a/test/layout-tests.jl +++ b/test/layout-tests.jl @@ -85,7 +85,8 @@ function checkC(expr, val) } """ - return CBinding.libclang.Clang_jll.clang() do bin + return withenv() do + bin = CBinding.libclang.Clang_jll.clang() tmp = tempname() open(f -> write(f, code), tmp*".c", "w+") run(`gcc -Wno-overflow -Wno-constant-conversion -Wno-address-of-packed-member -std=c99 -o $(tmp) $(tmp).c`)