Skip to content

Commit 0efa8c3

Browse files
authored
Merge pull request #31 from pthariensflame/GC_preserve
Make `unsafe_load`-based transmutes GC-protected
2 parents ba82cb5 + 6a59a70 commit 0efa8c3

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
18-
julia-version: ["1.8", "1.10", nightly]
18+
julia-version: ["1.8", "1.11", nightly]
1919
julia-arch: [x64, x86, aarch64]
20-
os: [ubuntu-latest, windows-latest, macos-13, macos-latest]
20+
os: [ubuntu-latest, windows-latest, macos-latest]
2121
exclude:
2222
- os: ubuntu-latest
2323
julia-arch: aarch64
2424
- os: windows-latest
2525
julia-arch: aarch64
26-
- os: macos-13
27-
julia-arch: x86
28-
- os: macos-13
29-
julia-arch: aarch64
3026
- os: macos-latest
3127
julia-arch: x86
3228
- os: macos-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ actual/
1111
/deps/aes-ni
1212
Manifest.toml
1313
.DS_Store
14+
.vscode/settings.json

src/arm/aesni_common.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const LITTLE_ENDIAN::Bool = ENDIAN_BOM ≡ 0x04030201
1616

1717
abstract type ArmVec128 end
1818
@inline Base.convert(::Type{T}, x::ArmVec128) where {T<:Union{ArmVec128, UInt128}} =
19-
unsafe_load(Ptr{T}(pointer_from_objref(Ref(x))))
19+
GC.@preserve x unsafe_load(Ptr{T}(pointer_from_objref(Ref(x))))
2020
@inline Base.convert(::Type{T}, x::UInt128) where {T<:ArmVec128} =
21-
unsafe_load(Ptr{T}(pointer_from_objref(Ref(x))))
21+
GC.@preserve x unsafe_load(Ptr{T}(pointer_from_objref(Ref(x))))
2222
@inline Base.UInt128(x::ArmVec128) = convert(UInt128, x)
2323
@inline (::Type{T})(x::Union{ArmVec128, UInt128}) where {T<:ArmVec128} = convert(T, x)
2424
@inline Base.convert(::Type{T}, x::Union{Signed, Unsigned}) where {T<:ArmVec128} =

src/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract type R123Generator2x{T} <: AbstractR123{T} end
1515
"RNG that generates four numbers at a time."
1616
abstract type R123Generator4x{T} <: AbstractR123{T} end
1717

18-
_value(r::AbstractR123{T}, i = 1, ::Type{T2} = T) where {T, T2} = unsafe_load(Ptr{T2}(pointer_from_objref(r)), i)
18+
_value(r::AbstractR123{T}, i = 1, ::Type{T2} = T) where {T, T2} = GC.@preserve r unsafe_load(Ptr{T2}(pointer_from_objref(r)), i)
1919

2020
"Set the counter of a Random123 RNG."
2121
@inline function set_counter!(r::R123Generator1x{T}, ctr::Integer) where T <: UInt128

src/x86/aesni_common.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const __m128i_lvec = NTuple{2, VecElement{UInt64}}
88
struct __m128i
99
data::__m128i_lvec
1010
end
11-
Base.convert(::Type{__m128i}, x::UInt128) = unsafe_load(Ptr{__m128i}(pointer_from_objref(Ref(x))))
12-
Base.convert(::Type{UInt128}, x::__m128i) = unsafe_load(Ptr{UInt128}(pointer_from_objref(Ref(x))))
11+
Base.convert(::Type{__m128i}, x::UInt128) = GC.@preserve x unsafe_load(Ptr{__m128i}(pointer_from_objref(Ref(x))))
12+
Base.convert(::Type{UInt128}, x::__m128i) = GC.@preserve x unsafe_load(Ptr{UInt128}(pointer_from_objref(Ref(x))))
1313
Base.UInt128(x::__m128i) = convert(UInt128, x)
1414
__m128i(x::UInt128) = convert(__m128i, x)
1515
Base.convert(::Type{__m128i}, x::Union{Signed, Unsigned}) = convert(__m128i, UInt128(x))

0 commit comments

Comments
 (0)