Skip to content

Commit b75b036

Browse files
committed
Use jl_reinit_foreign_type if available
This prepares us for an upcoming change to serialization in Julia 1.10.
1 parent 5ea730c commit b75b036

5 files changed

Lines changed: 55 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Version 0.9.2-DEV (released YYYY-MM-DD)
44

5+
- Silence scary warning about missing compiler
6+
- Prepare for an upcoming change to serialization in Julia 1.10
7+
58
## Version 0.9.1 (released 2022-11-23)
69

710
- Added a longer example for using GAP.jl, based around the Rubik's cube

pkg/JuliaInterface/example/function_perform.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module GapFunctionPerform
22

3-
import GAP_jll: GapObj
3+
import GAP: GapObj
44

55
function typed_func(a::GapObj, b::GapObj)
66
return a

src/GAP.jl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ GAP_jll.is_available() ||
2323
error("""This platform or julia version is currently not supported by GAP:
2424
$(Base.BinaryPlatforms.host_triplet())""")
2525

26+
# Julia >= 1.10 will at some point add support for (de)serializing foreign
27+
# types (the types, not the instances, at least not yet). We want (and need)
28+
# to use that if available, which also requires changes in GAP resp. GAP_jll.
29+
# To determine whether to use it, we therefore check two conditions:
30+
# (1) whether the Julia kernel exports `jl_reinit_foreign_type`, and
31+
# (2) whether or not GAP_jll defines GapObj.
32+
# See https://github.com/JuliaLang/julia/pull/44527
33+
# and https://github.com/JuliaLang/julia/pull/47407
34+
function use_jl_reinit_foreign_type()
35+
if isdefined(GAP_jll, :GapObj)
36+
# GAP_jll still provides GapObj => use the old system
37+
return false
38+
end
39+
# otherwise try to use the new system
40+
try
41+
cglobal(:jl_reinit_foreign_type) != C_NULL
42+
catch
43+
false
44+
end
45+
end
46+
2647
include("setup.jl")
2748

2849
import Base: length, finalize
@@ -75,6 +96,10 @@ const real_JuliaInterface_path = Ref{String}()
7596
JuliaInterface_path() = real_JuliaInterface_path[]
7697

7798
function initialize(argv::Vector{String})
99+
if use_jl_reinit_foreign_type()
100+
ccall((:GAP_InitJuliaMemoryInterface, libgap), Nothing, (Any, Ptr{Nothing}), @__MODULE__, C_NULL)
101+
end
102+
78103
handle_signals = isdefined(Main, :__GAP_ARGS__) # a bit of a hack...
79104
error_handler_func = handle_signals ? C_NULL : @cfunction(error_handlerwrap, Cvoid, ())
80105

@@ -112,7 +137,7 @@ function initialize(argv::Vector{String})
112137
## At this point, the GAP module has not been completely initialized, and
113138
## hence is not yet available under the global binding "GAP"; but
114139
## JuliaInterface needs to access it. To make that possible, we dlopen
115-
## its kernel extension already here, and poke a point to this module
140+
## its kernel extension already here, and poke a pointer to this module
116141
## into the kernel extension's global variable `gap_module`
117142
@debug "storing pointer to Julia module 'GAP' into JuliaInterface"
118143
Libdl.dlopen(JuliaInterface_path())

src/types.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1+
if use_jl_reinit_foreign_type()
2+
const GapObj = ccall((:GAP_DeclareGapObj, libgap),
3+
Any,
4+
(Symbol, Module, Any),
5+
:GapObj, GAP, Any)
6+
7+
const SmallBag = ccall((:GAP_DeclareBag, libgap),
8+
Any,
9+
(Symbol, Module, Any, Cint),
10+
:SmallBag, GAP, Any, 0)
11+
12+
const LargeBag = ccall((:GAP_DeclareBag, libgap),
13+
Any,
14+
(Symbol, Module, Any, Cint),
15+
:LargeBag, GAP, Any, 1)
16+
17+
else
18+
119
import GAP_jll: GapObj
220

21+
end
22+
323

424
"""
525
FFE

test/adapter.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ end
5353

5454
ioc = IOContext(io, :module => nothing);
5555
print(ioc, GAP.GapObj)
56-
@test String(take!(io)) == "GAP_jll.GapObj"
56+
if GAP.use_jl_reinit_foreign_type()
57+
@test String(take!(io)) == "GAP.GapObj"
58+
else
59+
@test String(take!(io)) == "GAP_jll.GapObj"
60+
end
5761
end

0 commit comments

Comments
 (0)