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

Remove unnecessary preserve calls #16

Merged
merged 2 commits into from
Jul 29, 2021
Merged
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
8 changes: 4 additions & 4 deletions src/cells.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ len(::Type{SpiceChar}, length) = length += 1
dim(::Type{T}) where {T} = 1
dim(::Type{SpiceChar}) = 2

data_ptr(::Type{SpiceChar}, data, length) = GC.@preserve data pointer(data, CTRLSZ * length + 1)
data_ptr(::Type{T}, data, _) where {T} = GC.@preserve data pointer(data, CTRLSZ + 1)
data_ptr(::Type{SpiceChar}, data, length) = pointer(data, CTRLSZ * length + 1)
data_ptr(::Type{T}, data, _) where {T} = pointer(data, CTRLSZ + 1)

mutable struct SpiceCell{S, T, N} <: AbstractArray{T, 1}
data::Array{S, N}
Expand All @@ -47,7 +47,7 @@ mutable struct SpiceCell{S, T, N} <: AbstractArray{T, 1}
cell = Cell{T}(length, size)
data = init_data(T, size, length)
self = new{T, itertype(T), dim(T)}(data, cell)
self.cell.base = GC.@preserve self pointer(self.data, 1)
self.cell.base = pointer(self.data, 1)
self.cell.data = data_ptr(T, self.data, length)
self
end
Expand Down Expand Up @@ -179,7 +179,7 @@ Duplicate the SpiceCell `cell`.
"""
function Base.copy(cell::SpiceCell{T}) where {T}
cell_copy = deepcopy(cell)
cell_copy.cell.base = GC.@preserve cell_copy pointer(cell_copy.data, 1)
cell_copy.cell.base = pointer(cell_copy.data, 1)
cell_copy.cell.data = data_ptr(T, cell_copy.data, length)
cell_copy
end
Expand Down
26 changes: 13 additions & 13 deletions src/g.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ function gfevnt(udstep, udrefn, gquant, qpnams, qcpars, qdpars, qipars, qlpars,
_qipars = SpiceInt.(qipars)
_qlpars = SpiceBoolean.(qlpars)
function _udstep(et::SpiceDouble, step::Ptr{SpiceDouble})
_step = GC.@preserve step unsafe_wrap(Array{SpiceDouble}, step, 1)
_step = unsafe_wrap(Array{SpiceDouble}, step, 1)
_step[1] = udstep(et)
nothing
end
udstep_ptr = @cfunction($_udstep, Cvoid, (SpiceDouble, Ptr{SpiceDouble}))
function _udrefn(t1::SpiceDouble, t2::SpiceDouble, s1::SpiceBoolean, s2::SpiceBoolean,
t::Ptr{SpiceDouble})
_t = GC.@preserve t unsafe_wrap(Array{SpiceDouble}, t, 1)
_t = unsafe_wrap(Array{SpiceDouble}, t, 1)
_t[1] = udrefn(t1, t2, s1, s2)
nothing
end
Expand All @@ -342,7 +342,7 @@ function gfevnt(udstep, udrefn, gquant, qpnams, qcpars, qdpars, qipars, qlpars,
Ptr{SpiceDouble}))
udrepf_ptr = @cfunction($udrepf, Cvoid, ())
function _udrepi(window::Ptr{Cell{SpiceDouble}}, begmss::Cstring, endmss::Cstring)
_window = GC.@preserve window unsafe_load(window, 1)
_window = unsafe_load(window, 1)
udrepi(_window, begmss, endmss)
end
udrepi_ptr = @cfunction($_udrepi, Cvoid, (Ptr{Cell{SpiceDouble}}, Cstring, Cstring))
Expand Down Expand Up @@ -400,14 +400,14 @@ function gffove!(inst, tshape, raydir, target, tframe, abcorr, obsrvr, tol, udst
rpt, udrepi, udrepu, udrepf, cnfine, result)
@checkdims 3 raydir
function _udstep(et::SpiceDouble, step::Ptr{SpiceDouble})
_step = GC.@preserve step unsafe_wrap(Array{SpiceDouble}, step, 1)
_step = unsafe_wrap(Array{SpiceDouble}, step, 1)
_step[1] = udstep(et)
nothing
end
udstep_ptr = @cfunction($_udstep, Cvoid, (SpiceDouble, Ptr{SpiceDouble}))
function _udrefn(t1::SpiceDouble, t2::SpiceDouble, s1::SpiceBoolean, s2::SpiceBoolean,
t::Ptr{SpiceDouble})
_t = GC.@preserve t unsafe_wrap(Array{SpiceDouble}, t, 1)
_t = unsafe_wrap(Array{SpiceDouble}, t, 1)
_t[1] = udrefn(t1, t2, s1, s2)
nothing
end
Expand All @@ -416,7 +416,7 @@ function gffove!(inst, tshape, raydir, target, tframe, abcorr, obsrvr, tol, udst
Ptr{SpiceDouble}))
udrepf_ptr = @cfunction($udrepf, Cvoid, ())
function _udrepi(window::Ptr{Cell{SpiceDouble}}, begmss::Cstring, endmss::Cstring)
_window = GC.@preserve window unsafe_load(window, 1)
_window = unsafe_load(window, 1)
udrepi(_window, begmss, endmss)
end
udrepi_ptr = @cfunction($_udrepi, Cvoid, (Ptr{Cell{SpiceDouble}}, Cstring, Cstring))
Expand Down Expand Up @@ -517,14 +517,14 @@ Returns `result`.
"""
function gfocce!(occtyp, front, fshape, fframe, back, bshape, bframe, abcorr, obsrvr, tol, udstep, udrefn, rpt, udrepi, udrepu, udrepf, cnfine, result)
function _udstep(et::SpiceDouble, step::Ptr{SpiceDouble})
_step = GC.@preserve step unsafe_wrap(Array{SpiceDouble}, step, 1)
_step = unsafe_wrap(Array{SpiceDouble}, step, 1)
_step[1] = udstep(et)
nothing
end
udstep_ptr = @cfunction($_udstep, Cvoid, (SpiceDouble, Ptr{SpiceDouble}))
function _udrefn(t1::SpiceDouble, t2::SpiceDouble, s1::SpiceBoolean, s2::SpiceBoolean,
t::Ptr{SpiceDouble})
_t = GC.@preserve t unsafe_wrap(Array{SpiceDouble}, t, 1)
_t = unsafe_wrap(Array{SpiceDouble}, t, 1)
_t[1] = udrefn(t1, t2, s1, s2)
nothing
end
Expand All @@ -533,7 +533,7 @@ function gfocce!(occtyp, front, fshape, fframe, back, bshape, bframe, abcorr, ob
Ptr{SpiceDouble}))
udrepf_ptr = @cfunction($udrepf, Cvoid, ())
function _udrepi(window::Ptr{Cell{SpiceDouble}}, begmss::Cstring, endmss::Cstring)
_window = GC.@preserve window unsafe_load(window, 1)
_window = unsafe_load(window, 1)
udrepi(_window, begmss, endmss)
end
udrepi_ptr = @cfunction($_udrepi, Cvoid, (Ptr{Cell{SpiceDouble}}, Cstring, Cstring))
Expand Down Expand Up @@ -1094,13 +1094,13 @@ Returns `result`.
"""
function gfudb!(udfuns, udfunb, step, cnfine, result)
function _udfuns(et::SpiceDouble, value::Ptr{SpiceDouble})
_value = GC.@preserve value unsafe_wrap(Array{SpiceDouble}, value, 1)
_value = unsafe_wrap(Array{SpiceDouble}, value, 1)
_value[1] = udfuns(et)
nothing
end
udfuns_ptr = @cfunction($_udfuns, Cvoid, (SpiceDouble, Ptr{SpiceDouble}))
function _udfunb(_::Ptr{Cvoid}, et::SpiceDouble, value::Ptr{SpiceBoolean})
_value = GC.@preserve value unsafe_wrap(Array{SpiceBoolean}, value, 1)
_value = unsafe_wrap(Array{SpiceBoolean}, value, 1)
_value[1] = udfunb(udfuns, et)
nothing
end
Expand Down Expand Up @@ -1139,13 +1139,13 @@ Returns `result`.
"""
function gfuds!(udfuns, udqdec, relate, refval, adjust, step, nintvls, cnfine, result)
function _udfuns(et::SpiceDouble, value::Ptr{SpiceDouble})
_value = GC.@preserve value unsafe_wrap(Array{SpiceDouble}, value, 1)
_value = unsafe_wrap(Array{SpiceDouble}, value, 1)
_value[1] = udfuns(et)
nothing
end
udfuns_ptr = @cfunction($_udfuns, Cvoid, (SpiceDouble, Ptr{SpiceDouble}))
function _udqdec(_::Ptr{Cvoid}, et::SpiceDouble, value::Ptr{SpiceBoolean})
_value = GC.@preserve value unsafe_wrap(Array{SpiceBoolean}, value, 1)
_value = unsafe_wrap(Array{SpiceBoolean}, value, 1)
_value[1] = udqdec(udfuns, et)
nothing
end
Expand Down
2 changes: 1 addition & 1 deletion src/t.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ version string.
"""
function tkvrsn(item=:TOOLKIT)
out = ccall((:tkvrsn_c, libcspice), Cstring, (Cstring,), string(item))
GC.@preserve out unsafe_string(pointer(out))
return unsafe_string(out)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/u.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Returns the approximate derivative of `udfunc` at `x`.
"""
function uddf(udfunc, x, dx)
function _udfunc(et::SpiceDouble, value::Ptr{SpiceDouble})
value_ = GC.@preserve value unsafe_wrap(Array{SpiceDouble}, value, 1)
value_ = unsafe_wrap(Array{SpiceDouble}, value, 1)
value_[1] = udfunc(et)
nothing
end
Expand Down