Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made package ready for Julia 1.5 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
/Manifest.toml
.vscode
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
17 changes: 17 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name = "PageAlignedArrays"
uuid = "ba0cfe35-a769-40a2-96c5-fb706a08f4a0"
authors = ["Andrew Keller"]
version = "0.1.0"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"

[compat]
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
2 changes: 0 additions & 2 deletions REQUIRE

This file was deleted.

40 changes: 17 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 1.0
- julia_version: 1.1
- julia_version: 1.2
- julia_version: 1.3
- julia_version: 1.4
- julia_version: 1.5
- julia_version: latest

platform:
- x86 # 32-bit
- x64 # 64-bit

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
# - julia_version: latest

branches:
only:
Expand All @@ -24,24 +30,12 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"PageAlignedArrays\"); Pkg.build(\"PageAlignedArrays\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"PageAlignedArrays\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
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, Cvoid, (Ptr{Cvoid},), addr)
end : @static Base.Sys.isapple() ? begin
return ccall((:free, "libSystem.dylib"), Cvoid, (Ptr{Cvoid},), addr)
end : error("OS not supported")
end
end # module
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
8 changes: 5 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using PageAlignedArrays
using Base.Test
using Test
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)) % Base.Mmap.PAGESIZE == 0
@test Int(pointer(p)) % Mmap.PAGESIZE == 0