Skip to content

Commit

Permalink
Fix tests and deprecated Compat.Sys calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschumacher committed Mar 11, 2021
1 parent eaa4232 commit 64645d9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ os:
- osx
julia:
- 0.6
- 1.1
- 1.2
- 1.3
- 1.4
- 1.5
- nightly
notifications:
email: false
Expand All @@ -13,9 +18,9 @@ git:

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - julia: nightly
matrix:
allow_failures:
- julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
Expand Down
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name = "PageAlignedArrays"
uuid = "ba0cfe35-a769-40a2-96c5-fb706a08f4a0"
authors = ["Andrew Keller"]
version = "0.1"
version = "0.1.0"

[deps]
Compat = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"

[compat]
julia = "1.5"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
22 changes: 11 additions & 11 deletions src/PageAlignedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mutable struct PageAlignedArray{T,N} <: AbstractArray{T,N}
function PageAlignedArray{T,N}(dims::NTuple{N,Integer}) where {T,N}
n = N == 0 ? 1 : reduce(*, dims)
addr = virtualalloc(sizeof(T) * n, T)
backing = unsafe_wrap(Array, addr, dims, false)
backing = unsafe_wrap(Array, addr, dims, own=false)
array = new{T,N}(backing, addr)
@compat finalizer(x->virtualfree(x.addr), array)
return array
Expand All @@ -44,15 +44,15 @@ Allocate page-aligned memory and return a `Ptr{T}` to the allocation. The caller
responsible for de-allocating the memory using `virtualfree`, otherwise it will leak.
"""
function virtualalloc(size_bytes::Integer, ::Type{T}) where {T}
@static Compat.Sys.iswindows() ? begin
@static Base.Sys.iswindows() ? begin
MEM_COMMIT = 0x1000
PAGE_READWRITE = 0x4
addr = ccall((:VirtualAlloc, "Kernel32"), Ptr{T},
(Ptr{Void}, Csize_t, Culong, Culong),
(Ptr{Cvoid}, Csize_t, Culong, Culong),
C_NULL, size_bytes, MEM_COMMIT, PAGE_READWRITE)
end : @static Compat.Sys.islinux() ? begin
end : @static Base.Sys.islinux() ? begin
addr = ccall(:valloc, Ptr{T}, (Csize_t,), size_bytes)
end : @static Compat.Sys.isapple() ? begin
end : @static Base.Sys.isapple() ? begin
addr = ccall((:valloc, "libSystem.dylib"), Ptr{T}, (Csize_t,), size_bytes)
end : throw(SystemError())

Expand All @@ -66,14 +66,14 @@ Free memory that has been allocated using `virtualalloc`. Undefined, likely very
behavior if called on a pointer coming from elsewhere.
"""
function virtualfree(addr::Ptr{T}) where {T}
@static Compat.Sys.iswindows() ? begin
@static Base.Sys.iswindows() ? begin
MEM_RELEASE = 0x8000
return ccall((:VirtualFree, "Kernel32"), Cint, (Ptr{Void}, Csize_t, Culong),
return ccall((:VirtualFree, "Kernel32"), Cint, (Ptr{Cvoid}, Csize_t, Culong),
addr, 0, MEM_RELEASE)
end : @static Compat.Sys.islinux() ? begin
return ccall(:free, Void, (Ptr{Void},), addr)
end : @static Compat.Sys.isapple() ? begin
return ccall((:free, "libSystem.dylib"), Void, (Ptr{Void},), addr)
end : @static Base.Sys.islinux() ? begin
return ccall(:free, Void, (Ptr{Cvoid},), addr)
end : @static Base.Sys.isapple() ? begin
return ccall((:free, "libSystem.dylib"), Void, (Ptr{Cvoid},), addr)
end : error("OS not supported")
end
end # module
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ using Mmap


p = PageAlignedVector{Int}(512)
@test (p[:] = 1) == 1
p[:] .= 1
@test eltype(p) == Int
@test @inferred(p[1]) == 1
@test all(p .== 1)
@test length(p) == 512
@test size(p) == (512,)
@test Base.IndexStyle(p) == Base.IndexLinear()

@test Integer(pointer(p)) % Mmap.PAGESIZE == 0
@test Int(pointer(p)) % Mmap.PAGESIZE == 0

0 comments on commit 64645d9

Please sign in to comment.