Skip to content

Commit

Permalink
Add Reference constructors (#7)
Browse files Browse the repository at this point in the history
* Add Reference constructors

* version bump
  • Loading branch information
Tokazama authored Aug 9, 2021
1 parent 1ddedc8 commit d9f69d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ManualMemory"
uuid = "d125e4d3-2237-4719-b19c-fa641b8a4667"
authors = ["chriselrod <[email protected]> and contributors"]
version = "0.1.4"
version = "0.1.5"

[compat]
julia = "1.5"
Expand Down
7 changes: 6 additions & 1 deletion src/ManualMemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ end

@inline store!(p::Ptr{T}, v) where {T} = store!(p, convert(T, v))

mutable struct Reference{T}; data::T; end
mutable struct Reference{T}
data::T

Reference{T}() where {T} = new()
Reference{T}(x) where {T} = new(x)
end
@inline load(p::Ptr{Reference{T}}) where {T} = getfield(ccall(:jl_value_ptr, Ref{Reference{T}}, (Ptr{Cvoid},), unsafe_load(Base.unsafe_convert(Ptr{Ptr{Cvoid}}, p))), :data)
@inline dereference(r::Reference) = getfield(r, :data)
@inline dereference(x) = x
Expand Down

2 comments on commit d9f69d9

@Tokazama
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/42439

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.5 -m "<description of version>" d9f69d97cb2c4b0adf550d675927749294689fc5
git push origin v0.1.5

Please sign in to comment.