Skip to content

Commit c8df0b7

Browse files
Merge pull request #127 from topolarity/fix-anonymous-methods-1.10
Fix `@atomic` usage on 1.7-1.9
2 parents 0f8ef90 + f507db6 commit c8df0b7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
version:
2020
- '1.0' # Replace this with the minimum Julia version that your package supports.
2121
- '1' # automatically expands to the latest stable 1.x release of Julia
22+
- '1.6'
23+
- '1.9'
2224
- 'nightly'
2325
os:
2426
- ubuntu-latest

src/anonymous.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,39 @@ baremodule __deserialized_types__ end
140140
end
141141
return tn
142142
end
143+
else @static if VERSION < v"1.10-"
144+
function newstruct_raw(cache, ::Type{TypeName}, d, init)
145+
name = raise_recursive(d[:data][2], cache, init)
146+
name = isdefined(__deserialized_types__, name) ? gensym() : name
147+
tn = ccall(:jl_new_typename_in, Ref{Core.TypeName}, (Any, Any),
148+
name, __deserialized_types__)
149+
cache[d] = tn
150+
names, super, parameters, types, has_instance, atomicfields,
151+
abstr, mutabl, ninitialized = map(x -> raise_recursive(x, cache, init), d[:data][3:end-1])
152+
ndt = ccall(:jl_new_datatype, Any, (Any, Any, Any, Any, Any, Any, Any, Cint, Cint, Cint),
153+
tn, tn.module, super, parameters, names, types, atomicfields,
154+
abstr, mutabl, ninitialized)
155+
# ty = tn.wrapper = ndt.name.wrapper
156+
ty = ndt.name.wrapper
157+
ccall(:jl_set_const, Cvoid, (Any, Any, Any), tn.module, tn.name, ty)
158+
if has_instance && !isdefined(ty, :instance)
159+
# use setfield! directly to avoid `fieldtype` lowering expecting to see a Singleton object already on ty
160+
Core.setfield!(ty, :instance, ccall(:jl_new_struct, Any, (Any, Any...), ty))
161+
end
162+
mt = raise_recursive(d[:data][end], cache, init)
163+
if mt != nothing
164+
mtname, defs, maxa, kwsorter = mt
165+
mt = ccall(:jl_new_method_table, Any, (Any, Any), name, tn.module)
166+
mt.name = mtname
167+
mt.max_args = maxa
168+
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), tn, Base.fieldindex(Core.TypeName, :mt)-1, mt)
169+
for def in defs
170+
isdefined(def, :sig) || continue
171+
ccall(:jl_method_table_insert, Cvoid, (Any, Any, Ptr{Cvoid}), mt, def, C_NULL)
172+
end
173+
end
174+
return tn
175+
end
143176
else
144177
function newstruct_raw(cache, ::Type{TypeName}, d, init)
145178
name = raise_recursive(d[:data][2], cache, init)
@@ -174,6 +207,7 @@ else
174207
return tn
175208
end
176209
end
210+
end
177211

178212
# Function Types
179213

0 commit comments

Comments
 (0)