Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 031c57b

Browse files
committedFeb 9, 2025·
Improve support for Julia v1.10+, drop support for Julia v1.5
1 parent 0be1c0f commit 031c57b

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed
 

‎.github/workflows/CI.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
version:
13-
- '1.5'
1413
- '1.6'
1514
- '1.7'
1615
- '1.8'
@@ -25,10 +24,12 @@ jobs:
2524
# - windows-latest
2625
arch:
2726
- x64
28-
# - x86
27+
- aarch64
2928
exclude:
29+
- os: ubuntu-latest
30+
arch: aarch64
3031
- os: macos-latest
31-
version: '1.5'
32+
arch: x64
3233
steps:
3334
- uses: actions/checkout@v3
3435
- uses: julia-actions/setup-julia@latest

‎Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CBinding"
22
uuid = "d43a6710-96b8-4a2d-833c-c424785e5374"
33
authors = ["Keith Rutkowski <keith@analytech-solutions.com>"]
4-
version = "1.0.12"
4+
version = "1.1.0"
55

66
[deps]
77
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"
@@ -12,4 +12,4 @@ Scratch = "6c6a2e73-6563-6170-7368-637461726353"
1212
[compat]
1313
Clang_jll = "^9, ^11, ^12, ^13, ^14, ^15, ^16, ^18"
1414
Scratch = "^1"
15-
julia = "^1.5"
15+
julia = "^1.6"

‎src/CBinding.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ module CBinding
9292

9393
bitstype(::Type{T}; raise::Bool = true) where {T} = isbitstype(T) ? T : raise ? error("Failure to obtain a bits-type") : nothing
9494
bitstype(::Type{CQ}; kwargs...) where {CQ<:Cqualifier} = bitstype(unqualifiedtype(CQ); kwargs...)
95-
bitstype(::Type{CA}; kwargs...) where {T, N, CA<:Carray{T, N}} = bitstype(T; kwargs...) === nothing ? nothing : Carray{bitstype(T), N, sizeof(bitstype(T))*N}
95+
bitstype(::Type{CA}; kwargs...) where {T, N, CA<:Carray{T, N}} = Carray{bitstype(T), N, sizeof(bitstype(T))*N}
9696

97-
values(::Type{CE}) where {CE<:Cenum} = bitstype(CE; raise = false) === nothing ? () : values(bitstype(CE))
97+
values(::Type{CE}) where {CE<:Cenum} = values(bitstype(CE))
9898

99-
fields(::Type{CA}) where {CA<:Caggregate} = bitstype(CA; raise = false) === nothing ? () : fields(bitstype(CA))
99+
fields(::Type{CA}) where {CA<:Caggregate} = isnothing(bitstype(CA; raise = false)) ? () : fields(bitstype(CA))
100100

101101

102102
include("longdouble.jl")

‎src/context.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ end
124124

125125

126126

127-
getexprs(ctx::Context) = getexprs(ctx, clang_getTranslationUnitCursor(ctx.tu[]))
127+
getexprs(ctx::Context) = getexprs(ctx, clang_getTranslationUnitCursor(ctx.tu[]); path = CXCursor[])
128128

129129
function getexprs(ctx::Context, syms, blocks...)
130130
expr = filter(!isnothing, collect(blocks))
@@ -156,7 +156,7 @@ end
156156

157157

158158

159-
function getexprs_tu(ctx::Context, cursor::CXCursor)
159+
function getexprs_tu(ctx::Context, cursor::CXCursor; path::Vector{CXCursor})
160160
exprs = []
161161

162162
for child in children(cursor)
@@ -168,7 +168,7 @@ function getexprs_tu(ctx::Context, cursor::CXCursor)
168168
first(range).file != header(ctx) || first(range).line > ctx.line || continue
169169
end
170170

171-
append!(exprs, filter(!isnothing, getexprs(ctx, child)))
171+
append!(exprs, filter(!isnothing, getexprs(ctx, child; path = path)))
172172
end
173173

174174
return exprs
@@ -400,7 +400,8 @@ function wrap!(ctx::Context)
400400
end
401401
close(file)
402402

403-
libclang.Clang_jll.clang() do bin
403+
withenv() do
404+
bin = libclang.Clang_jll.clang()
404405
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?
405406
end
406407
end

‎src/context_c.jl

+13-8
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,15 @@ function gettype(ctx::Type{Context{:c}}, type::CXType; kwargs...)
322322
end
323323

324324

325-
326-
function getexprs(ctx::Context{:c}, cursor::CXCursor)
325+
function getexprs(ctx::Context{:c}, cursor::CXCursor; path::Vector{CXCursor})
326+
push!(path, cursor)
327327
exprs = []
328328

329329
getblock(ctx).flags.skip && return exprs
330330
getblock(ctx).flags.defer && return exprs
331331

332332
if cursor.kind == CXCursor_TranslationUnit
333-
append!(exprs, getexprs_tu(ctx, cursor))
333+
append!(exprs, getexprs_tu(ctx, cursor; path = path))
334334

335335
for (_, child) in ctx.macros
336336
append!(exprs, getexprs_macro(ctx, child))
@@ -349,11 +349,11 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor)
349349
CXCursor_EnumDecl,
350350
CXCursor_TypedefDecl,
351351
)
352-
append!(exprs, getexprs(ctx, child))
352+
append!(exprs, getexprs(ctx, child; path = path))
353353
end
354354
end
355355

356-
append!(exprs, getexprs_opaque(ctx, cursor))
356+
append!(exprs, getexprs_opaque(ctx, cursor; path = path))
357357
elseif cursor.kind in (
358358
CXCursor_VarDecl,
359359
CXCursor_FunctionDecl,
@@ -366,7 +366,7 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor)
366366
CXCursor_TypedefDecl,
367367
CXCursor_ParmDecl,
368368
)
369-
append!(exprs, getexprs(ctx, child))
369+
append!(exprs, getexprs(ctx, child; path = path))
370370
end
371371
end
372372

@@ -379,7 +379,7 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor)
379379
CXCursor_EnumDecl,
380380
CXCursor_TypedefDecl,
381381
)
382-
append!(exprs, getexprs(ctx, child))
382+
append!(exprs, getexprs(ctx, child; path = path))
383383
end
384384
end
385385
elseif cursor.kind == CXCursor_InclusionDirective
@@ -443,7 +443,7 @@ end
443443

444444

445445

446-
function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor)
446+
function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor; path::Vector{CXCursor})
447447
exprs = []
448448

449449
getblock(ctx).flags.notype && return exprs
@@ -465,6 +465,11 @@ function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor)
465465
(getjl(ctx, string(type)), nothing) :
466466
(nothing, getjl(ctx, string(type)))
467467

468+
# anonymous opaque function parameters (for function pointers, not function) appear as type definitions twice it seems, so ignore this occurrence
469+
if isanon && length(path) >= 2 && path[end-1].kind == CXCursor_ParmDecl && !any(x -> x.kind == CXCursor_FunctionDecl, path)
470+
return exprs
471+
end
472+
468473
def = clang_getCursorDefinition(cursor)
469474
loc = getlocation(clang_getCursorLocation(def))
470475

‎test/layout-tests.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ function checkC(expr, val)
8585
}
8686
"""
8787

88-
return CBinding.libclang.Clang_jll.clang() do bin
88+
return withenv() do
89+
bin = CBinding.libclang.Clang_jll.clang()
8990
tmp = tempname()
9091
open(f -> write(f, code), tmp*".c", "w+")
9192
run(`gcc -Wno-overflow -Wno-constant-conversion -Wno-address-of-packed-member -std=c99 -o $(tmp) $(tmp).c`)

0 commit comments

Comments
 (0)
Please sign in to comment.