Skip to content

Commit

Permalink
Merge pull request #127 from topolarity/fix-anonymous-methods-1.10
Browse files Browse the repository at this point in the history
Fix `@atomic` usage on 1.7-1.9
  • Loading branch information
DhairyaLGandhi committed Jan 22, 2024
2 parents 0f8ef90 + f507db6 commit c8df0b7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -19,6 +19,8 @@ jobs:
version:
- '1.0' # Replace this with the minimum Julia version that your package supports.
- '1' # automatically expands to the latest stable 1.x release of Julia
- '1.6'
- '1.9'
- 'nightly'
os:
- ubuntu-latest
Expand Down
34 changes: 34 additions & 0 deletions src/anonymous.jl
Expand Up @@ -140,6 +140,39 @@ baremodule __deserialized_types__ end
end
return tn
end
else @static if VERSION < v"1.10-"
function newstruct_raw(cache, ::Type{TypeName}, d, init)
name = raise_recursive(d[:data][2], cache, init)
name = isdefined(__deserialized_types__, name) ? gensym() : name
tn = ccall(:jl_new_typename_in, Ref{Core.TypeName}, (Any, Any),
name, __deserialized_types__)
cache[d] = tn
names, super, parameters, types, has_instance, atomicfields,
abstr, mutabl, ninitialized = map(x -> raise_recursive(x, cache, init), d[:data][3:end-1])
ndt = ccall(:jl_new_datatype, Any, (Any, Any, Any, Any, Any, Any, Any, Cint, Cint, Cint),
tn, tn.module, super, parameters, names, types, atomicfields,
abstr, mutabl, ninitialized)
# ty = tn.wrapper = ndt.name.wrapper
ty = ndt.name.wrapper
ccall(:jl_set_const, Cvoid, (Any, Any, Any), tn.module, tn.name, ty)
if has_instance && !isdefined(ty, :instance)
# use setfield! directly to avoid `fieldtype` lowering expecting to see a Singleton object already on ty
Core.setfield!(ty, :instance, ccall(:jl_new_struct, Any, (Any, Any...), ty))
end
mt = raise_recursive(d[:data][end], cache, init)
if mt != nothing
mtname, defs, maxa, kwsorter = mt
mt = ccall(:jl_new_method_table, Any, (Any, Any), name, tn.module)
mt.name = mtname
mt.max_args = maxa
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), tn, Base.fieldindex(Core.TypeName, :mt)-1, mt)
for def in defs
isdefined(def, :sig) || continue
ccall(:jl_method_table_insert, Cvoid, (Any, Any, Ptr{Cvoid}), mt, def, C_NULL)
end
end
return tn
end
else
function newstruct_raw(cache, ::Type{TypeName}, d, init)
name = raise_recursive(d[:data][2], cache, init)
Expand Down Expand Up @@ -174,6 +207,7 @@ else
return tn
end
end
end

# Function Types

Expand Down

0 comments on commit c8df0b7

Please sign in to comment.