File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 37
37
Base. unsafe_convert (:: Type{API.LLVMOrcThreadSafeModuleRef} , mod:: ThreadSafeModule ) = mod. ref
38
38
39
39
function ThreadSafeModule (mod:: Module )
40
+ if context (mod) != context (ts_context ())
41
+ # XXX : the C API doesn't expose the convenience method to create a TSModule from a
42
+ # Module and a regular Context, only a method to create one from a Module
43
+ # and a pre-existing TSContext, which isn't useful...
44
+ # TODO : expose the other convenience method?
45
+ # XXX : work around this by serializing/deserializing the module in the correct contex
46
+ bitcode = convert (MemoryBuffer, mod)
47
+ mod = context! (context (ts_context ())) do
48
+ parse (Module, bitcode)
49
+ end
50
+ end
51
+ @assert context (mod) == context (ts_context ())
52
+
40
53
ref = API. LLVMOrcCreateNewThreadSafeModule (mod, ts_context ())
41
- ThreadSafeModule (ref)
54
+ tsm = ThreadSafeModule (ref)
55
+ mark_dispose (mod)
56
+ return tsm
42
57
end
43
58
44
59
function ThreadSafeModule (name:: String )
@@ -48,9 +63,7 @@ function ThreadSafeModule(name::String)
48
63
mod = context! (ctx) do
49
64
Module (name)
50
65
end
51
- tsm = ThreadSafeModule (mod)
52
- mark_dispose (mod)
53
- return tsm
66
+ ThreadSafeModule (mod)
54
67
end
55
68
56
69
function dispose (mod:: ThreadSafeModule )
Original file line number Diff line number Diff line change 24
24
true
25
25
end
26
26
end
27
+
28
+ @dispose ctx= Context () ts_ctx= ThreadSafeContext () begin
29
+ src_mod = LLVM. Module (" SomeModule" )
30
+ ts_mod = ThreadSafeModule (src_mod)
31
+ ts_mod () do copied_mod
32
+ # XXX : this is a very specific test to check the current implementation of the
33
+ # ThreadSafeModule constructor, which currently copies the source module
34
+ # from its context into the thread safe one. This is questionable; maybe
35
+ # it should create a ThreadSafeModule in a ThreadSafeContext matching the
36
+ # source context. However, that would result in a TSMod that doesn't match
37
+ # the currently-active ts_context()...
38
+ @test context (copied_mod) != context (src_mod)
39
+ @test context (copied_mod) == context (ts_context ())
40
+ end
41
+ dispose (ts_mod)
42
+ end
27
43
end
28
44
29
45
@testset " JITDylib" begin
You can’t perform that action at this time.
0 commit comments